Skip to content

Commit

Permalink
add missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Oct 27, 2023
1 parent 9384f00 commit ab3638d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions internal/http/services/owncloud/ocgraph/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"

"github.com/CiscoM31/godata"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
providerpb "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -75,7 +76,11 @@ func (s *svc) listMySpaces(w http.ResponseWriter, r *http.Request) {
return
}

spaces := list.Map(res.StorageSpaces, s.cs3StorageSpaceToDrive)
me := appctx.ContextMustGetUser(ctx)

spaces := list.Map(res.StorageSpaces, func(space *providerpb.StorageSpace) *libregraph.Drive {
return s.cs3StorageSpaceToDrive(me, space)
})

if err := json.NewEncoder(w).Encode(map[string]any{
"value": spaces,
Expand Down Expand Up @@ -106,14 +111,15 @@ func generateCs3Filters(request *godata.GoDataRequest) ([]*providerpb.ListStorag
return filters.List(), nil
}

func (s *svc) cs3StorageSpaceToDrive(space *providerpb.StorageSpace) *libregraph.Drive {
func (s *svc) cs3StorageSpaceToDrive(user *userpb.User, space *providerpb.StorageSpace) *libregraph.Drive {
drive := &libregraph.Drive{
Id: libregraph.PtrString(space.Id.OpaqueId),
Name: space.Name,
DriveType: libregraph.PtrString(space.SpaceType),
DriveAlias: libregraph.PtrString(space.SpaceType + "/" + space.Name),
Id: libregraph.PtrString(space.Id.OpaqueId),
Name: space.Name,
DriveType: libregraph.PtrString(space.SpaceType),
Root: &libregraph.DriveItem{
Id: libregraph.PtrString(space.Id.OpaqueId),
Permissions: cs3PermissionsToLibreGraph(space.RootInfo.PermissionSet),
Permissions: cs3PermissionsToLibreGraph(user, space.RootInfo.PermissionSet),
},
}

Expand All @@ -135,7 +141,7 @@ func fullUrl(base, path string) string {
return full
}

func cs3PermissionsToLibreGraph(perms *providerpb.ResourcePermissions) []libregraph.Permission {
func cs3PermissionsToLibreGraph(user *userpb.User, perms *providerpb.ResourcePermissions) []libregraph.Permission {
var p libregraph.Permission
// we need to map the permissions to the roles
switch {
Expand All @@ -149,5 +155,13 @@ func cs3PermissionsToLibreGraph(perms *providerpb.ResourcePermissions) []libregr
case perms.Stat:
p.SetRoles([]string{"viewer"})
}
p.GrantedToIdentities = []libregraph.IdentitySet{
{
User: &libregraph.Identity{
DisplayName: user.DisplayName,
Id: &user.Id.OpaqueId,
},
},
}
return []libregraph.Permission{p}
}

0 comments on commit ab3638d

Please sign in to comment.