Skip to content

Commit 6eb856c

Browse files
authored
Fix owner team access mode value in team_unit table (#23675)
All `access_mode` value of Owner Teams are 0(AccessModeNone) in `team_unit` table, which should be 4(AccessModeOwner) In `team` table: ![image](https://user-images.githubusercontent.com/18380374/227409457-1b9660ae-8cf7-49c8-a013-1850b46baebc.png) In `team_unit` table: ![image](https://user-images.githubusercontent.com/18380374/227409429-a793dd90-4ae1-4191-b95b-e288c591f9fd.png) ps: In #23630, `access_mode` in `team_unit` is used to check the team unit permission, but I found that user can not see issues in owned org repos.
1 parent 29133f3 commit 6eb856c

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ var migrations = []Migration{
479479
NewMigration("Improve Action table indices v3", v1_20.ImproveActionTableIndices),
480480
// v250 -> v251
481481
NewMigration("Change Container Metadata", v1_20.ChangeContainerMetadataMultiArch),
482+
// v251 -> v252
483+
NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode),
482484
}
483485

484486
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v251.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/log"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixIncorrectOwnerTeamUnitAccessMode(x *xorm.Engine) error {
13+
type UnitType int
14+
type AccessMode int
15+
16+
type TeamUnit struct {
17+
ID int64 `xorm:"pk autoincr"`
18+
OrgID int64 `xorm:"INDEX"`
19+
TeamID int64 `xorm:"UNIQUE(s)"`
20+
Type UnitType `xorm:"UNIQUE(s)"`
21+
AccessMode AccessMode
22+
}
23+
24+
const (
25+
// AccessModeOwner owner access
26+
AccessModeOwner = 4
27+
)
28+
29+
sess := x.NewSession()
30+
defer sess.Close()
31+
32+
if err := sess.Begin(); err != nil {
33+
return err
34+
}
35+
36+
count, err := sess.Table("team_unit").
37+
Where("team_id IN (SELECT id FROM team WHERE authorize = ?)", AccessModeOwner).
38+
Update(&TeamUnit{
39+
AccessMode: AccessModeOwner,
40+
})
41+
if err != nil {
42+
return err
43+
}
44+
log.Debug("Updated %d owner team unit access mode to belong to owner instead of none", count)
45+
46+
return sess.Commit()
47+
}

models/organization/org.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,10 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
338338
units := make([]TeamUnit, 0, len(unit.AllRepoUnitTypes))
339339
for _, tp := range unit.AllRepoUnitTypes {
340340
units = append(units, TeamUnit{
341-
OrgID: org.ID,
342-
TeamID: t.ID,
343-
Type: tp,
341+
OrgID: org.ID,
342+
TeamID: t.ID,
343+
Type: tp,
344+
AccessMode: perm.AccessModeOwner,
344345
})
345346
}
346347

0 commit comments

Comments
 (0)