From 1e58dc419be06796b44b4e964e3816e63a1db92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 10 May 2022 14:59:28 +0000 Subject: [PATCH] Filter CS3 share manager listing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../filter-cs3-share-manager-listing.md | 5 ++ pkg/share/manager/cs3/cs3.go | 9 +- pkg/share/manager/cs3/cs3_test.go | 87 +++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/filter-cs3-share-manager-listing.md diff --git a/changelog/unreleased/filter-cs3-share-manager-listing.md b/changelog/unreleased/filter-cs3-share-manager-listing.md new file mode 100644 index 0000000000..bd45311839 --- /dev/null +++ b/changelog/unreleased/filter-cs3-share-manager-listing.md @@ -0,0 +1,5 @@ +Bugfix: Filter CS3 share manager listing + +The cs3 share manager driver now correctly filters user and group queries + +https://github.com/cs3org/reva/pull/2853 \ No newline at end of file diff --git a/pkg/share/manager/cs3/cs3.go b/pkg/share/manager/cs3/cs3.go index f1c09010d6..4e6f616007 100644 --- a/pkg/share/manager/cs3/cs3.go +++ b/pkg/share/manager/cs3/cs3.go @@ -404,11 +404,14 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati } for _, id := range receivedIds { - share, err := m.getShareByID(ctx, id) + s, err := m.getShareByID(ctx, id) if err != nil { return nil, err } - metadata, err := m.downloadMetadata(ctx, share) + if !share.MatchesFilters(s, filters) { + continue + } + metadata, err := m.downloadMetadata(ctx, s) if err != nil { if _, ok := err.(errtypes.NotFound); !ok { return nil, err @@ -419,7 +422,7 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati } } result = append(result, &collaboration.ReceivedShare{ - Share: share, + Share: s, State: metadata.State, MountPoint: metadata.MountPoint, }) diff --git a/pkg/share/manager/cs3/cs3_test.go b/pkg/share/manager/cs3/cs3_test.go index 67a9b5c311..97ce8e772c 100644 --- a/pkg/share/manager/cs3/cs3_test.go +++ b/pkg/share/manager/cs3/cs3_test.go @@ -49,6 +49,7 @@ var _ = Describe("Manager", func() { grantee *userpb.User share *collaboration.Share share2 *collaboration.Share + groupShare *collaboration.Share grant *collaboration.ShareGrant ctx context.Context granteeCtx context.Context @@ -134,6 +135,27 @@ var _ = Describe("Manager", func() { }, }, } + groupShare = &collaboration.Share{ + Id: &collaboration.ShareId{OpaqueId: "3"}, + ResourceId: &provider.ResourceId{OpaqueId: "ijkl"}, + Owner: user.GetId(), + Grantee: &provider.Grantee{ + Type: provider.GranteeType_GRANTEE_TYPE_GROUP, + Id: &provider.Grantee_GroupId{GroupId: &groupv1beta1.GroupId{ + Idp: "localhost:1111", + OpaqueId: "users", + }}, + }, + Permissions: &collaboration.SharePermissions{ + Permissions: &provider.ResourcePermissions{ + GetPath: true, + InitiateFileDownload: true, + ListFileVersions: true, + ListContainer: true, + Stat: true, + }, + }, + } ctx = ctxpkg.ContextSetUser(context.Background(), user) granteeCtx = ctxpkg.ContextSetUser(context.Background(), grantee) }) @@ -171,6 +193,9 @@ var _ = Describe("Manager", func() { data, err = json.Marshal(share2) Expect(err).ToNot(HaveOccurred()) storage.On("SimpleDownload", mock.Anything, path.Join("shares", share2.Id.OpaqueId)).Return(data, nil) + data, err = json.Marshal(groupShare) + Expect(err).ToNot(HaveOccurred()) + storage.On("SimpleDownload", mock.Anything, path.Join("shares", groupShare.Id.OpaqueId)).Return(data, nil) data, err = json.Marshal(&cs3.ReceivedShareMetadata{ State: collaboration.ShareState_SHARE_STATE_PENDING, MountPoint: &provider.Reference{ @@ -448,6 +473,68 @@ var _ = Describe("Manager", func() { Expect(rshare.MountPoint.Path).To(Equal("path")) }) }) + + Context("with a received user and group share", func() { + BeforeEach(func() { + indexer.On("FindBy", mock.Anything, + mock.MatchedBy(func(input indexerpkg.Field) bool { + return input.Name == "GranteeId" && input.Value == granteeFn + }), + ). + Return([]string{share.Id.OpaqueId}, nil) + + indexer.On("FindBy", mock.Anything, + mock.MatchedBy(func(input indexerpkg.Field) bool { + return input.Name == "GranteeId" && input.Value == groupFn + }), + ). + Return([]string{groupShare.Id.OpaqueId}, nil) + + indexer.On("FindBy", mock.Anything, + mock.MatchedBy(func(input indexerpkg.Field) bool { + return input.Name == "GranteeId" + }), + ). + Return([]string{}, nil) + }) + + It("list the user and shares", func() { + rshares, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{}) + Expect(err).ToNot(HaveOccurred()) + Expect(rshares).ToNot(BeNil()) + Expect(len(rshares)).To(Equal(2)) + }) + + It("list only the user when user filter is given ", func() { + rshares, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{ + { + Type: collaboration.Filter_TYPE_GRANTEE_TYPE, + Term: &collaboration.Filter_GranteeType{ + GranteeType: provider.GranteeType_GRANTEE_TYPE_USER, + }, + }, + }) + Expect(err).ToNot(HaveOccurred()) + Expect(rshares).ToNot(BeNil()) + Expect(len(rshares)).To(Equal(1)) + Expect(rshares[0].Share.Grantee.Type).To(Equal(provider.GranteeType_GRANTEE_TYPE_USER)) + }) + + It("list only the group when group filter is given ", func() { + rshares, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{ + { + Type: collaboration.Filter_TYPE_GRANTEE_TYPE, + Term: &collaboration.Filter_GranteeType{ + GranteeType: provider.GranteeType_GRANTEE_TYPE_GROUP, + }, + }, + }) + Expect(err).ToNot(HaveOccurred()) + Expect(rshares).ToNot(BeNil()) + Expect(len(rshares)).To(Equal(1)) + Expect(rshares[0].Share.Grantee.Type).To(Equal(provider.GranteeType_GRANTEE_TYPE_GROUP)) + }) + }) }) Describe("GetReceivedShare", func() {