Skip to content

Commit

Permalink
consider roles when updating a share
Browse files Browse the repository at this point in the history
  • Loading branch information
fschade committed May 18, 2022
1 parent 690fb7f commit 0bf6b56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/ocs-share-update-consider-role.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix role consideration when updating a share

Previously when updating a share the endpoint only considered the permissions, now this also respects a given role.

https://github.com/cs3org/reva/pull/2883

Original file line number Diff line number Diff line change
Expand Up @@ -581,26 +581,36 @@ func (h *Handler) UpdateShare(w http.ResponseWriter, r *http.Request) {
func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, shareID string) {
ctx := r.Context()

pval := r.FormValue("permissions")
if pval == "" {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, "permissions missing", nil)
client, err := pool.GetGatewayServiceClient(h.gatewayAddr)
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err)
return
}

pint, err := strconv.Atoi(pval)
shareR, err := client.GetShare(r.Context(), &collaboration.GetShareRequest{
Ref: &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: &collaboration.ShareId{
OpaqueId: shareID,
},
},
},
})

if err != nil {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, "permissions must be an integer", nil)
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error sending a grpc update share request", err)
return
}
permissions, err := conversions.NewPermissions(pint)
if err != nil {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, err.Error(), nil)

info, status, err := h.getResourceInfoByID(ctx, client, shareR.Share.ResourceId)
if err != nil || status.Code != rpc.Code_CODE_OK {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err)
return
}

client, err := pool.GetGatewayServiceClient(h.gatewayAddr)
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err)
role, _, ocsErr := h.extractPermissions(w, r, info, conversions.NewManagerRole())
if ocsErr != nil {
response.WriteOCSError(w, r, ocsErr.Code, ocsErr.Message, ocsErr.Error)
return
}

Expand All @@ -616,7 +626,7 @@ func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, shareID st
Field: &collaboration.UpdateShareRequest_UpdateField_Permissions{
Permissions: &collaboration.SharePermissions{
// this completely overwrites the permissions for this user
Permissions: conversions.RoleFromOCSPermissions(permissions).CS3ResourcePermissions(),
Permissions: role.CS3ResourcePermissions(),
},
},
},
Expand Down

0 comments on commit 0bf6b56

Please sign in to comment.