Skip to content

Commit 7d54006

Browse files
committed
remove issue_watches when team member is removed, team repository is removed, a collaborator is removed
1 parent fd3cf7e commit 7d54006

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

models/issue_watch.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,14 @@ func getIssueWatchers(e Engine, issueID int64) (watches []*IssueWatch, err error
7171
Find(&watches)
7272
return
7373
}
74+
75+
func removeIssueWatchersByRepoID(e Engine, userID int64, repoID int64) error {
76+
iw := &IssueWatch{
77+
IsWatching: false,
78+
}
79+
_, err := e.
80+
Join("INNER", "issue", "`issue`.id = `issue_watch`.issue_id AND `issue`.repo_id = ?", repoID).
81+
Cols("is_watching", "updated_unix").
82+
Update(iw)
83+
return err
84+
}

models/org_team.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
178178
if err = watchRepo(e, teamUser.UID, repo.ID, false); err != nil {
179179
return err
180180
}
181+
182+
// Remove all IssueWatches a user has subscribed to in the repositories
183+
if err := removeIssueWatchersByRepoID(e, teamUser.ID, repo.ID); err != nil {
184+
return err
185+
}
181186
}
182187

183188
return nil
@@ -396,6 +401,11 @@ func DeleteTeam(t *Team) error {
396401
if err = watchRepo(sess, user.ID, repo.ID, false); err != nil {
397402
return err
398403
}
404+
405+
// Remove all IssueWatches a user has subscribed to in the repositories
406+
if err = removeIssueWatchersByRepoID(sess, user.ID, repo.ID); err != nil {
407+
return err
408+
}
399409
}
400410
}
401411

@@ -592,6 +602,11 @@ func removeTeamMember(e *xorm.Session, team *Team, userID int64) error {
592602
if err = watchRepo(e, userID, repo.ID, false); err != nil {
593603
return err
594604
}
605+
606+
// Remove all IssueWatches a user has subscribed to in the repositories
607+
if err := removeIssueWatchersByRepoID(e, userID, repo.ID); err != nil {
608+
return err
609+
}
595610
}
596611

597612
// Check if the user is a member of any team in the organization.

models/repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,9 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
18511851
if _, err = sess.In("issue_id", issueIDs).Delete(&Reaction{}); err != nil {
18521852
return err
18531853
}
1854+
if _, err = sess.In("issue_id", issueIDs).Delete(&IssueWatch{}); err != nil {
1855+
return err
1856+
}
18541857

18551858
attachments := make([]*Attachment, 0, 5)
18561859
if err = sess.

models/repo_collaboration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,10 @@ func (repo *Repository) DeleteCollaboration(uid int64) (err error) {
176176
return err
177177
}
178178

179+
// Remove all IssueWatches a user has subscribed to in the repository
180+
if err := removeIssueWatchersByRepoID(sess, uid, repo.ID); err != nil {
181+
return err
182+
}
183+
179184
return sess.Commit()
180185
}

0 commit comments

Comments
 (0)