summaryrefslogtreecommitdiffstats
path: root/models/org_team.go
diff options
context:
space:
mode:
authorDavid Schneiderbauer <daviian@users.noreply.github.com>2018-06-19 21:44:33 +0200
committertechknowlogick <techknowlogick@users.noreply.github.com>2018-06-19 15:44:33 -0400
commita93f13849cd7f54029f1dc17b642d024b98ee71e (patch)
tree99340a1daec2fa3a3db14ed630b57c6bc3984fbe /models/org_team.go
parent467ff4d34302f6ecab959d61bf3944a2bdf125d0 (diff)
downloadgitea-a93f13849cd7f54029f1dc17b642d024b98ee71e.tar.gz
gitea-a93f13849cd7f54029f1dc17b642d024b98ee71e.zip
Fix not removed watches on unallowed repositories (#4201)
Diffstat (limited to 'models/org_team.go')
-rw-r--r--models/org_team.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/models/org_team.go b/models/org_team.go
index 9d8a031418..5ea6e76cd9 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.UID, repo.ID); err != nil {
+ return err
+ }
}
return nil
@@ -374,11 +379,34 @@ func DeleteTeam(t *Team) error {
return err
}
+ if err := t.getMembers(sess); err != nil {
+ return err
+ }
+
// Delete all accesses.
for _, repo := range t.Repos {
if err := repo.recalculateTeamAccesses(sess, t.ID); err != nil {
return err
}
+
+ // Remove watches from all users and now unaccessible repos
+ for _, user := range t.Members {
+ has, err := hasAccess(sess, user.ID, repo, AccessModeRead)
+ if err != nil {
+ return err
+ } else if has {
+ continue
+ }
+
+ 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
+ }
+ }
}
// Delete team-repo
@@ -518,6 +546,10 @@ func AddTeamMember(team *Team, userID int64) error {
if err := repo.recalculateTeamAccesses(sess, 0); err != nil {
return err
}
+
+ if err = watchRepo(sess, userID, repo.ID, true); err != nil {
+ return err
+ }
}
return sess.Commit()
@@ -558,6 +590,23 @@ func removeTeamMember(e *xorm.Session, team *Team, userID int64) error {
if err := repo.recalculateTeamAccesses(e, 0); err != nil {
return err
}
+
+ // Remove watches from now unaccessible
+ has, err := hasAccess(e, userID, repo, AccessModeRead)
+ if err != nil {
+ return err
+ } else if has {
+ continue
+ }
+
+ 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.