Fix broken of team create (#19288)

* Fix broken of team create

* Update models/organization/team.go

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
tokarchuk/v1.17
Lunny Xiao 3 years ago committed by GitHub
parent 124b072f0b
commit 89b9d42f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      models/organization/team.go
  2. 2
      models/repo_permission.go
  3. 2
      models/review.go

@ -239,15 +239,17 @@ func (t *Team) GetMembersCtx(ctx context.Context) (err error) {
// UnitEnabled returns if the team has the given unit type enabled // UnitEnabled returns if the team has the given unit type enabled
func (t *Team) UnitEnabled(tp unit.Type) bool { func (t *Team) UnitEnabled(tp unit.Type) bool {
return t.unitEnabled(db.DefaultContext, tp) return t.UnitAccessMode(tp) > perm.AccessModeNone
} }
func (t *Team) unitEnabled(ctx context.Context, tp unit.Type) bool { // UnitAccessMode returns if the team has the given unit type enabled
return t.UnitAccessMode(ctx, tp) > perm.AccessModeNone // it is called in templates, should not be replaced by `UnitAccessModeCtx(ctx ...)`
func (t *Team) UnitAccessMode(tp unit.Type) perm.AccessMode {
return t.UnitAccessModeCtx(db.DefaultContext, tp)
} }
// UnitAccessMode returns if the team has the given unit type enabled // UnitAccessModeCtx returns if the team has the given unit type enabled
func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode { func (t *Team) UnitAccessModeCtx(ctx context.Context, tp unit.Type) perm.AccessMode {
if err := t.getUnits(ctx); err != nil { if err := t.getUnits(ctx); err != nil {
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error()) log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
} }

@ -250,7 +250,7 @@ func getUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
for _, u := range repo.Units { for _, u := range repo.Units {
var found bool var found bool
for _, team := range teams { for _, team := range teams {
teamMode := team.UnitAccessMode(ctx, u.Type) teamMode := team.UnitAccessModeCtx(ctx, u.Type)
if teamMode > perm_model.AccessModeNone { if teamMode > perm_model.AccessModeNone {
m := perm.UnitsMode[u.Type] m := perm.UnitsMode[u.Type]
if m < teamMode { if m < teamMode {

@ -273,7 +273,7 @@ func isOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
} }
if !pr.ProtectedBranch.EnableApprovalsWhitelist { if !pr.ProtectedBranch.EnableApprovalsWhitelist {
return team.UnitAccessMode(ctx, unit.TypeCode) >= perm.AccessModeWrite, nil return team.UnitAccessModeCtx(ctx, unit.TypeCode) >= perm.AccessModeWrite, nil
} }
return base.Int64sContains(pr.ProtectedBranch.ApprovalsWhitelistTeamIDs, team.ID), nil return base.Int64sContains(pr.ProtectedBranch.ApprovalsWhitelistTeamIDs, team.ID), nil

Loading…
Cancel
Save