From 3197597c91d9f6a8db82253c3a5520c1d22f65a5 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 4 Sep 2023 14:55:51 +0200 Subject: [PATCH 1/9] add hide field to reva Signed-off-by: Christian Richter --- pkg/share/manager/json/json.go | 2 ++ pkg/share/manager/jsoncs3/jsoncs3.go | 2 ++ pkg/share/manager/memory/memory.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/pkg/share/manager/json/json.go b/pkg/share/manager/json/json.go index 7f78e226e7..511ea87a83 100644 --- a/pkg/share/manager/json/json.go +++ b/pkg/share/manager/json/json.go @@ -403,6 +403,8 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference m.model.Shares[idx].Permissions = updated.Permissions case "expiration": m.model.Shares[idx].Expiration = updated.Expiration + case "hide": + m.model.Shares[idx].Hide = updated.Hide default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } diff --git a/pkg/share/manager/jsoncs3/jsoncs3.go b/pkg/share/manager/jsoncs3/jsoncs3.go index 2bfeeb0b0d..97ff872d6a 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3.go +++ b/pkg/share/manager/jsoncs3/jsoncs3.go @@ -511,6 +511,8 @@ func (m *Manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer toUpdate.Permissions = updated.Permissions case "expiration": toUpdate.Expiration = updated.Expiration + case "hide": + toUpdate.Hide = updated.Hide default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } diff --git a/pkg/share/manager/memory/memory.go b/pkg/share/manager/memory/memory.go index 2719320dbb..3927613a32 100644 --- a/pkg/share/manager/memory/memory.go +++ b/pkg/share/manager/memory/memory.go @@ -242,6 +242,8 @@ func (m *manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer m.shares[i].Permissions = updated.Permissions case "expiration": m.shares[i].Expiration = updated.Expiration + case "hide": + m.shares[i].Hide = updated.Hide default: return nil, errtypes.NotSupported("updating " + path + " is not supported") } From e9848afe2eaf6b3d1ce22a98db409fe5b1b0658b Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 11 Sep 2023 09:21:45 +0200 Subject: [PATCH 2/9] Implement show-hide for Shares Co-authored-by: Julian Koberg Signed-off-by: Christian Richter --- go.mod | 3 ++- go.sum | 5 ++--- .../http/services/owncloud/ocs/conversions/main.go | 2 ++ .../ocs/handlers/apps/sharing/shares/pending.go | 11 +++++++++-- .../ocs/handlers/apps/sharing/shares/shares.go | 2 +- .../owncloud/ocs/handlers/apps/sharing/shares/user.go | 2 +- pkg/share/manager/jsoncs3/jsoncs3.go | 2 ++ .../jsoncs3/receivedsharecache/receivedsharecache.go | 2 ++ 8 files changed, 21 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f5f050e1ae..4a24c82634 100644 --- a/go.mod +++ b/go.mod @@ -223,4 +223,5 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/cs3org/go-cs3apis => github.com/2403905/go-cs3apis v0.0.0-20230517122726-727045414fd1 +// 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-20230918130959-ae732d4b8147 diff --git a/go.sum b/go.sum index 5ab381a7d6..d6ad28dcea 100644 --- a/go.sum +++ b/go.sum @@ -388,8 +388,6 @@ cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT contrib.go.opencensus.io/exporter/prometheus v0.4.2 h1:sqfsYl5GIY/L570iT+l93ehxaWJs2/OwXtiWwew3oAg= contrib.go.opencensus.io/exporter/prometheus v0.4.2/go.mod h1:dvEHbiKmgvbr5pjaF9fpw1KeYcjrnC1J8B+JKjsZyRQ= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/2403905/go-cs3apis v0.0.0-20230517122726-727045414fd1 h1:dOIG9lXUo5CAZbjlegvZpeTqfAlH+zn+0uXbtlZjCPY= -github.com/2403905/go-cs3apis v0.0.0-20230517122726-727045414fd1/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k= github.com/Azure/azure-storage-blob-go v0.14.0/go.mod h1:SMqIBi+SuiQH32bvyjngEewEeXoPfKMgWlBDaYf6fck= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= @@ -531,6 +529,8 @@ 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-20230918130959-ae732d4b8147 h1:DIEKyIGBNDDzdwnHlbX2BFABHol6c9EEHuCDdVKgWsA= +github.com/dragonchaser/go-cs3apis v0.0.0-20230918130959-ae732d4b8147/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= @@ -1729,7 +1729,6 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6 google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 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/conversions/main.go b/internal/http/services/owncloud/ocs/conversions/main.go index 06fdd6868e..7c2b6ac2ad 100644 --- a/internal/http/services/owncloud/ocs/conversions/main.go +++ b/internal/http/services/owncloud/ocs/conversions/main.go @@ -169,6 +169,7 @@ type ShareData struct { Quicklink bool `json:"quicklink,omitempty" xml:"quicklink,omitempty"` // PasswordProtected represents a public share is password protected // PasswordProtected bool `json:"password_protected,omitempty" xml:"password_protected,omitempty"` + Hide bool `json:"hide" xml:"hide"` } // ShareeData holds share recipient search results @@ -229,6 +230,7 @@ func CS3Share2ShareData(ctx context.Context, share *collaboration.Share) (*Share // Displaynames are added later UIDOwner: LocalUserIDToString(share.GetCreator()), UIDFileOwner: LocalUserIDToString(share.GetOwner()), + Hide: share.Hide, } if share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER { 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 c2e6464fc4..6809315131 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 @@ -48,6 +48,7 @@ const ( // AcceptReceivedShare handles Post Requests on /apps/files_sharing/api/v1/shares/{shareid} func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) { + // TODO: this needs to evaluate the hide form field maybe and pass it on to updateReceivedShare ctx := r.Context() shareID := chi.URLParam(r, shareidkey) client, err := h.getClient() @@ -134,6 +135,7 @@ 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) { + // TODO: this needs to evaluate the hide form field maybe and pass it on to updateReceivedShare shareID := chi.URLParam(r, "shareid") data := h.updateReceivedShare(w, r, shareID, true, "") if data != nil { @@ -151,15 +153,20 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh return nil } + hideFlag, _ := strconv.ParseBool(r.URL.Query().Get("hide")) + // we need to add a path to the share shareRequest := &collaboration.UpdateReceivedShareRequest{ Share: &collaboration.ReceivedShare{ - Share: &collaboration.Share{Id: &collaboration.ShareId{OpaqueId: shareID}}, + Share: &collaboration.Share{ + Id: &collaboration.ShareId{OpaqueId: shareID}, + Hide: hideFlag, + }, MountPoint: &provider.Reference{ Path: mountPoint, }, }, - UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state"}}, + UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}}, } if rejectShare { shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_REJECTED 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 6b64f8a1f5..c0f93288bd 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 @@ -734,7 +734,7 @@ func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, share *col share.Permissions = &collaboration.SharePermissions{Permissions: role.CS3ResourcePermissions()} - var fieldMaskPaths = []string{"permissions"} + var fieldMaskPaths = []string{"permissions", "hide"} expireDate := r.PostFormValue("expireDate") var expirationTs *types.Timestamp diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go index 06975ce5cc..daadd6add3 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go @@ -244,7 +244,7 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.Filte h.addFileInfo(ctx, data, info) h.mapUserIds(ctx, client, data) - + //TODO: get filter list concorrent from a share manager service that deals with hidden shares // Filter out a share if ShareWith is not found because the user or group already deleted if data.ShareWith == "" { continue diff --git a/pkg/share/manager/jsoncs3/jsoncs3.go b/pkg/share/manager/jsoncs3/jsoncs3.go index 97ff872d6a..1a6be96f0c 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3.go +++ b/pkg/share/manager/jsoncs3/jsoncs3.go @@ -999,6 +999,8 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab rs.State = receivedShare.State case "mount_point": rs.MountPoint = receivedShare.MountPoint + case "hide": + rs.Share.Hide = receivedShare.Share.Hide default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } diff --git a/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go b/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go index 7c719aa486..376f4fb787 100644 --- a/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go +++ b/pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go @@ -68,6 +68,7 @@ type Space struct { type State struct { State collaboration.ShareState MountPoint *provider.Reference + Hide bool } // New returns a new Cache instance @@ -117,6 +118,7 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati receivedSpace.States[rs.Share.Id.GetOpaqueId()] = &State{ State: rs.State, MountPoint: rs.MountPoint, + Hide: rs.Share.Hide, } return c.persist(ctx, userID) From bfba14ee4ae1c348221268e8d80d061300d3111b Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 18 Sep 2023 16:10:14 +0200 Subject: [PATCH 3/9] Fix tests Co-authored-by: Julian Koberg Signed-off-by: Christian Richter --- .../handlers/apps/sharing/shares/pending.go | 2 -- pkg/share/manager/jsoncs3/jsoncs3.go | 4 +-- pkg/share/manager/jsoncs3/jsoncs3_test.go | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) 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 6809315131..b408909c2a 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 @@ -48,7 +48,6 @@ const ( // AcceptReceivedShare handles Post Requests on /apps/files_sharing/api/v1/shares/{shareid} func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) { - // TODO: this needs to evaluate the hide form field maybe and pass it on to updateReceivedShare ctx := r.Context() shareID := chi.URLParam(r, shareidkey) client, err := h.getClient() @@ -135,7 +134,6 @@ 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) { - // TODO: this needs to evaluate the hide form field maybe and pass it on to updateReceivedShare shareID := chi.URLParam(r, "shareid") data := h.updateReceivedShare(w, r, shareID, true, "") if data != nil { diff --git a/pkg/share/manager/jsoncs3/jsoncs3.go b/pkg/share/manager/jsoncs3/jsoncs3.go index 1a6be96f0c..8f35cdecba 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3.go +++ b/pkg/share/manager/jsoncs3/jsoncs3.go @@ -511,8 +511,6 @@ func (m *Manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer toUpdate.Permissions = updated.Permissions case "expiration": toUpdate.Expiration = updated.Expiration - case "hide": - toUpdate.Hide = updated.Hide default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } @@ -880,6 +878,7 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati if share.IsGrantedToUser(s, user) { if share.MatchesFiltersWithState(s, state.State, filters) { + s.Hide = state.Hide rs := &collaboration.ReceivedShare{ Share: s, State: state.State, @@ -935,6 +934,7 @@ func (m *Manager) convert(ctx context.Context, userID string, s *collaboration.S if err == nil && state != nil { rs.State = state.State rs.MountPoint = state.MountPoint + rs.Share.Hide = state.Hide } return rs } diff --git a/pkg/share/manager/jsoncs3/jsoncs3_test.go b/pkg/share/manager/jsoncs3/jsoncs3_test.go index f6459effd2..ac74bd8b18 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3_test.go +++ b/pkg/share/manager/jsoncs3/jsoncs3_test.go @@ -957,6 +957,36 @@ var _ = Describe("Jsoncs3", func() { }) Expect(err).ToNot(HaveOccurred()) Expect(rs.MountPoint.Path).To(Equal("newMP")) + Expect(rs.Share.Hide).To(Equal(false)) + }) + + It("hides the share", func() { + rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: share.Id, + }, + }) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.MountPoint).To(BeNil()) + + rs.MountPoint = &providerv1beta1.Reference{ + Path: "newMP", + } + rs.Share.Hide = true + + rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"hide", "mount_point"}}, nil) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.MountPoint.Path).To(Equal("newMP")) + Expect(rs.Share.Hide).To(Equal(true)) + + rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: share.Id, + }, + }) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.MountPoint.Path).To(Equal("newMP")) + Expect(rs.Share.Hide).To(Equal(true)) }) It("handles invalid field masks", func() { From 8ed79e10f1055b05becec6f21f6b24266f5a15dc Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 18 Sep 2023 16:16:13 +0200 Subject: [PATCH 4/9] Add changelog Co-authored-by: Julian Koberg Signed-off-by: Christian Richter --- changelog/unreleased/add-hide-flag-to-shares.md.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/add-hide-flag-to-shares.md.md diff --git a/changelog/unreleased/add-hide-flag-to-shares.md.md b/changelog/unreleased/add-hide-flag-to-shares.md.md new file mode 100644 index 0000000000..c4b8a15c23 --- /dev/null +++ b/changelog/unreleased/add-hide-flag-to-shares.md.md @@ -0,0 +1,7 @@ +Enhancement: Add hide flag to shares + +We have added the ability to hide shares through the +ocs/v2.php/apps/files_sharing/api/v1/shares/pending/ endpoint +by appending a POST-Variable called hide which can be true or false. + +https://github.com/cs3org/reva/pull/4194/files \ No newline at end of file From 8c163c8e088007b580447bf923f2002876b02cf0 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 18 Sep 2023 16:18:38 +0200 Subject: [PATCH 5/9] remove obsolete comment Signed-off-by: Christian Richter --- .../services/owncloud/ocs/handlers/apps/sharing/shares/user.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go index daadd6add3..14037c3510 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go @@ -244,7 +244,6 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.Filte h.addFileInfo(ctx, data, info) h.mapUserIds(ctx, client, data) - //TODO: get filter list concorrent from a share manager service that deals with hidden shares // Filter out a share if ShareWith is not found because the user or group already deleted if data.ShareWith == "" { continue From bf5be20175eea30823a916d3a698c3c79405cf7b Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 20 Sep 2023 16:07:17 +0200 Subject: [PATCH 6/9] add additional tests Signed-off-by: Christian Richter --- pkg/share/manager/jsoncs3/jsoncs3_test.go | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/pkg/share/manager/jsoncs3/jsoncs3_test.go b/pkg/share/manager/jsoncs3/jsoncs3_test.go index ac74bd8b18..3f17b9674e 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3_test.go +++ b/pkg/share/manager/jsoncs3/jsoncs3_test.go @@ -1060,6 +1060,79 @@ var _ = Describe("Jsoncs3", func() { Expect(err).ToNot(HaveOccurred()) Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED)) }) + + It("hides share and persists the change", func() { + rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: gshare.Id, + }, + }) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_PENDING)) + + rs.State = collaboration.ShareState_SHARE_STATE_ACCEPTED + rs.Share.Hide = true + rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}}, nil) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED)) + Expect(rs.Share.Hide).To(Equal(true)) + + m, err := jsoncs3.New(storage, nil, 0, nil, 0) // Reset in-memory cache + Expect(err).ToNot(HaveOccurred()) + + rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: gshare.Id, + }, + }) + Expect(rs.Share.Hide).To(Equal(true)) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED)) + }) + + It("hides and unhides the share and persists the change", func() { + rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: gshare.Id, + }, + }) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_PENDING)) + + rs.State = collaboration.ShareState_SHARE_STATE_ACCEPTED + rs.Share.Hide = true + rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}}, nil) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED)) + Expect(rs.Share.Hide).To(Equal(true)) + + m, err := jsoncs3.New(storage, nil, 0, nil, 0) // Reset in-memory cache + Expect(err).ToNot(HaveOccurred()) + + rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: gshare.Id, + }, + }) + Expect(rs.Share.Hide).To(Equal(true)) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED)) + + rs.Share.Hide = false + rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}}, nil) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED)) + Expect(rs.Share.Hide).To(Equal(false)) + + rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{ + Spec: &collaboration.ShareReference_Id{ + Id: gshare.Id, + }, + }) + Expect(rs.Share.Hide).To(Equal(false)) + Expect(err).ToNot(HaveOccurred()) + Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED)) + }) }) }) }) From 538f29716aaddc10f24518ec2932d0c15f6d40ba Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 20 Sep 2023 17:33:04 +0200 Subject: [PATCH 7/9] [Experiment] try to bypass issues with go 1.21.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jörn Dreyer Signed-off-by: Christian Richter --- pkg/appctx/ctxmap.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/pkg/appctx/ctxmap.go b/pkg/appctx/ctxmap.go index a7e10eaa8a..1acdec7bd9 100644 --- a/pkg/appctx/ctxmap.go +++ b/pkg/appctx/ctxmap.go @@ -41,20 +41,24 @@ func GetKeyValuesFromCtx(ctx context.Context) map[interface{}]interface{} { } func getKeyValue(ctx interface{}, m map[interface{}]interface{}) { - ctxVals := reflect.ValueOf(ctx).Elem() - ctxType := reflect.TypeOf(ctx).Elem() + // This is a dirty hack to run with go 1.21.x + reflectCtxValues := reflect.ValueOf(ctx) + if reflectCtxValues.Kind() != reflect.Struct { + ctxVals := reflectCtxValues.Elem() + ctxType := reflect.TypeOf(ctx).Elem() - if ctxType.Kind() == reflect.Struct { - for i := 0; i < ctxVals.NumField(); i++ { - currField, currIf := extractField(ctxVals, ctxType, i) - switch currField { - case "Context": - getKeyValue(currIf, m) - case "key": - nextField, nextIf := extractField(ctxVals, ctxType, i+1) - if nextField == "val" { - m[currIf] = nextIf - i++ + if ctxType.Kind() == reflect.Struct { + for i := 0; i < ctxVals.NumField(); i++ { + currField, currIf := extractField(ctxVals, ctxType, i) + switch currField { + case "Context": + getKeyValue(currIf, m) + case "key": + nextField, nextIf := extractField(ctxVals, ctxType, i+1) + if nextField == "val" { + m[currIf] = nextIf + i++ + } } } } From c9a314f217e9c05c8578f91388f1181bebfee290 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Fri, 22 Sep 2023 10:25:20 +0200 Subject: [PATCH 8/9] Add missing cases to all managers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jörn Dreyer Co-authored-by: Julian Koberg Signed-off-by: Christian Richter --- pkg/share/manager/cs3/cs3.go | 2 ++ pkg/share/manager/json/json.go | 2 +- pkg/share/manager/memory/memory.go | 2 ++ pkg/share/manager/owncloudsql/owncloudsql.go | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/share/manager/cs3/cs3.go b/pkg/share/manager/cs3/cs3.go index ed5d665c2e..f0ac9a1351 100644 --- a/pkg/share/manager/cs3/cs3.go +++ b/pkg/share/manager/cs3/cs3.go @@ -638,6 +638,8 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, rshare *collaboration rs.State = rshare.State case "mount_point": rs.MountPoint = rshare.MountPoint + case "hide": + continue default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } diff --git a/pkg/share/manager/json/json.go b/pkg/share/manager/json/json.go index 511ea87a83..31c20c27d5 100644 --- a/pkg/share/manager/json/json.go +++ b/pkg/share/manager/json/json.go @@ -404,7 +404,7 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference case "expiration": m.model.Shares[idx].Expiration = updated.Expiration case "hide": - m.model.Shares[idx].Hide = updated.Hide + continue default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } diff --git a/pkg/share/manager/memory/memory.go b/pkg/share/manager/memory/memory.go index 3927613a32..6d2c3a1791 100644 --- a/pkg/share/manager/memory/memory.go +++ b/pkg/share/manager/memory/memory.go @@ -361,6 +361,8 @@ func (m *manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab rs.State = receivedShare.State case "mount_point": rs.MountPoint = receivedShare.MountPoint + case "hide": + continue default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } diff --git a/pkg/share/manager/owncloudsql/owncloudsql.go b/pkg/share/manager/owncloudsql/owncloudsql.go index d5f28c4a12..34fe52a5a9 100644 --- a/pkg/share/manager/owncloudsql/owncloudsql.go +++ b/pkg/share/manager/owncloudsql/owncloudsql.go @@ -447,6 +447,8 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, receivedShare *collaborat fields = append(fields, "file_target=?") rs.MountPoint = receivedShare.MountPoint params = append(params, rs.MountPoint.Path) + case "hide": + continue default: return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported") } From 10a931cae67a2ccd0e170b9acfab2d2d86eb32f7 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 25 Sep 2023 09:31:44 +0200 Subject: [PATCH 9/9] add option to filter out hidden in list shares Signed-off-by: Christian Richter --- .../owncloud/ocs/handlers/apps/sharing/shares/shares.go | 5 +++++ 1 file changed, 5 insertions(+) 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 c0f93288bd..f2c0737bb2 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 @@ -863,6 +863,8 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { // which pending state to list stateFilter := getStateFilter(r.FormValue("state")) + showHidden, _ := strconv.ParseBool(r.URL.Query().Get("show_hidden")) + ctx := r.Context() p := r.URL.Query().Get("path") shareRef := r.URL.Query().Get("share_ref") @@ -950,6 +952,9 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { // TODO(refs) filter out "invalid" shares for _, rs := range lrsRes.GetShares() { + if rs.Share.Hide && !showHidden { + continue + } if stateFilter != ocsStateUnknown && rs.GetState() != stateFilter { continue }