Skip to content

Commit c3d323f

Browse files
GiteaBotyp05327wxiaoguang
authored
Add fix incorrect can_create_org_repo for org owner team (#26683) (#26791)
Backport #26683 by @yp05327 Related to: #8312 #26491 In migration v109, we only added a new column `CanCreateOrgRepo` in Team table, but not initial the value of it. This may cause bug like #26491. Co-authored-by: yp05327 <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 4013f3f commit c3d323f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

modules/doctor/fix8312.go

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

0 commit comments

Comments
 (0)