@@ -11,7 +11,6 @@ import (
11
11
"code.gitea.io/gitea/models/perm"
12
12
"code.gitea.io/gitea/models/unit"
13
13
user_model "code.gitea.io/gitea/models/user"
14
- "code.gitea.io/gitea/modules/log"
15
14
"code.gitea.io/gitea/modules/setting"
16
15
"code.gitea.io/gitea/modules/structs"
17
16
)
@@ -31,29 +30,11 @@ type Organization struct {
31
30
}
32
31
33
32
func (org * Organization ) CanWriteUnit (ctx * Context , unitType unit.Type ) bool {
34
- if ctx .Doer == nil {
35
- return false
36
- }
37
- return org .UnitPermission (ctx , ctx .Doer .ID , unitType ) >= perm .AccessModeWrite
33
+ return org .Organization .UnitPermission (ctx , ctx .Doer , unitType ) >= perm .AccessModeWrite
38
34
}
39
35
40
- func (org * Organization ) UnitPermission (ctx * Context , doerID int64 , unitType unit.Type ) perm.AccessMode {
41
- if doerID > 0 {
42
- teams , err := organization .GetUserOrgTeams (ctx , org .Organization .ID , doerID )
43
- if err != nil {
44
- log .Error ("GetUserOrgTeams: %v" , err )
45
- return perm .AccessModeNone
46
- }
47
- if len (teams ) > 0 {
48
- return teams .UnitMaxAccess (unitType )
49
- }
50
- }
51
-
52
- if org .Organization .Visibility == structs .VisibleTypePublic {
53
- return perm .AccessModeRead
54
- }
55
-
56
- return perm .AccessModeNone
36
+ func (org * Organization ) CanReadUnit (ctx * Context , unitType unit.Type ) bool {
37
+ return org .Organization .UnitPermission (ctx , ctx .Doer , unitType ) >= perm .AccessModeRead
57
38
}
58
39
59
40
func GetOrganizationByParams (ctx * Context ) {
@@ -170,6 +151,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
170
151
}
171
152
ctx .Data ["IsOrganizationOwner" ] = ctx .Org .IsOwner
172
153
ctx .Data ["IsOrganizationMember" ] = ctx .Org .IsMember
154
+ ctx .Data ["IsProjectEnabled" ] = true
173
155
ctx .Data ["IsPackageEnabled" ] = setting .Packages .Enabled
174
156
ctx .Data ["IsRepoIndexerEnabled" ] = setting .Indexer .RepoIndexerEnabled
175
157
ctx .Data ["IsPublicMember" ] = func (uid int64 ) bool {
@@ -245,6 +227,10 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
245
227
return
246
228
}
247
229
}
230
+
231
+ ctx .Data ["CanReadProjects" ] = ctx .Org .CanReadUnit (ctx , unit .TypeProjects )
232
+ ctx .Data ["CanReadPackages" ] = ctx .Org .CanReadUnit (ctx , unit .TypePackages )
233
+ ctx .Data ["CanReadCode" ] = ctx .Org .CanReadUnit (ctx , unit .TypeCode )
248
234
}
249
235
250
236
// OrgAssignment returns a middleware to handle organization assignment
0 commit comments