diff --git a/changelog/unreleased/sharing-filter-methods.md b/changelog/unreleased/sharing-filter-methods.md new file mode 100644 index 0000000000..7b90d29d74 --- /dev/null +++ b/changelog/unreleased/sharing-filter-methods.md @@ -0,0 +1,5 @@ +Enhancement: Add utility methods for creating share filters + +Updated the CS3 API to include the new share grantee filter and added utility methods for creating share filters. This will help making the code more concise. + +https://github.com/cs3org/reva/pull/2044 diff --git a/cmd/reva/ocm-share-list.go b/cmd/reva/ocm-share-list.go index 1bff9bcd3b..ed246a8c26 100644 --- a/cmd/reva/ocm-share-list.go +++ b/cmd/reva/ocm-share-list.go @@ -29,6 +29,7 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/pkg/ocm/share" "github.com/jedib0t/go-pretty/table" ) @@ -60,14 +61,7 @@ func ocmShareListCommand() *command { StorageId: tokens[0], OpaqueId: tokens[1], } - shareRequest.Filters = []*ocm.ListOCMSharesRequest_Filter{ - { - Type: ocm.ListOCMSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &ocm.ListOCMSharesRequest_Filter_ResourceId{ - ResourceId: id, - }, - }, - } + shareRequest.Filters = []*ocm.ListOCMSharesRequest_Filter{share.ResourceIDFilter(id)} } shareRes, err := shareClient.ListOCMShares(ctx, shareRequest) diff --git a/cmd/reva/public-share-list.go b/cmd/reva/public-share-list.go index 1a0a2f1a74..baa13e4ad5 100644 --- a/cmd/reva/public-share-list.go +++ b/cmd/reva/public-share-list.go @@ -29,6 +29,7 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/pkg/publicshare" "github.com/jedib0t/go-pretty/table" ) @@ -60,14 +61,7 @@ func publicShareListCommand() *command { StorageId: tokens[0], OpaqueId: tokens[1], } - shareRequest.Filters = []*link.ListPublicSharesRequest_Filter{ - { - Type: link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &link.ListPublicSharesRequest_Filter_ResourceId{ - ResourceId: id, - }, - }, - } + shareRequest.Filters = []*link.ListPublicSharesRequest_Filter{publicshare.ResourceIDFilter(id)} } shareRes, err := shareClient.ListPublicShares(ctx, shareRequest) diff --git a/cmd/reva/share-list.go b/cmd/reva/share-list.go index 9ec94a5999..fa00b1dc0b 100644 --- a/cmd/reva/share-list.go +++ b/cmd/reva/share-list.go @@ -29,6 +29,7 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/pkg/share" "github.com/jedib0t/go-pretty/table" ) @@ -60,14 +61,7 @@ func shareListCommand() *command { StorageId: tokens[0], OpaqueId: tokens[1], } - shareRequest.Filters = []*collaboration.ListSharesRequest_Filter{ - { - Type: collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &collaboration.ListSharesRequest_Filter_ResourceId{ - ResourceId: id, - }, - }, - } + shareRequest.Filters = []*collaboration.Filter{share.ResourceIDFilter(id)} } shareRes, err := shareClient.ListShares(ctx, shareRequest) diff --git a/go.mod b/go.mod index cfad917fbe..5bce009d7b 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,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-20210812121411-f18cf19614e8 + github.com/cs3org/go-cs3apis v0.0.0-20210906133842-03e4a408c1f3 github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59 github.com/gdexlab/go-render v1.0.1 diff --git a/go.sum b/go.sum index 69435978f2..e8bf204aed 100644 --- a/go.sum +++ b/go.sum @@ -92,6 +92,8 @@ github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJff github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20210812121411-f18cf19614e8 h1:bqUkE0l5wD62TKH6HkbSVYwyYzZ0PIeak/hnW7ggUdU= github.com/cs3org/go-cs3apis v0.0.0-20210812121411-f18cf19614e8/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= +github.com/cs3org/go-cs3apis v0.0.0-20210906133842-03e4a408c1f3 h1:NcLk09WK4wx/iIrEI+7ZFbr78APaRKJxF0+zl6kv4is= +github.com/cs3org/go-cs3apis v0.0.0-20210906133842-03e4a408c1f3/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/grpc/services/usershareprovider/usershareprovider.go b/internal/grpc/services/usershareprovider/usershareprovider.go index 4130dacc77..4a582a40c6 100644 --- a/internal/grpc/services/usershareprovider/usershareprovider.go +++ b/internal/grpc/services/usershareprovider/usershareprovider.go @@ -187,7 +187,7 @@ func (s *service) UpdateShare(ctx context.Context, req *collaboration.UpdateShar } func (s *service) ListReceivedShares(ctx context.Context, req *collaboration.ListReceivedSharesRequest) (*collaboration.ListReceivedSharesResponse, error) { - shares, err := s.sm.ListReceivedShares(ctx) // TODO(labkode): check what to update + shares, err := s.sm.ListReceivedShares(ctx, req.Filters) // TODO(labkode): check what to update if err != nil { return &collaboration.ListReceivedSharesResponse{ Status: status.NewInternal(ctx, err, "error listing received shares"), 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 31409e512d..9b16e8925e 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 @@ -49,7 +49,9 @@ import ( "github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions" "github.com/cs3org/reva/internal/http/services/owncloud/ocs/response" "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/publicshare" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" + "github.com/cs3org/reva/pkg/share" "github.com/cs3org/reva/pkg/share/cache" "github.com/cs3org/reva/pkg/share/cache/registry" "github.com/cs3org/reva/pkg/utils" @@ -607,7 +609,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { func (h *Handler) listSharesWithOthers(w http.ResponseWriter, r *http.Request) { shares := make([]*conversions.ShareData, 0) - filters := []*collaboration.ListSharesRequest_Filter{} + filters := []*collaboration.Filter{} linkFilters := []*link.ListPublicSharesRequest_Filter{} var e error @@ -663,8 +665,8 @@ func (h *Handler) logProblems(s *rpc.Status, e error, msg string) { } } -func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix string) ([]*collaboration.ListSharesRequest_Filter, []*link.ListPublicSharesRequest_Filter, error) { - collaborationFilters := []*collaboration.ListSharesRequest_Filter{} +func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix string) ([]*collaboration.Filter, []*link.ListPublicSharesRequest_Filter, error) { + collaborationFilters := []*collaboration.Filter{} linkFilters := []*link.ListPublicSharesRequest_Filter{} ctx := r.Context() @@ -692,19 +694,9 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri return nil, nil, err } - collaborationFilters = append(collaborationFilters, &collaboration.ListSharesRequest_Filter{ - Type: collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &collaboration.ListSharesRequest_Filter_ResourceId{ - ResourceId: info.Id, - }, - }) + collaborationFilters = append(collaborationFilters, share.ResourceIDFilter(info.Id)) - linkFilters = append(linkFilters, &link.ListPublicSharesRequest_Filter{ - Type: link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &link.ListPublicSharesRequest_Filter_ResourceId{ - ResourceId: info.Id, - }, - }) + linkFilters = append(linkFilters, publicshare.ResourceIDFilter(info.Id)) return collaborationFilters, linkFilters, nil } 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 1a133f34b6..7ce8822d97 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 @@ -120,7 +120,7 @@ func (h *Handler) removeUserShare(w http.ResponseWriter, r *http.Request, shareI response.WriteOCSSuccess(w, r, nil) } -func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.ListSharesRequest_Filter) ([]*conversions.ShareData, *rpc.Status, error) { +func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.Filter) ([]*conversions.ShareData, *rpc.Status, error) { ctx := r.Context() log := appctx.GetLogger(ctx) diff --git a/pkg/cbox/share/sql/sql.go b/pkg/cbox/share/sql/sql.go index ffe2c05e95..05c4a7c559 100644 --- a/pkg/cbox/share/sql/sql.go +++ b/pkg/cbox/share/sql/sql.go @@ -274,13 +274,13 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference return m.GetShare(ctx, ref) } -func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListSharesRequest_Filter) ([]*collaboration.Share, error) { +func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.Share, error) { uid := conversions.FormatUserID(ctxpkg.ContextMustGetUser(ctx).Id) query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, id, stime, permissions, share_type FROM oc_share WHERE (orphan = 0 or orphan IS NULL) AND (uid_owner=? or uid_initiator=?) AND (share_type=? OR share_type=?)" var filterQuery string params := []interface{}{uid, uid, 0, 1} for i, f := range filters { - if f.Type == collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID { + if f.Type == collaboration.Filter_TYPE_RESOURCE_ID { filterQuery += "(fileid_prefix=? AND item_source=?)" if i != len(filters)-1 { filterQuery += " AND " @@ -314,7 +314,7 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListShare } // we list the shares that are targeted to the user in context or to the user groups. -func (m *mgr) ListReceivedShares(ctx context.Context) ([]*collaboration.ReceivedShare, error) { +func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) { user := ctxpkg.ContextMustGetUser(ctx) uid := conversions.FormatUserID(user.Id) diff --git a/pkg/ocm/share/share.go b/pkg/ocm/share/share.go index 9eb439a6e0..e4b7d1188d 100644 --- a/pkg/ocm/share/share.go +++ b/pkg/ocm/share/share.go @@ -55,3 +55,13 @@ type Manager interface { // UpdateReceivedShare updates the received share with share state. UpdateReceivedShare(ctx context.Context, ref *ocm.ShareReference, f *ocm.UpdateReceivedOCMShareRequest_UpdateField) (*ocm.ReceivedShare, error) } + +// ResourceIDFilter is an abstraction for creating filter by resource id. +func ResourceIDFilter(id *provider.ResourceId) *ocm.ListOCMSharesRequest_Filter { + return &ocm.ListOCMSharesRequest_Filter{ + Type: ocm.ListOCMSharesRequest_Filter_TYPE_RESOURCE_ID, + Term: &ocm.ListOCMSharesRequest_Filter_ResourceId{ + ResourceId: id, + }, + } +} diff --git a/pkg/publicshare/publicshare.go b/pkg/publicshare/publicshare.go index 0cab57363a..fa00beb32c 100644 --- a/pkg/publicshare/publicshare.go +++ b/pkg/publicshare/publicshare.go @@ -83,3 +83,13 @@ func AddSignature(share *link.PublicShare, pw string) error { } return nil } + +// ResourceIDFilter is an abstraction for creating filter by resource id. +func ResourceIDFilter(id *provider.ResourceId) *link.ListPublicSharesRequest_Filter { + return &link.ListPublicSharesRequest_Filter{ + Type: link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID, + Term: &link.ListPublicSharesRequest_Filter_ResourceId{ + ResourceId: id, + }, + } +} diff --git a/pkg/share/manager/json/json.go b/pkg/share/manager/json/json.go index 79f3ae3646..fe47803f94 100644 --- a/pkg/share/manager/json/json.go +++ b/pkg/share/manager/json/json.go @@ -354,7 +354,7 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference return nil, errtypes.NotFound(ref.String()) } -func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListSharesRequest_Filter) ([]*collaboration.Share, error) { +func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.Share, error) { var ss []*collaboration.Share m.Lock() defer m.Unlock() @@ -368,7 +368,7 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListShare // check filters // TODO(labkode): add the rest of filters. for _, f := range filters { - if f.Type == collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID { + if f.Type == collaboration.Filter_TYPE_RESOURCE_ID { if utils.ResourceIDEqual(s.ResourceId, f.GetResourceId()) { ss = append(ss, s) } @@ -381,7 +381,7 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListShare } // we list the shares that are targeted to the user in context or to the user groups. -func (m *mgr) ListReceivedShares(ctx context.Context) ([]*collaboration.ReceivedShare, error) { +func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) { var rss []*collaboration.ReceivedShare m.Lock() defer m.Unlock() diff --git a/pkg/share/manager/memory/memory.go b/pkg/share/manager/memory/memory.go index df7e2b9a8e..8f84c77d9b 100644 --- a/pkg/share/manager/memory/memory.go +++ b/pkg/share/manager/memory/memory.go @@ -215,7 +215,7 @@ func (m *manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer return nil, errtypes.NotFound(ref.String()) } -func (m *manager) ListShares(ctx context.Context, filters []*collaboration.ListSharesRequest_Filter) ([]*collaboration.Share, error) { +func (m *manager) ListShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.Share, error) { var ss []*collaboration.Share m.lock.Lock() defer m.lock.Unlock() @@ -229,7 +229,7 @@ func (m *manager) ListShares(ctx context.Context, filters []*collaboration.ListS // check filters // TODO(labkode): add the rest of filters. for _, f := range filters { - if f.Type == collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID { + if f.Type == collaboration.Filter_TYPE_RESOURCE_ID { if utils.ResourceIDEqual(s.ResourceId, f.GetResourceId()) { ss = append(ss, s) } @@ -242,7 +242,7 @@ func (m *manager) ListShares(ctx context.Context, filters []*collaboration.ListS } // we list the shares that are targeted to the user in context or to the user groups. -func (m *manager) ListReceivedShares(ctx context.Context) ([]*collaboration.ReceivedShare, error) { +func (m *manager) ListReceivedShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) { var rss []*collaboration.ReceivedShare m.lock.Lock() defer m.lock.Unlock() diff --git a/pkg/share/manager/sql/sql.go b/pkg/share/manager/sql/sql.go index 6fea507391..c43ef2b377 100644 --- a/pkg/share/manager/sql/sql.go +++ b/pkg/share/manager/sql/sql.go @@ -269,13 +269,13 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference return m.GetShare(ctx, ref) } -func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListSharesRequest_Filter) ([]*collaboration.Share, error) { +func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.Share, error) { uid := ctxpkg.ContextMustGetUser(ctx).Username query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with, coalesce(item_source, '') as item_source, id, stime, permissions, share_type FROM oc_share WHERE (uid_owner=? or uid_initiator=?) AND (share_type=? OR share_type=?)" var filterQuery string params := []interface{}{uid, uid, 0, 1} for i, f := range filters { - if f.Type == collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID { + if f.Type == collaboration.Filter_TYPE_RESOURCE_ID { filterQuery += "(item_source=?)" if i != len(filters)-1 { filterQuery += " AND " @@ -315,7 +315,7 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListShare } // we list the shares that are targeted to the user in context or to the user groups. -func (m *mgr) ListReceivedShares(ctx context.Context) ([]*collaboration.ReceivedShare, error) { +func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) { user := ctxpkg.ContextMustGetUser(ctx) uid := user.Username diff --git a/pkg/share/manager/sql/sql_test.go b/pkg/share/manager/sql/sql_test.go index fd61639fa6..aba406862a 100644 --- a/pkg/share/manager/sql/sql_test.go +++ b/pkg/share/manager/sql/sql_test.go @@ -165,20 +165,15 @@ var _ = Describe("SQL manager", func() { Describe("ListShares", func() { It("lists shares", func() { - shares, err := mgr.ListShares(ctx, []*collaboration.ListSharesRequest_Filter{}) + shares, err := mgr.ListShares(ctx, []*collaboration.Filter{}) Expect(err).ToNot(HaveOccurred()) Expect(len(shares)).To(Equal(1)) - shares, err = mgr.ListShares(ctx, []*collaboration.ListSharesRequest_Filter{ - { - Type: collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID, - Term: &collaboration.ListSharesRequest_Filter_ResourceId{ - ResourceId: &provider.ResourceId{ - StorageId: "/", - OpaqueId: "somethingElse", - }, - }, - }, + shares, err = mgr.ListShares(ctx, []*collaboration.Filter{ + share.ResourceIDFilter(&provider.ResourceId{ + StorageId: "/", + OpaqueId: "somethingElse", + }), }) Expect(err).ToNot(HaveOccurred()) Expect(len(shares)).To(Equal(0)) @@ -188,7 +183,7 @@ var _ = Describe("SQL manager", func() { Describe("ListReceivedShares", func() { It("lists received shares", func() { loginAs(otherUser) - shares, err := mgr.ListReceivedShares(ctx) + shares, err := mgr.ListReceivedShares(ctx, []*collaboration.Filter{}) Expect(err).ToNot(HaveOccurred()) Expect(len(shares)).To(Equal(1)) }) @@ -230,7 +225,7 @@ var _ = Describe("SQL manager", func() { Describe("Unshare", func() { It("deletes shares", func() { loginAs(otherUser) - shares, err := mgr.ListReceivedShares(ctx) + shares, err := mgr.ListReceivedShares(ctx, []*collaboration.Filter{}) Expect(err).ToNot(HaveOccurred()) Expect(len(shares)).To(Equal(1)) @@ -243,7 +238,7 @@ var _ = Describe("SQL manager", func() { Expect(err).ToNot(HaveOccurred()) loginAs(otherUser) - shares, err = mgr.ListReceivedShares(ctx) + shares, err = mgr.ListReceivedShares(ctx, []*collaboration.Filter{}) Expect(err).ToNot(HaveOccurred()) Expect(len(shares)).To(Equal(0)) }) diff --git a/pkg/share/share.go b/pkg/share/share.go index b66bdf8969..9184e0d93c 100644 --- a/pkg/share/share.go +++ b/pkg/share/share.go @@ -41,10 +41,10 @@ type Manager interface { // ListShares returns the shares created by the user. If md is provided is not nil, // it returns only shares attached to the given resource. - ListShares(ctx context.Context, filters []*collaboration.ListSharesRequest_Filter) ([]*collaboration.Share, error) + ListShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.Share, error) // ListReceivedShares returns the list of shares the user has access. - ListReceivedShares(ctx context.Context) ([]*collaboration.ReceivedShare, error) + ListReceivedShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) // GetReceivedShare returns the information for a received share the user has access. GetReceivedShare(ctx context.Context, ref *collaboration.ShareReference) (*collaboration.ReceivedShare, error) @@ -52,3 +52,33 @@ type Manager interface { // UpdateReceivedShare updates the received share with share state. UpdateReceivedShare(ctx context.Context, ref *collaboration.ShareReference, f *collaboration.UpdateReceivedShareRequest_UpdateField) (*collaboration.ReceivedShare, error) } + +// GroupGranteeFilter is an abstraction for creating filter by grantee type group. +func GroupGranteeFilter() *collaboration.Filter { + return &collaboration.Filter{ + Type: collaboration.Filter_TYPE_GRANTEE_TYPE, + Term: &collaboration.Filter_GranteeType{ + GranteeType: provider.GranteeType_GRANTEE_TYPE_GROUP, + }, + } +} + +// UserGranteeFilter is an abstraction for creating filter by grantee type user. +func UserGranteeFilter() *collaboration.Filter { + return &collaboration.Filter{ + Type: collaboration.Filter_TYPE_GRANTEE_TYPE, + Term: &collaboration.Filter_GranteeType{ + GranteeType: provider.GranteeType_GRANTEE_TYPE_USER, + }, + } +} + +// ResourceIDFilter is an abstraction for creating filter by resource id. +func ResourceIDFilter(id *provider.ResourceId) *collaboration.Filter { + return &collaboration.Filter{ + Type: collaboration.Filter_TYPE_RESOURCE_ID, + Term: &collaboration.Filter_ResourceId{ + ResourceId: id, + }, + } +}