Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_20
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.dev/modelmigration/base"
|
|
"gitea.dev/modules/log"
|
|
)
|
|
|
|
func FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam(_ context.Context, x base.EngineMigration) error {
|
|
type UnitType int
|
|
type AccessMode int
|
|
|
|
type TeamUnit struct {
|
|
ID int64 `xorm:"pk autoincr"`
|
|
Type UnitType `xorm:"UNIQUE(s)"`
|
|
AccessMode AccessMode
|
|
}
|
|
|
|
const (
|
|
// AccessModeRead read access
|
|
AccessModeRead = 1
|
|
|
|
// Unit Type
|
|
TypeExternalWiki = 6
|
|
TypeExternalTracker = 7
|
|
)
|
|
|
|
sess := x.NewSession()
|
|
defer sess.Close()
|
|
|
|
if err := sess.Begin(); err != nil {
|
|
return err
|
|
}
|
|
|
|
count, err := sess.Table("team_unit").
|
|
Where("type IN (?, ?) AND access_mode > ?", TypeExternalWiki, TypeExternalTracker, AccessModeRead).
|
|
Update(&TeamUnit{
|
|
AccessMode: AccessModeRead,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Debug("Updated %d ExternalTracker and ExternalWiki access mode to belong to owner and admin", count)
|
|
|
|
return sess.Commit()
|
|
}
|