File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2023 The Gitea Authors. All rights reserved.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ package doctor
5
+
6
+ import (
7
+ "context"
8
+
9
+ "code.gitea.io/gitea/models"
10
+ "code.gitea.io/gitea/models/db"
11
+ org_model "code.gitea.io/gitea/models/organization"
12
+ "code.gitea.io/gitea/models/perm"
13
+ "code.gitea.io/gitea/modules/log"
14
+
15
+ "xorm.io/builder"
16
+ )
17
+
18
+ func fixOwnerTeamCreateOrgRepo (ctx context.Context , logger log.Logger , autofix bool ) error {
19
+ count := 0
20
+
21
+ err := db .Iterate (
22
+ ctx ,
23
+ builder.Eq {"authorize" : perm .AccessModeOwner , "can_create_org_repo" : false },
24
+ func (ctx context.Context , team * org_model.Team ) error {
25
+ team .CanCreateOrgRepo = true
26
+ count ++
27
+
28
+ if ! autofix {
29
+ return nil
30
+ }
31
+
32
+ return models .UpdateTeam (team , false , false )
33
+ },
34
+ )
35
+ if err != nil {
36
+ logger .Critical ("Unable to iterate across repounits to fix incorrect can_create_org_repo: Error %v" , err )
37
+ return err
38
+ }
39
+
40
+ if ! autofix {
41
+ if count == 0 {
42
+ logger .Info ("Found no team with incorrect can_create_org_repo" )
43
+ } else {
44
+ logger .Warn ("Found %d teams with incorrect can_create_org_repo" , count )
45
+ }
46
+ return nil
47
+ }
48
+ logger .Info ("Fixed %d teams with incorrect can_create_org_repo" , count )
49
+
50
+ return nil
51
+ }
52
+
53
+ func init () {
54
+ Register (& Check {
55
+ Title : "Check for incorrect can_create_org_repo for org owner teams" ,
56
+ Name : "fix-owner-team-create-org-repo" ,
57
+ IsDefault : false ,
58
+ Run : fixOwnerTeamCreateOrgRepo ,
59
+ Priority : 7 ,
60
+ })
61
+ }
You can’t perform that action at this time.
0 commit comments