remove issue_watches when team member is removed, team repository is removed, a collaborator is removed

This commit is contained in:
David Schneiderbauer 2018-06-13 00:15:06 +02:00
parent fd3cf7e090
commit 7d54006802
No known key found for this signature in database
GPG Key ID: 576113B2803B3EAB
4 changed files with 34 additions and 0 deletions

View File

@ -71,3 +71,14 @@ func getIssueWatchers(e Engine, issueID int64) (watches []*IssueWatch, err error
Find(&watches)
return
}
func removeIssueWatchersByRepoID(e Engine, userID int64, repoID int64) error {
iw := &IssueWatch{
IsWatching: false,
}
_, err := e.
Join("INNER", "issue", "`issue`.id = `issue_watch`.issue_id AND `issue`.repo_id = ?", repoID).
Cols("is_watching", "updated_unix").
Update(iw)
return err
}

View File

@ -178,6 +178,11 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
if err = watchRepo(e, teamUser.UID, repo.ID, false); err != nil {
return err
}
// Remove all IssueWatches a user has subscribed to in the repositories
if err := removeIssueWatchersByRepoID(e, teamUser.ID, repo.ID); err != nil {
return err
}
}
return nil
@ -396,6 +401,11 @@ func DeleteTeam(t *Team) error {
if err = watchRepo(sess, user.ID, repo.ID, false); err != nil {
return err
}
// Remove all IssueWatches a user has subscribed to in the repositories
if err = removeIssueWatchersByRepoID(sess, user.ID, repo.ID); err != nil {
return err
}
}
}
@ -592,6 +602,11 @@ func removeTeamMember(e *xorm.Session, team *Team, userID int64) error {
if err = watchRepo(e, userID, repo.ID, false); err != nil {
return err
}
// Remove all IssueWatches a user has subscribed to in the repositories
if err := removeIssueWatchersByRepoID(e, userID, repo.ID); err != nil {
return err
}
}
// Check if the user is a member of any team in the organization.

View File

@ -1851,6 +1851,9 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
if _, err = sess.In("issue_id", issueIDs).Delete(&Reaction{}); err != nil {
return err
}
if _, err = sess.In("issue_id", issueIDs).Delete(&IssueWatch{}); err != nil {
return err
}
attachments := make([]*Attachment, 0, 5)
if err = sess.

View File

@ -176,5 +176,10 @@ func (repo *Repository) DeleteCollaboration(uid int64) (err error) {
return err
}
// Remove all IssueWatches a user has subscribed to in the repository
if err := removeIssueWatchersByRepoID(sess, uid, repo.ID); err != nil {
return err
}
return sess.Commit()
}