github.com/cs3org/reva/v2@v2.27.7/pkg/ocm/share/share.go (about) 1 // Copyright 2018-2023 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package share 20 21 import ( 22 "context" 23 24 userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" 25 ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1" 26 provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" 27 "github.com/cs3org/reva/v2/pkg/errtypes" 28 "google.golang.org/genproto/protobuf/field_mask" 29 ) 30 31 // Repository is the interface that manipulates the OCM shares repository. 32 type Repository interface { 33 // StoreShare stores a share. 34 StoreShare(ctx context.Context, share *ocm.Share) (*ocm.Share, error) 35 36 // GetShare gets the information for a share by the given ref. 37 GetShare(ctx context.Context, user *userpb.User, ref *ocm.ShareReference) (*ocm.Share, error) 38 39 // DeleteShare deletes the share pointed by ref. 40 DeleteShare(ctx context.Context, user *userpb.User, ref *ocm.ShareReference) error 41 42 // UpdateShare updates the mode of the given share. 43 UpdateShare(ctx context.Context, user *userpb.User, ref *ocm.ShareReference, f ...*ocm.UpdateOCMShareRequest_UpdateField) (*ocm.Share, error) 44 45 // ListShares returns the shares created by the user. If md is provided is not nil, 46 // it returns only shares attached to the given resource. 47 ListShares(ctx context.Context, user *userpb.User, filters []*ocm.ListOCMSharesRequest_Filter) ([]*ocm.Share, error) 48 49 // StoreReceivedShare stores a received share. 50 StoreReceivedShare(ctx context.Context, share *ocm.ReceivedShare) (*ocm.ReceivedShare, error) 51 52 // ListReceivedShares returns the list of shares the user has access. 53 ListReceivedShares(ctx context.Context, user *userpb.User) ([]*ocm.ReceivedShare, error) 54 55 // GetReceivedShare returns the information for a received share the user has access. 56 GetReceivedShare(ctx context.Context, user *userpb.User, ref *ocm.ShareReference) (*ocm.ReceivedShare, error) 57 58 // DeleteReceivedShare deletes the share pointed by ref. 59 DeleteReceivedShare(ctx context.Context, user *userpb.User, ref *ocm.ShareReference) error 60 61 // UpdateReceivedShare updates the received share with share state. 62 UpdateReceivedShare(ctx context.Context, user *userpb.User, share *ocm.ReceivedShare, fieldMask *field_mask.FieldMask) (*ocm.ReceivedShare, error) 63 } 64 65 // ResourceIDFilter is an abstraction for creating filter by resource id. 66 func ResourceIDFilter(id *provider.ResourceId) *ocm.ListOCMSharesRequest_Filter { 67 return &ocm.ListOCMSharesRequest_Filter{ 68 Type: ocm.ListOCMSharesRequest_Filter_TYPE_RESOURCE_ID, 69 Term: &ocm.ListOCMSharesRequest_Filter_ResourceId{ 70 ResourceId: id, 71 }, 72 } 73 } 74 75 // ErrShareAlreadyExisting is the error returned when the share already exists 76 // for the 3-tuple consisting of (owner, resource, grantee). 77 var ErrShareAlreadyExisting = errtypes.AlreadyExists("share already exists") 78 79 // ErrShareNotFound is the error returned where the share does not exist. 80 var ErrShareNotFound = errtypes.NotFound("share not found")