Skip to content

Commit

Permalink
work on api change
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Sep 9, 2021
1 parent f55d2e8 commit c0acb58
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 61 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ require (
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987
google.golang.org/grpc v1.39.1
google.golang.org/protobuf v1.27.1
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
Expand All @@ -79,6 +80,8 @@ require (
go 1.16

replace (
// FIXME remove the replace when upstream has merged https://github.com/cs3org/cs3apis/pull/144 and synced https://github.com/cs3org/go-cs3apis/pull/44
github.com/cs3org/go-cs3apis => github.com/butonic/go-cs3apis v0.0.0-20210909065123-65fad97da587
github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a
github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ github.com/bluele/gcache v0.0.2 h1:WcbfdXICg7G/DGBh1PFfcirkWOQV+v077yF1pSy3DGw=
github.com/bluele/gcache v0.0.2/go.mod h1:m15KV+ECjptwSPxKhOhQoAFQVtUFjTVkc3H8o0t/fp0=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40 h1:y4B3+GPxKlrigF1ha5FFErxK+sr6sWxQovRMzwMhejo=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/butonic/go-cs3apis v0.0.0-20210909065123-65fad97da587 h1:WiZk32Qu+5NFJy/E6zOQmZxUGAcsGPXq8yWIsYI0cNA=
github.com/butonic/go-cs3apis v0.0.0-20210909065123-65fad97da587/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/c-bata/go-prompt v0.2.5 h1:3zg6PecEywxNn0xiqcXHD96fkbxghD+gdB2tbsYfl+Y=
github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand All @@ -90,10 +92,6 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
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-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=
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/interceptors/auth/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func extractShareRef(req interface{}) (*collaboration.ShareReference, bool) {
case *collaboration.GetReceivedShareRequest:
return v.GetRef(), true
case *collaboration.UpdateReceivedShareRequest:
return v.GetRef(), true
return &collaboration.ShareReference{Spec: &collaboration.ShareReference_Id{Id: v.GetShare().GetShare().GetId()}}, true
}
return nil, false
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (s *service) ListReceivedOCMShares(ctx context.Context, req *ocm.ListReceiv
}

func (s *service) UpdateReceivedOCMShare(ctx context.Context, req *ocm.UpdateReceivedOCMShareRequest) (*ocm.UpdateReceivedOCMShareResponse, error) {
_, err := s.sm.UpdateReceivedShare(ctx, req.Ref, req.Field) // TODO(labkode): check what to update
_, err := s.sm.UpdateReceivedShare(ctx, req.Share, req.UpdateMask) // TODO(labkode): check what to update
if err != nil {
return &ocm.UpdateReceivedOCMShareResponse{
Status: status.NewInternal(ctx, err, "error updating received share"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
gstatus "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/fieldmaskpb"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
Expand Down Expand Up @@ -854,18 +855,11 @@ func (s *service) rejectReceivedShare(ctx context.Context, share string) error {
return err
}

ref := &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: stattedShare.ReceivedShare.Share.Id,
},
}
stattedShare.ReceivedShare.State = collaboration.ShareState_SHARE_STATE_REJECTED

_, err = s.sharesProviderClient.UpdateReceivedShare(ctx, &collaboration.UpdateReceivedShareRequest{
Ref: ref,
Field: &collaboration.UpdateReceivedShareRequest_UpdateField{
Field: &collaboration.UpdateReceivedShareRequest_UpdateField_State{
State: collaboration.ShareState_SHARE_STATE_REJECTED,
},
},
Share: stattedShare.ReceivedShare,
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state"}},
})
return err
}
Expand Down
24 changes: 23 additions & 1 deletion internal/grpc/services/usershareprovider/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,29 @@ func (s *service) GetReceivedShare(ctx context.Context, req *collaboration.GetRe
}

func (s *service) UpdateReceivedShare(ctx context.Context, req *collaboration.UpdateReceivedShareRequest) (*collaboration.UpdateReceivedShareResponse, error) {
share, err := s.sm.UpdateReceivedShare(ctx, req.Ref, req.Field) // TODO(labkode): check what to update

if req.Share == nil {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalidArg(ctx, "updating requires a received share object"),
}, nil
}
if req.Share.Share == nil {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalidArg(ctx, "share missing"),
}, nil
}
if req.Share.Share.Id == nil {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalidArg(ctx, "share id missing"),
}, nil
}
if req.Share.Share.Id.OpaqueId == "" {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalidArg(ctx, "share id empty"),
}, nil
}

share, err := s.sm.UpdateReceivedShare(ctx, req.Share, req.UpdateMask)
if err != nil {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInternal(ctx, err, "error updating received share"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/go-chi/chi/v5"
"github.com/pkg/errors"
"google.golang.org/protobuf/types/known/fieldmaskpb"
)

// AcceptReceivedShare handles Post Requests on /apps/files_sharing/api/v1/shares/{shareid}
Expand All @@ -54,28 +55,14 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh
return
}

ref := &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: &collaboration.ShareId{
OpaqueId: shareID,
},
},
}

shareRequest := &collaboration.UpdateReceivedShareRequest{
Ref: ref,
Field: &collaboration.UpdateReceivedShareRequest_UpdateField{
Field: &collaboration.UpdateReceivedShareRequest_UpdateField_State{
State: collaboration.ShareState_SHARE_STATE_ACCEPTED,
},
},
Share: &collaboration.ReceivedShare{Share: &collaboration.Share{Id: &collaboration.ShareId{OpaqueId: shareID}}},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state"}},
}
if rejectShare {
shareRequest.Field = &collaboration.UpdateReceivedShareRequest_UpdateField{
Field: &collaboration.UpdateReceivedShareRequest_UpdateField_State{
State: collaboration.ShareState_SHARE_STATE_REJECTED,
},
}
shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_REJECTED
} else {
shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_ACCEPTED
}

shareRes, err := client.UpdateReceivedShare(ctx, shareRequest)
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/scope/receivedshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func receivedShareScope(scope *authpb.Scope, resource interface{}) (bool, error)
case *collaboration.GetReceivedShareRequest:
return checkShareRef(share.Share, v.GetRef()), nil
case *collaboration.UpdateReceivedShareRequest:
return checkShareRef(share.Share, v.GetRef()), nil
return checkShare(share.Share, v.GetShare().GetShare()), nil
case string:
return checkSharePath(v) || checkResourcePath(v), nil
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/auth/scope/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func checkShareRef(s *collaboration.Share, ref *collaboration.ShareReference) bo
}
return false
}
func checkShare(s1 *collaboration.Share, s2 *collaboration.Share) bool {
if s2.GetId() != nil {
return s2.GetId().OpaqueId == s1.Id.OpaqueId
}
return false
}

func checkSharePath(path string) bool {
paths := []string{
Expand Down
19 changes: 15 additions & 4 deletions pkg/cbox/share/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/cs3org/reva/pkg/utils"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"google.golang.org/genproto/protobuf/field_mask"

// Provides mysql drivers
_ "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -423,17 +424,28 @@ func (m *mgr) GetReceivedShare(ctx context.Context, ref *collaboration.ShareRefe

}

func (m *mgr) UpdateReceivedShare(ctx context.Context, ref *collaboration.ShareReference, f *collaboration.UpdateReceivedShareRequest_UpdateField) (*collaboration.ReceivedShare, error) {
func (m *mgr) UpdateReceivedShare(ctx context.Context, share *collaboration.ReceivedShare, fieldMask *field_mask.FieldMask) (*collaboration.ReceivedShare, error) {
user := ctxpkg.ContextMustGetUser(ctx)

rs, err := m.GetReceivedShare(ctx, ref)
rs, err := m.GetReceivedShare(ctx, &collaboration.ShareReference{Spec: &collaboration.ShareReference_Id{Id: share.Share.Id}})
if err != nil {
return nil, err
}

for i := range fieldMask.Paths {
switch fieldMask.Paths[i] {
case "state":
rs.State = share.State
case "mount_point":
rs.MountPoint = share.MountPoint
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
}

var query, queryAccept string
params := []interface{}{rs.Share.Id.OpaqueId, conversions.FormatUserID(user.Id)}
switch f.GetState() {
switch rs.State {
case collaboration.ShareState_SHARE_STATE_REJECTED:
query = "insert into oc_share_acl(id, rejected_by) values(?, ?)"
case collaboration.ShareState_SHARE_STATE_ACCEPTED:
Expand Down Expand Up @@ -461,6 +473,5 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, ref *collaboration.ShareR
}
}

rs.State = f.GetState()
return rs, nil
}
17 changes: 14 additions & 3 deletions pkg/ocm/share/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/google/uuid"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"google.golang.org/genproto/protobuf/field_mask"
)

const createOCMCoreShareEndpoint = "shares"
Expand Down Expand Up @@ -644,21 +645,31 @@ func (m *mgr) getReceived(ctx context.Context, ref *ocm.ShareReference) (*ocm.Re
return nil, errtypes.NotFound(ref.String())
}

func (m *mgr) UpdateReceivedShare(ctx context.Context, ref *ocm.ShareReference, f *ocm.UpdateReceivedOCMShareRequest_UpdateField) (*ocm.ReceivedShare, error) {
rs, err := m.getReceived(ctx, ref)
func (m *mgr) UpdateReceivedShare(ctx context.Context, share *ocm.ReceivedShare, fieldMask *field_mask.FieldMask) (*ocm.ReceivedShare, error) {
rs, err := m.getReceived(ctx, &ocm.ShareReference{Spec: &ocm.ShareReference_Id{Id: share.Share.Id}})
if err != nil {
return nil, err
}

m.Lock()
defer m.Unlock()

for i := range fieldMask.Paths {
switch fieldMask.Paths[i] {
case "state":
rs.State = share.State
case "mount_point":
rs.MountPoint = share.MountPoint
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
}

if err := m.model.ReadFile(); err != nil {
err = errors.Wrap(err, "error reading model")
return nil, err
}

rs.State = f.GetState()
encShare, err := utils.MarshalProtoV1ToJSON(rs)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/ocm/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1"
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"google.golang.org/genproto/protobuf/field_mask"
)

// Manager is the interface that manipulates the OCM shares.
Expand Down Expand Up @@ -53,7 +54,7 @@ type Manager interface {
GetReceivedShare(ctx context.Context, ref *ocm.ShareReference) (*ocm.ReceivedShare, error)

// UpdateReceivedShare updates the received share with share state.
UpdateReceivedShare(ctx context.Context, ref *ocm.ShareReference, f *ocm.UpdateReceivedOCMShareRequest_UpdateField) (*ocm.ReceivedShare, error)
UpdateReceivedShare(ctx context.Context, share *ocm.ReceivedShare, fieldMask *field_mask.FieldMask) (*ocm.ReceivedShare, error)
}

// ResourceIDFilter is an abstraction for creating filter by resource id.
Expand Down
22 changes: 17 additions & 5 deletions pkg/share/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/google/uuid"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"google.golang.org/genproto/protobuf/field_mask"

"github.com/cs3org/reva/pkg/share/manager/registry"
"github.com/cs3org/reva/pkg/utils"
Expand Down Expand Up @@ -448,8 +449,8 @@ func (m *mgr) getReceived(ctx context.Context, ref *collaboration.ShareReference
return nil, errtypes.NotFound(ref.String())
}

func (m *mgr) UpdateReceivedShare(ctx context.Context, ref *collaboration.ShareReference, f *collaboration.UpdateReceivedShareRequest_UpdateField) (*collaboration.ReceivedShare, error) {
rs, err := m.getReceived(ctx, ref)
func (m *mgr) UpdateReceivedShare(ctx context.Context, share *collaboration.ReceivedShare, fieldMask *field_mask.FieldMask) (*collaboration.ReceivedShare, error) {
rs, err := m.getReceived(ctx, &collaboration.ShareReference{Spec: &collaboration.ShareReference_Id{Id: share.Share.Id}})
if err != nil {
return nil, err
}
Expand All @@ -458,12 +459,23 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, ref *collaboration.ShareR
m.Lock()
defer m.Unlock()

for i := range fieldMask.Paths {
switch fieldMask.Paths[i] {
case "state":
rs.State = share.State
case "mount_point":
rs.MountPoint = share.MountPoint
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
}

if v, ok := m.model.State[user.Id.String()]; ok {
v[rs.Share.Id.String()] = f.GetState()
v[rs.Share.Id.String()] = rs.State
m.model.State[user.Id.String()] = v
} else {
a := map[string]collaboration.ShareState{
rs.Share.Id.String(): f.GetState(),
rs.Share.Id.String(): rs.State,
}
m.model.State[user.Id.String()] = a
}
Expand All @@ -472,7 +484,7 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, ref *collaboration.ShareR
err = errors.Wrap(err, "error saving model")
return nil, err
}
// TODO persist mount point

rs.State = f.GetState()
return rs, nil
}
22 changes: 17 additions & 5 deletions pkg/share/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/share"
"google.golang.org/genproto/protobuf/field_mask"

collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -309,8 +310,8 @@ func (m *manager) getReceived(ctx context.Context, ref *collaboration.ShareRefer
return nil, errtypes.NotFound(ref.String())
}

func (m *manager) UpdateReceivedShare(ctx context.Context, ref *collaboration.ShareReference, f *collaboration.UpdateReceivedShareRequest_UpdateField) (*collaboration.ReceivedShare, error) {
rs, err := m.getReceived(ctx, ref)
func (m *manager) UpdateReceivedShare(ctx context.Context, share *collaboration.ReceivedShare, fieldMask *field_mask.FieldMask) (*collaboration.ReceivedShare, error) {
rs, err := m.getReceived(ctx, &collaboration.ShareReference{Spec: &collaboration.ShareReference_Id{Id: share.Share.Id}})
if err != nil {
return nil, err
}
Expand All @@ -319,16 +320,27 @@ func (m *manager) UpdateReceivedShare(ctx context.Context, ref *collaboration.Sh
m.lock.Lock()
defer m.lock.Unlock()

for i := range fieldMask.Paths {
switch fieldMask.Paths[i] {
case "state":
rs.State = share.State
case "mount_point":
rs.MountPoint = share.MountPoint
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
}

if v, ok := m.shareState[user.Id.String()]; ok {
v[rs.Share.Id] = f.GetState()
v[rs.Share.Id] = rs.State
m.shareState[user.Id.String()] = v
} else {
a := map[*collaboration.ShareId]collaboration.ShareState{
rs.Share.Id: f.GetState(),
rs.Share.Id: rs.State,
}
m.shareState[user.Id.String()] = a
}
// TODO persist mount point

rs.State = f.GetState()
return rs, nil
}
Loading

0 comments on commit c0acb58

Please sign in to comment.