Skip to content

Commit

Permalink
add permissions in the response
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Oct 24, 2023
1 parent 51bccc7 commit bd63731
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions pkg/spaces/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
conversions "github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
)

func init() {
Expand Down Expand Up @@ -115,7 +116,7 @@ func (s *service) userSpace(ctx context.Context, user *userpb.User) *provider.St
func (s *service) projectSpaces(ctx context.Context, user *userpb.User) []*provider.StorageSpace {
projects := []*provider.StorageSpace{}
for _, space := range s.c.Spaces {
if projectBelongToUser(user, &space) {
if perms, ok := projectBelongToUser(user, &space); ok {
projects = append(projects, &provider.StorageSpace{
Id: &provider.StorageSpaceId{
OpaqueId: space.ID,
Expand All @@ -128,19 +129,29 @@ func (s *service) projectSpaces(ctx context.Context, user *userpb.User) []*provi
Name: space.Name,
SpaceType: spaces.SpaceTypeProject.AsString(),
RootInfo: &provider.ResourceInfo{
Path: space.Path,
Path: space.Path,
PermissionSet: perms,
},
})
}
}
return projects
}

func projectBelongToUser(user *userpb.User, project *SpaceDescription) bool {
return user.Id.OpaqueId == project.Owner ||
slices.Contains(user.Groups, project.Admins) ||
slices.Contains(user.Groups, project.Readers) ||
slices.Contains(user.Groups, project.Writers)
func projectBelongToUser(user *userpb.User, project *SpaceDescription) (*provider.ResourcePermissions, bool) {
if user.Id.OpaqueId == project.Owner {
return conversions.NewManagerRole().CS3ResourcePermissions(), true
}
if slices.Contains(user.Groups, project.Admins) {
return conversions.NewManagerRole().CS3ResourcePermissions(), true
}
if slices.Contains(user.Groups, project.Readers) {
return conversions.NewReaderRole().CS3ResourcePermissions(), true
}
if slices.Contains(user.Groups, project.Writers) {
return conversions.NewEditorRole().CS3ResourcePermissions(), true
}
return nil, false
}

func (s *service) UpdateSpace(ctx context.Context, space *provider.StorageSpace) error {
Expand Down

0 comments on commit bd63731

Please sign in to comment.