Skip to content

Commit

Permalink
drop unnecessary grant exists check
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Feb 21, 2024
1 parent cac6c69 commit b97ad6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 51 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/unnecessary-grant-exists-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: drop unnecessary grant exists check

At least the jsoncs3 share manager properly returns an ALREADY_EXISTS response when trying to add a share to a resource that has already been shared with the grantee.

https://github.com/cs3org/reva/pull/4530
Original file line number Diff line number Diff line change
Expand Up @@ -1516,24 +1516,6 @@ func (h *Handler) getResourceInfo(ctx context.Context, client gateway.GatewayAPI

func (h *Handler) createCs3Share(ctx context.Context, w http.ResponseWriter, r *http.Request, client gateway.GatewayAPIClient, req *collaboration.CreateShareRequest) (*collaboration.Share, *ocsError) {
logger := appctx.GetLogger(ctx)
exists, err := h.granteeExists(ctx, req.Grant.Grantee, req.ResourceInfo.Id)
if err != nil {
return nil, &ocsError{
Code: response.MetaServerError.StatusCode,
Message: "error sending a grpc list shares request",
Error: err,
}
}

if exists {
// the grantee already has a share - should we jump to UpdateShare?
// for now - lets error
return nil, &ocsError{
Code: response.MetaBadRequest.StatusCode,
Message: "grantee already has a share on this item",
Error: nil,
}
}

expiry := r.PostFormValue("expireDate")
if expiry != "" {
Expand Down Expand Up @@ -1662,39 +1644,6 @@ func (h *Handler) getHomeNamespace(u *userpb.User) string {
return templates.WithUser(u, h.homeNamespace)
}

func (h *Handler) granteeExists(ctx context.Context, g *provider.Grantee, rid *provider.ResourceId) (bool, error) {
client, err := h.getClient()
if err != nil {
return false, err
}

lsreq := collaboration.ListSharesRequest{
Filters: []*collaboration.Filter{
{
Type: collaboration.Filter_TYPE_RESOURCE_ID,
Term: &collaboration.Filter_ResourceId{
ResourceId: rid,
},
},
},
}
lsres, err := client.ListShares(ctx, &lsreq)
if err != nil {
return false, err
}
if lsres.GetStatus().GetCode() != rpc.Code_CODE_OK {
return false, fmt.Errorf("unexpected status code from ListShares: %v", lsres.GetStatus())
}

for _, s := range lsres.GetShares() {
if utils.GranteeEqual(g, s.GetGrantee()) {
return true, nil
}
}

return false, nil
}

func publicPwdEnforced(c *config.Config) passwordEnforced {
enf := passwordEnforced{}
if c == nil ||
Expand Down

0 comments on commit b97ad6b

Please sign in to comment.