Skip to content

Commit 89b9d42

Browse files
lunnywxiaoguang
andauthored
Fix broken of team create (#19288)
* Fix broken of team create * Update models/organization/team.go Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 124b072 commit 89b9d42

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

models/organization/team.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,17 @@ func (t *Team) GetMembersCtx(ctx context.Context) (err error) {
239239

240240
// UnitEnabled returns if the team has the given unit type enabled
241241
func (t *Team) UnitEnabled(tp unit.Type) bool {
242-
return t.unitEnabled(db.DefaultContext, tp)
242+
return t.UnitAccessMode(tp) > perm.AccessModeNone
243243
}
244244

245-
func (t *Team) unitEnabled(ctx context.Context, tp unit.Type) bool {
246-
return t.UnitAccessMode(ctx, tp) > perm.AccessModeNone
245+
// UnitAccessMode returns if the team has the given unit type enabled
246+
// it is called in templates, should not be replaced by `UnitAccessModeCtx(ctx ...)`
247+
func (t *Team) UnitAccessMode(tp unit.Type) perm.AccessMode {
248+
return t.UnitAccessModeCtx(db.DefaultContext, tp)
247249
}
248250

249-
// UnitAccessMode returns if the team has the given unit type enabled
250-
func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode {
251+
// UnitAccessModeCtx returns if the team has the given unit type enabled
252+
func (t *Team) UnitAccessModeCtx(ctx context.Context, tp unit.Type) perm.AccessMode {
251253
if err := t.getUnits(ctx); err != nil {
252254
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
253255
}

models/repo_permission.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func getUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
250250
for _, u := range repo.Units {
251251
var found bool
252252
for _, team := range teams {
253-
teamMode := team.UnitAccessMode(ctx, u.Type)
253+
teamMode := team.UnitAccessModeCtx(ctx, u.Type)
254254
if teamMode > perm_model.AccessModeNone {
255255
m := perm.UnitsMode[u.Type]
256256
if m < teamMode {

models/review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func isOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
273273
}
274274

275275
if !pr.ProtectedBranch.EnableApprovalsWhitelist {
276-
return team.UnitAccessMode(ctx, unit.TypeCode) >= perm.AccessModeWrite, nil
276+
return team.UnitAccessModeCtx(ctx, unit.TypeCode) >= perm.AccessModeWrite, nil
277277
}
278278

279279
return base.Int64sContains(pr.ProtectedBranch.ApprovalsWhitelistTeamIDs, team.ID), nil

0 commit comments

Comments
 (0)