diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-01-20 19:42:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 19:42:33 +0800 |
commit | 6fe3c8b3980f850c9789f9fa62bdfee7b2708ff0 (patch) | |
tree | 5e11864dd63c60564080506291ca93e465c19940 /modules | |
parent | 0c048e554ba42d99bd66c07447de5f35cf6c981b (diff) | |
download | gitea-6fe3c8b3980f850c9789f9fa62bdfee7b2708ff0.tar.gz gitea-6fe3c8b3980f850c9789f9fa62bdfee7b2708ff0.zip |
Support org/user level projects (#22235)
Fix #13405
<img width="1151" alt="image"
src="https://user-images.githubusercontent.com/81045/209442911-7baa3924-c389-47b6-b63b-a740803e640e.png">
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/org.go | 28 |
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 ( |