Skip to content

Commit

Permalink
Check for remaining space manager when updating space permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed May 25, 2023
1 parent 07a8178 commit 9e53b11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/keep-last-space-manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Prevent last space manager from leaving

It should not be possible for the last remaining space manager to change his role or get changed by others.

https://github.com/cs3org/reva/pull/3917
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ func (h *Handler) addSpaceMember(w http.ResponseWriter, r *http.Request, info *p
Nanos: uint32(expiration.UnixNano() % int64(time.Second)),
}
}

if role.Name != conversions.RoleManager {
ref := provider.Reference{ResourceId: info.GetId()}
p, err := h.findProvider(ctx, &ref)
if err != nil {
response.WriteOCSError(w, r, response.MetaNotFound.StatusCode, "error getting storage provider", err)
return
}

providerClient, err := h.getStorageProviderClient(p)
if err != nil {
response.WriteOCSError(w, r, response.MetaNotFound.StatusCode, "error getting storage provider client", err)
return
}

lgRes, err := providerClient.ListGrants(ctx, &provider.ListGrantsRequest{Ref: &ref})
if err != nil || lgRes.Status.Code != rpc.Code_CODE_OK {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error listing space grants", err)
return
}

if !isSpaceManagerRemaining(lgRes.Grants, grantee) {
response.WriteOCSError(w, r, http.StatusForbidden, "the space must have at least one manager", nil)
return
}
}

createShareRes, err := client.CreateShare(ctx, &collaborationv1beta1.CreateShareRequest{
ResourceInfo: info,
Grant: &collaborationv1beta1.ShareGrant{
Expand Down

0 comments on commit 9e53b11

Please sign in to comment.