From 033125d4f192332f346570f4898c0e9e984c5479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 20 Feb 2024 16:43:45 +0100 Subject: [PATCH] drop unnecessary grant exists check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../unnecessary-grant-exists-check.md | 5 ++ .../handlers/apps/sharing/shares/shares.go | 51 ------------------- 2 files changed, 5 insertions(+), 51 deletions(-) create mode 100644 changelog/unreleased/unnecessary-grant-exists-check.md diff --git a/changelog/unreleased/unnecessary-grant-exists-check.md b/changelog/unreleased/unnecessary-grant-exists-check.md new file mode 100644 index 0000000000..bd40f3feaa --- /dev/null +++ b/changelog/unreleased/unnecessary-grant-exists-check.md @@ -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 \ No newline at end of file diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index 4ce0c5bf8f..6ebcaf37f7 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -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 != "" { @@ -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 ||