aboutsummaryrefslogtreecommitdiffstats
path: root/models/organization
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-04-17 16:31:37 +0800
committerGitHub <noreply@github.com>2024-04-17 08:31:37 +0000
commit3e2e76e2484c79715ab5d56f268ea3ad8e1c259b (patch)
treeec1a5e2dd015a17a5833abe3bdc758095ac53250 /models/organization
parent4f276a336355c4bf999034fb79f0fe5c967ceb50 (diff)
downloadgitea-3e2e76e2484c79715ab5d56f268ea3ad8e1c259b.tar.gz
gitea-3e2e76e2484c79715ab5d56f268ea3ad8e1c259b.zip
Refactor web routes (#30519)
Re-organize the routes in web.go and use ctx constants instead of `context.UnitTypes()` --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'models/organization')
-rw-r--r--models/organization/team.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/models/organization/team.go b/models/organization/team.go
index 17db11c42d..501a43d3a1 100644
--- a/models/organization/team.go
+++ b/models/organization/team.go
@@ -174,23 +174,27 @@ func (t *Team) LoadMembers(ctx context.Context) (err error) {
return err
}
-// UnitEnabled returns if the team has the given unit type enabled
+// UnitEnabled returns true if the team has the given unit type enabled
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
+// UnitAccessMode returns the access mode for the given unit type, "none" for non-existent units
func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode {
+ accessMode, _ := t.UnitAccessModeEx(ctx, tp)
+ return accessMode
+}
+
+func (t *Team) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
if err := t.LoadUnits(ctx); err != nil {
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
}
-
- for _, unit := range t.Units {
- if unit.Type == tp {
- return unit.AccessMode
+ for _, u := range t.Units {
+ if u.Type == tp {
+ return u.AccessMode, true
}
}
- return perm.AccessModeNone
+ return perm.AccessModeNone, false
}
// IsUsableTeamName tests if a name could be as team name