Skip to content

Commit

Permalink
get root drive permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Aug 5, 2024
1 parent 1cb23c7 commit d6b930b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions internal/http/services/owncloud/ocgraph/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/cs3org/reva/pkg/rhttp/router"
"github.com/cs3org/reva/pkg/spaces"
"github.com/cs3org/reva/pkg/utils/list"
"github.com/go-chi/chi/v5"
libregraph "github.com/owncloud/libre-graph-api-go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -370,3 +371,52 @@ func cs3PermissionsToLibreGraph(user *userpb.User, perms *providerpb.ResourcePer
func (s *svc) getDrivePermissions(w http.ResponseWriter, r *http.Request) {

}

func (s *svc) getRootDrivePermissions(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := appctx.GetLogger(ctx)

spaceID := chi.URLParam(r, "space-id")

_, path, ok := spaces.DecodeSpaceID(spaceID)
if !ok {
log.Error().Msg("error getting space by id")
w.WriteHeader(http.StatusBadRequest)
return
}

gw, err := s.getClient()
if err != nil {
log.Error().Err(err).Msg("error getting grpc client")
w.WriteHeader(http.StatusInternalServerError)
return
}

statRes, err := gw.Stat(ctx, &providerpb.StatRequest{
Ref: &providerpb.Reference{
Path: path,
},
})
if err != nil {
log.Error().Err(err).Msg("error getting space by id")
w.WriteHeader(http.StatusInternalServerError)
return
}
if statRes.Status.Code != rpcv1beta1.Code_CODE_OK {
log.Error().Str("path", path).Int("code", int(statRes.Status.Code)).Str("message", statRes.Status.Message).Msg("error statting resource")
w.WriteHeader(http.StatusInternalServerError)
return
}

actions := CS3ResourcePermissionsToLibregraphActions(statRes.Info.PermissionSet)
role := CS3ResourcePermissionsToUnifiedRole(statRes.Info.PermissionSet)

if err := json.NewEncoder(w).Encode(map[string]any{
"@libre.graph.permissions.actions.allowedValues": actions,
"@libre.graph.permissions.roles.allowedValues": []*libregraph.UnifiedRoleDefinition{role},
}); err != nil {
log.Error().Err(err).Msg("error marshalling spaces as json")
w.WriteHeader(http.StatusInternalServerError)
return
}
}
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocgraph/ocgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s *svc) initRouter() {
r.Get("/sharedByMe", s.getSharedByMe)
})
r.Get("/roleManagement/permissions/roleDefinitions", s.getRoleDefinitions)
r.Get("/drives/{space-id}/root/permissions", s.getDrivePermissions)
r.Get("/drives/{space-id}/root/permissions", s.getRootDrivePermissions)
r.Get("/drives/{space-id}/items/{item-id}/permissions", s.getDrivePermissions)
})
// /graph/v1beta1/drives/166d1210-cdb9-50ab-9f1e-ecb9ef12a304%244c510ada-c86b-4815-8820-42cdf82c3d51/items/166d1210-cdb9-50ab-9f1e-ecb9ef12a304%244c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51/permissions
Expand Down

0 comments on commit d6b930b

Please sign in to comment.