summaryrefslogtreecommitdiffstats
path: root/models/org_team.go
diff options
context:
space:
mode:
authorNorwin <noerw@users.noreply.github.com>2022-03-22 02:09:45 +0100
committerGitHub <noreply@github.com>2022-03-22 09:09:45 +0800
commit77d1c7bf2fbdc217cef564417c8fd82612834f6e (patch)
tree527fb67941d21e1a41bb2670940a6df8f0a75602 /models/org_team.go
parentbfe2e3d562307eb8b6659d71d2c10bf3c1284e77 (diff)
downloadgitea-77d1c7bf2fbdc217cef564417c8fd82612834f6e.tar.gz
gitea-77d1c7bf2fbdc217cef564417c8fd82612834f6e.zip
Cleanup protected branches when deleting users & teams (#19158)
* Clean up protected_branches when deleting user fixes #19094 * Clean up protected_branches when deleting teams * fix issue Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/org_team.go')
-rw-r--r--models/org_team.go42
1 files changed, 40 insertions, 2 deletions
diff --git a/models/org_team.go b/models/org_team.go
index 17f95bb5b0..faee23f4f8 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -19,6 +19,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
@@ -776,8 +777,45 @@ func DeleteTeam(t *Team) error {
return err
}
- if err := t.removeAllRepositories(ctx); err != nil {
- return err
+ // update branch protections
+ {
+ protections := make([]*ProtectedBranch, 0, 10)
+ err := sess.In("repo_id",
+ builder.Select("id").From("repository").Where(builder.Eq{"owner_id": t.OrgID})).
+ Find(&protections)
+ if err != nil {
+ return fmt.Errorf("findProtectedBranches: %v", err)
+ }
+ for _, p := range protections {
+ var matched1, matched2, matched3 bool
+ if len(p.WhitelistTeamIDs) != 0 {
+ p.WhitelistTeamIDs, matched1 = util.RemoveIDFromList(
+ p.WhitelistTeamIDs, t.ID)
+ }
+ if len(p.ApprovalsWhitelistTeamIDs) != 0 {
+ p.ApprovalsWhitelistTeamIDs, matched2 = util.RemoveIDFromList(
+ p.ApprovalsWhitelistTeamIDs, t.ID)
+ }
+ if len(p.MergeWhitelistTeamIDs) != 0 {
+ p.MergeWhitelistTeamIDs, matched3 = util.RemoveIDFromList(
+ p.MergeWhitelistTeamIDs, t.ID)
+ }
+ if matched1 || matched2 || matched3 {
+ if _, err = sess.ID(p.ID).Cols(
+ "whitelist_team_i_ds",
+ "merge_whitelist_team_i_ds",
+ "approvals_whitelist_team_i_ds",
+ ).Update(p); err != nil {
+ return fmt.Errorf("updateProtectedBranches: %v", err)
+ }
+ }
+ }
+ }
+
+ if !t.IncludesAllRepositories {
+ if err := t.removeAllRepositories(ctx); err != nil {
+ return err
+ }
}
// Delete team-user.