aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/context/org.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/context/org.go b/modules/context/org.go
index 39df29a860..ff3a5ae7ec 100644
--- a/modules/context/org.go
+++ b/modules/context/org.go
@@ -9,7 +9,9 @@ import (
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
+ "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
)
@@ -28,6 +30,32 @@ type Organization struct {
Teams []*organization.Team
}
+func (org *Organization) CanWriteUnit(ctx *Context, unitType unit.Type) bool {
+ if ctx.Doer == nil {
+ return false
+ }
+ return org.UnitPermission(ctx, ctx.Doer.ID, unitType) >= perm.AccessModeWrite
+}
+
+func (org *Organization) UnitPermission(ctx *Context, doerID int64, unitType unit.Type) perm.AccessMode {
+ if doerID > 0 {
+ teams, err := organization.GetUserOrgTeams(ctx, org.Organization.ID, doerID)
+ if err != nil {
+ log.Error("GetUserOrgTeams: %v", err)
+ return perm.AccessModeNone
+ }
+ if len(teams) > 0 {
+ return teams.UnitMaxAccess(unitType)
+ }
+ }
+
+ if org.Organization.Visibility == structs.VisibleTypePublic {
+ return perm.AccessModeRead
+ }
+
+ return perm.AccessModeNone
+}
+
// HandleOrgAssignment handles organization assignment
func HandleOrgAssignment(ctx *Context, args ...bool) {
var (