Skip to content

Commit 941c3fb

Browse files
authored
Merge branch 'main' into add-unset-default-project
2 parents fef8b83 + fa34951 commit 941c3fb

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ var migrations = []Migration{
483483
NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode),
484484
// v252 -> v253
485485
NewMigration("Fix incorrect admin team unit access mode", v1_20.FixIncorrectAdminTeamUnitAccessMode),
486+
// v253 -> v254
487+
NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam),
486488
}
487489

488490
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v253.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam(x *xorm.Engine) error {
13+
type UnitType int
14+
type AccessMode int
15+
16+
type TeamUnit struct {
17+
ID int64 `xorm:"pk autoincr"`
18+
Type UnitType `xorm:"UNIQUE(s)"`
19+
AccessMode AccessMode
20+
}
21+
22+
const (
23+
// AccessModeRead read access
24+
AccessModeRead = 1
25+
26+
// Unit Type
27+
TypeExternalWiki = 6
28+
TypeExternalTracker = 7
29+
)
30+
31+
sess := x.NewSession()
32+
defer sess.Close()
33+
34+
if err := sess.Begin(); err != nil {
35+
return err
36+
}
37+
38+
count, err := sess.Table("team_unit").
39+
Where("type IN (?, ?) AND access_mode > ?", TypeExternalWiki, TypeExternalTracker, AccessModeRead).
40+
Update(&TeamUnit{
41+
AccessMode: AccessModeRead,
42+
})
43+
if err != nil {
44+
return err
45+
}
46+
log.Debug("Updated %d ExternalTracker and ExternalWiki access mode to belong to owner and admin", count)
47+
48+
return sess.Commit()
49+
}

0 commit comments

Comments
 (0)