diff --git a/go.mod b/go.mod index 34536b68ab3..027d1d6b834 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/cheggaaa/pb v1.0.29 github.com/coreos/go-oidc v2.2.1+incompatible github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e - github.com/cs3org/go-cs3apis v0.0.0-20230727093620-0f4399be4543 + github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 github.com/dgraph-io/ristretto v0.1.1 github.com/emvi/iso-639-1 v1.0.1 github.com/eventials/go-tus v0.0.0-20220610120217-05d0564bb571 @@ -227,6 +227,3 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -// the replacement build is based on https://github.com/dragonchaser/cs3apis/tree/master -replace github.com/cs3org/go-cs3apis => github.com/dragonchaser/go-cs3apis v0.0.0-20231018101134-aadeeb03233c diff --git a/go.sum b/go.sum index ad7997abf42..d2c4660fa98 100644 --- a/go.sum +++ b/go.sum @@ -519,6 +519,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= +github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 h1:BUdwkIlf8IS2FasrrPg8gGPHQPOrQ18MS1Oew2tmGtY= +github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -529,8 +531,6 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUn github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dragonchaser/go-cs3apis v0.0.0-20231018101134-aadeeb03233c h1:W12nbHzbDqM4WNDtEUNJXEzLK//0JpvKp0OdGc/yvwA= -github.com/dragonchaser/go-cs3apis v0.0.0-20231018101134-aadeeb03233c/go.mod h1:TKUgPjk4kNU0KLd9ZxoFE74Wv6PiXckF4RB3749FztA= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= @@ -1745,6 +1745,7 @@ google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAs google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go index ed55fe436c3..414078da0a3 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/pending.go @@ -122,9 +122,22 @@ func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) { // TODO we could delete shares here if the stat returns code NOT FOUND ... but listening for file deletes would be better } } + // we need to add a path to the share + shareRequest := &collaboration.UpdateReceivedShareRequest{ + Share: &collaboration.ReceivedShare{ + Share: &collaboration.Share{ + Id: &collaboration.ShareId{OpaqueId: shareID}, + }, + State: collaboration.ShareState_SHARE_STATE_ACCEPTED, + MountPoint: &provider.Reference{ + Path: mount, + }, + }, + UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}}, + } for id := range sharesToAccept { - data := h.updateReceivedShare(w, r, id, mount, &fieldmaskpb.FieldMask{}) + data := h.updateReceivedShare(w, r, shareRequest) // only render the data for the changed share if id == shareID && data != nil { response.WriteOCSSuccess(w, r, []*conversions.ShareData{data}) @@ -135,8 +148,17 @@ func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) { // RejectReceivedShare handles DELETE Requests on /apps/files_sharing/api/v1/shares/{shareid} func (h *Handler) RejectReceivedShare(w http.ResponseWriter, r *http.Request) { shareID := chi.URLParam(r, "shareid") - fieldMask := &fieldmaskpb.FieldMask{Paths: []string{"rejectshare"}} - data := h.updateReceivedShare(w, r, shareID, "", fieldMask) + // we need to add a path to the share + shareRequest := &collaboration.UpdateReceivedShareRequest{ + Share: &collaboration.ReceivedShare{ + Share: &collaboration.Share{ + Id: &collaboration.ShareId{OpaqueId: shareID}, + }, + State: collaboration.ShareState_SHARE_STATE_REJECTED, + }, + UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}}, + } + data := h.updateReceivedShare(w, r, shareRequest) if data != nil { response.WriteOCSSuccess(w, r, []*conversions.ShareData{data}) } @@ -144,32 +166,13 @@ func (h *Handler) RejectReceivedShare(w http.ResponseWriter, r *http.Request) { func (h *Handler) UpdateReceivedShare(w http.ResponseWriter, r *http.Request) { shareID := chi.URLParam(r, "shareid") - fieldMask := &fieldmaskpb.FieldMask{Paths: []string{"hidden"}} - data := h.updateReceivedShare(w, r, shareID, "", fieldMask) - if data != nil { - response.WriteOCSSuccess(w, r, []*conversions.ShareData{data}) - } -} - -func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, shareID, mountPoint string, fieldmask *fieldmaskpb.FieldMask) *conversions.ShareData { - var rejectShare, hideFlag bool - for i := range fieldmask.Paths { - switch fieldmask.Paths[i] { - case "rejectshare": - rejectShare = true - case "mountpoint": - continue - case "hidden": - hideFlag, _ = strconv.ParseBool(r.URL.Query().Get("hidden")) - } - } - ctx := r.Context() - logger := appctx.GetLogger(ctx) + hideFlag, _ := strconv.ParseBool(r.URL.Query().Get("hidden")) + // unfortunately we need to get the share first to read the state client, err := h.getClient() if err != nil { response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err) - return nil + return } // we need to add a path to the share @@ -178,21 +181,34 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh Share: &collaboration.Share{ Id: &collaboration.ShareId{OpaqueId: shareID}, }, - MountPoint: &provider.Reference{ - Path: mountPoint, - }, Hidden: hideFlag, }, UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}}, } - if rejectShare { - shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_REJECTED - } else { - shareRequest.UpdateMask.Paths = append(shareRequest.UpdateMask.Paths, "mount_point") - shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_ACCEPTED + + rs, _ := getReceivedShareFromID(r.Context(), client, shareID) + if rs != nil && rs.Share != nil { + shareRequest.Share.State = rs.Share.State + } + + data := h.updateReceivedShare(w, r, shareRequest) + if data != nil { + response.WriteOCSSuccess(w, r, []*conversions.ShareData{data}) + } + // TODO: do we need error handling here? +} + +func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, updateShareRequest *collaboration.UpdateReceivedShareRequest) *conversions.ShareData { + ctx := r.Context() + logger := appctx.GetLogger(ctx) + + client, err := h.getClient() + if err != nil { + response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err) + return nil } - shareRes, err := client.UpdateReceivedShare(ctx, shareRequest) + shareRes, err := client.UpdateReceivedShare(ctx, updateShareRequest) if err != nil { response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "grpc update received share request failed", err) return nil