Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop unnecessary grant exists check #4530

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading