Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken of team create #19288

Merged
merged 3 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions models/organization/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,17 @@ func (t *Team) GetMembersCtx(ctx context.Context) (err error) {

// UnitEnabled returns if the team has the given unit type enabled
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 {
return t.UnitAccessMode(ctx, tp) > perm.AccessModeNone
// UnitAccessMode returns if the team has the given unit type enabled
lunny marked this conversation as resolved.
Show resolved Hide resolved
// 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
func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode {
// UnitAccessModeCtx returns if the team has the given unit type enabled
func (t *Team) UnitAccessModeCtx(ctx context.Context, tp unit.Type) perm.AccessMode {
if err := t.getUnits(ctx); err != nil {
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion models/repo_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func getUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
for _, u := range repo.Units {
var found bool
for _, team := range teams {
teamMode := team.UnitAccessMode(ctx, u.Type)
teamMode := team.UnitAccessModeCtx(ctx, u.Type)
if teamMode > perm_model.AccessModeNone {
m := perm.UnitsMode[u.Type]
if m < teamMode {
Expand Down
2 changes: 1 addition & 1 deletion models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func isOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
}

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
Expand Down