1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-23 07:09:43 +02:00

Allow non space creators to manage space settings

Fixes #337
This commit is contained in:
McMatts 2019-11-13 09:49:19 +00:00
parent 7fc74be7cd
commit 0e6f2f1f5e
2 changed files with 27 additions and 5 deletions

View file

@ -147,6 +147,26 @@ func CanUploadDocument(ctx domain.RequestContext, s store.Store, spaceID string)
return false
}
// CanManageSpace returns if the user has permission to manage the given space.
func CanManageSpace(ctx domain.RequestContext, s store.Store, spaceID string) bool {
roles, err := s.Permission.GetUserSpacePermissions(ctx, spaceID)
if err == sql.ErrNoRows {
err = nil
}
if err != nil {
return false
}
for _, role := range roles {
if role.RefID == spaceID && role.Location == pm.LocationSpace && role.Scope == pm.ScopeRow &&
pm.ContainsPermission(role.Action, pm.SpaceManage, pm.SpaceOwner) {
return true
}
}
return false
}
// CanViewSpace returns if the user has permission to view the given spaceID.
func CanViewSpace(ctx domain.RequestContext, s store.Store, spaceID string) bool {
roles, err := s.Permission.GetUserSpacePermissions(ctx, spaceID)