From 6968b7f884a8a4b6efcf0499fa086c9dafc55544 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 1 Apr 2022 09:46:41 +0800 Subject: [PATCH 1/2] Fix broken of team create --- models/organization/team.go | 11 ++++++----- models/repo_permission.go | 2 +- models/review.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/models/organization/team.go b/models/organization/team.go index 16170058412f..56607ea54b60 100644 --- a/models/organization/team.go +++ b/models/organization/team.go @@ -239,15 +239,16 @@ 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 +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()) } diff --git a/models/repo_permission.go b/models/repo_permission.go index 4dfc63d4e160..3e9ad04482d9 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -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 { diff --git a/models/review.go b/models/review.go index 6ef8d530b684..f360d459cfde 100644 --- a/models/review.go +++ b/models/review.go @@ -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 From 08fb004b828f65adf8b57b7025eb46a476b12457 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 1 Apr 2022 13:32:06 +0800 Subject: [PATCH 2/2] Update models/organization/team.go Co-authored-by: wxiaoguang --- models/organization/team.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/organization/team.go b/models/organization/team.go index 56607ea54b60..077fba6a60cf 100644 --- a/models/organization/team.go +++ b/models/organization/team.go @@ -243,6 +243,7 @@ func (t *Team) UnitEnabled(tp unit.Type) bool { } // UnitAccessMode returns if the team has the given unit type enabled +// 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) }