diff --git a/models/issue_watch.go b/models/issue_watch.go index 69e218af0..f0b3adbb1 100644 --- a/models/issue_watch.go +++ b/models/issue_watch.go @@ -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 +} diff --git a/models/org_team.go b/models/org_team.go index 8fd7af595..efc627259 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -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. diff --git a/models/repo.go b/models/repo.go index f4923cf4a..7f2be502a 100644 --- a/models/repo.go +++ b/models/repo.go @@ -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. diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go index c09f488fb..9d2935d58 100644 --- a/models/repo_collaboration.go +++ b/models/repo_collaboration.go @@ -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() }