Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and delete OCM shares #3937

Merged
merged 32 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
549d9b8
implemented DeleteRemoteUser
gmgigi96 Jun 5, 2023
5ba8527
update state of received ocm share
gmgigi96 Jun 5, 2023
2b11b85
fix cmd
gmgigi96 Jun 5, 2023
2f5683d
removed old comment
gmgigi96 Jun 5, 2023
3d5de53
add endpoint to delete accepted user
gmgigi96 Jun 5, 2023
3cab2c0
remove federated share
gmgigi96 Jun 5, 2023
2378b49
fix linter
gmgigi96 Jun 5, 2023
ea16989
accept/reject ocm recevied shares
gmgigi96 Jun 6, 2023
bdd2bb3
update access methods in sql driver
gmgigi96 Jun 6, 2023
9f09f82
inject time for unit tests
gmgigi96 Jun 6, 2023
0e366bb
add unit tests for UpdateShare
gmgigi96 Jun 6, 2023
adb079a
removed tests for DeleteShare
gmgigi96 Jun 6, 2023
0d36cbb
update permissions of federated shares from ocs
gmgigi96 Jun 6, 2023
1d1378a
update go-cs3apis
gmgigi96 Jun 6, 2023
c15b25c
fix linter
gmgigi96 Jun 6, 2023
f481eb2
add command in cli to remove an accepted user
gmgigi96 Jun 7, 2023
871b128
update permissions of ocm share from cli
gmgigi96 Jun 7, 2023
c39f81c
optimized query build when updating access methods
gmgigi96 Jun 7, 2023
6f45674
fix update ocm share in ocs
gmgigi96 Jun 7, 2023
a1c4c68
fix update received ocm share
gmgigi96 Jun 7, 2023
8d60a53
return share id when accepting/reject ocm share
gmgigi96 Jun 7, 2023
be7d176
filter ocm shares by status
gmgigi96 Jun 7, 2023
41abc23
fix update received share
gmgigi96 Jun 7, 2023
a9d5466
expose state of ocm share
gmgigi96 Jun 7, 2023
41f58a0
set correct user type when deleting user
gmgigi96 Jun 8, 2023
4de1c0b
add share info when creating ocm share
gmgigi96 Jun 8, 2023
786f7cc
disabled nextcloud unit test
gmgigi96 Jun 8, 2023
f260f72
add changelog
gmgigi96 Jun 8, 2023
d86739b
trigger pipeline
gmgigi96 Jun 8, 2023
de59686
add header
gmgigi96 Jun 8, 2023
b9662cf
fix rebase
gmgigi96 Jun 8, 2023
6b44aa3
fix linter
gmgigi96 Jun 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog/unreleased/update_remove_ocm_share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Enhancement: Manage OCM shares

Implements the following item regarding OCM:
- update of OCM shares in both grpc and ocs layer,
allowing an user to update permissions and expiration of the share
- deletion of OCM shares in both grpc and ocs layer
- accept/reject of received OCM shares
- remove accepted remote users

https://github.com/cs3org/reva/pull/3937
1 change: 1 addition & 0 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
moveCommand(),
mkdirCommand(),
ocmFindAcceptedUsersCommand(),
ocmRemoveAcceptedUser(),
ocmInviteGenerateCommand(),
ocmInviteForwardCommand(),
ocmShareCreateCommand(),
Expand Down
77 changes: 77 additions & 0 deletions cmd/reva/ocm-remove-accepted-user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2018-2023 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"errors"
"fmt"
"io"

userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
invitepb "github.com/cs3org/go-cs3apis/cs3/ocm/invite/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
)

func ocmRemoveAcceptedUser() *command {
cmd := newCommand("ocm-remove-accepted-user")
cmd.Description = func() string { return "remove a remote user from the personal user list" }
cmd.Usage = func() string { return "Usage: ocm-remove-accepted-user [-flags]" }

user := cmd.String("user", "", "the user id")
idp := cmd.String("idp", "", "the idp of the user")

cmd.ResetFlags = func() {
*user, *idp = "", ""
}

cmd.Action = func(w ...io.Writer) error {
// validate flags
if *user == "" {
return errors.New("User cannot be empty: user -user flag\n" + cmd.Usage())
}

if *idp == "" {
return errors.New("IdP cannot be empty: use -idp flag\n" + cmd.Usage())
}

ctx := getAuthContext()
client, err := getClient()
if err != nil {
return err
}

res, err := client.DeleteAcceptedUser(ctx, &invitepb.DeleteAcceptedUserRequest{
RemoteUserId: &userv1beta1.UserId{
Type: userv1beta1.UserType_USER_TYPE_FEDERATED,
Idp: *idp,
OpaqueId: *user,
},
})
if err != nil {
return err
}
if res.Status.Code != rpcv1beta1.Code_CODE_OK {
return formatError(res.Status)
}

fmt.Println("OK")
return nil
}
return cmd
}
59 changes: 42 additions & 17 deletions cmd/reva/ocm-share-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,26 @@ func ocmShareUpdateCommand() *command {
cmd := newCommand("ocm-share-update")
cmd.Description = func() string { return "update an OCM share" }
cmd.Usage = func() string { return "Usage: ocm-share-update [-flags] <share_id>" }
rol := cmd.String("rol", "viewer", "the permission for the share (viewer or editor)")

webdavRol := cmd.String("webdav-rol", "viewer", "the permission for the WebDAV access method (viewer or editor)")
webappViewMode := cmd.String("webapp-mode", "view", "the view mode for the Webapp access method (read or write)")

cmd.ResetFlags = func() {
*rol = "viewer"
*webdavRol, *webappViewMode = "viewer", "read"
}
cmd.Action = func(w ...io.Writer) error {
if cmd.NArg() < 1 {
return errors.New("Invalid arguments: " + cmd.Usage())
}

// validate flags
if *rol != viewerPermission && *rol != editorPermission {
return errors.New("Invalid rol: rol must be viewer or editor\n" + cmd.Usage())
}

id := cmd.Args()[0]

ctx := getAuthContext()
shareClient, err := getClient()
if err != nil {
return err
if *webdavRol == "" && *webappViewMode == "" {
return errors.New("use at least one of -webdav-rol or -webapp-mode flag")
}

perm, err := getOCMSharePerm(*rol)
ctx := getAuthContext()
shareClient, err := getClient()
if err != nil {
return err
}
Expand All @@ -67,13 +63,42 @@ func ocmShareUpdateCommand() *command {
},
},
},
Field: &ocm.UpdateOCMShareRequest_UpdateField{
Field: &ocm.UpdateOCMShareRequest_UpdateField_Permissions{
Permissions: &ocm.SharePermissions{
Permissions: perm,
}

if *webdavRol != "" {
perm, err := getOCMSharePerm(*webdavRol)
if err != nil {
return err
}
shareRequest.Field = append(shareRequest.Field, &ocm.UpdateOCMShareRequest_UpdateField{
Field: &ocm.UpdateOCMShareRequest_UpdateField_AccessMethods{
AccessMethods: &ocm.AccessMethod{
Term: &ocm.AccessMethod_WebdavOptions{
WebdavOptions: &ocm.WebDAVAccessMethod{
Permissions: perm,
},
},
},
},
},
})
}

if *webappViewMode != "" {
mode, err := getOCMViewMode(*webappViewMode)
if err != nil {
return err
}
shareRequest.Field = append(shareRequest.Field, &ocm.UpdateOCMShareRequest_UpdateField{
Field: &ocm.UpdateOCMShareRequest_UpdateField_AccessMethods{
AccessMethods: &ocm.AccessMethod{
Term: &ocm.AccessMethod_WebappOptions{
WebappOptions: &ocm.WebappAccessMethod{
ViewMode: mode,
},
},
},
},
})
}

shareRes, err := shareClient.UpdateOCMShare(ctx, shareRequest)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/ceph/go-ceph v0.15.0
github.com/cheggaaa/pb v1.0.29
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20230508132523-e0d062e63b3b
github.com/cs3org/go-cs3apis v0.0.0-20230606135123-b799d47a6648
github.com/dgraph-io/ristretto v0.1.1
github.com/dolthub/go-mysql-server v0.14.0
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,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-20230508132523-e0d062e63b3b h1:UCO7Rnf5bvIvRtETguV8IaTx73cImLlFWxrApCB0QsQ=
github.com/cs3org/go-cs3apis v0.0.0-20230508132523-e0d062e63b3b/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20230606135123-b799d47a6648 h1:gBz1JSC2u6o/TkUhWSdJZvacyTsVUzDouegRzvrJye4=
github.com/cs3org/go-cs3apis v0.0.0-20230606135123-b799d47a6648/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
32 changes: 32 additions & 0 deletions internal/grpc/services/gateway/ocmcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,35 @@ func (s *svc) CreateOCMCoreShare(ctx context.Context, req *ocmcore.CreateOCMCore

return res, nil
}

func (s *svc) UpdateOCMCoreShare(ctx context.Context, req *ocmcore.UpdateOCMCoreShareRequest) (*ocmcore.UpdateOCMCoreShareResponse, error) {
c, err := pool.GetOCMCoreClient(pool.Endpoint(s.c.OCMCoreEndpoint))
if err != nil {
return &ocmcore.UpdateOCMCoreShareResponse{
Status: status.NewInternal(ctx, err, "error getting ocm core client"),
}, nil
}

res, err := c.UpdateOCMCoreShare(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling UpdateOCMCoreShare")
}

return res, nil
}

func (s *svc) DeleteOCMCoreShare(ctx context.Context, req *ocmcore.DeleteOCMCoreShareRequest) (*ocmcore.DeleteOCMCoreShareResponse, error) {
c, err := pool.GetOCMCoreClient(pool.Endpoint(s.c.OCMCoreEndpoint))
if err != nil {
return &ocmcore.DeleteOCMCoreShareResponse{
Status: status.NewInternal(ctx, err, "error getting ocm core client"),
}, nil
}

res, err := c.DeleteOCMCoreShare(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling UpdateOCMCoreShare")
}

return res, nil
}
16 changes: 16 additions & 0 deletions internal/grpc/services/gateway/ocminvitemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,19 @@ func (s *svc) FindAcceptedUsers(ctx context.Context, req *invitepb.FindAcceptedU

return res, nil
}

func (s *svc) DeleteAcceptedUser(ctx context.Context, req *invitepb.DeleteAcceptedUserRequest) (*invitepb.DeleteAcceptedUserResponse, error) {
c, err := pool.GetOCMInviteManagerClient(pool.Endpoint(s.c.OCMInviteManagerEndpoint))
if err != nil {
return &invitepb.DeleteAcceptedUserResponse{
Status: status.NewInternal(ctx, err, "error getting user invite provider client"),
}, nil
}

res, err := c.DeleteAcceptedUser(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling FindAcceptedUsers")
}

return res, nil
}
8 changes: 8 additions & 0 deletions internal/grpc/services/ocmcore/ocmcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ func (s *service) CreateOCMCoreShare(ctx context.Context, req *ocmcore.CreateOCM
Created: share.Ctime,
}, nil
}

func (s *service) UpdateOCMCoreShare(ctx context.Context, req *ocmcore.UpdateOCMCoreShareRequest) (*ocmcore.UpdateOCMCoreShareResponse, error) {
return nil, errtypes.NotSupported("not implemented")
}

func (s *service) DeleteOCMCoreShare(ctx context.Context, req *ocmcore.DeleteOCMCoreShareRequest) (*ocmcore.DeleteOCMCoreShareResponse, error) {
return nil, errtypes.NotSupported("not implemented")
}
13 changes: 13 additions & 0 deletions internal/grpc/services/ocminvitemanager/ocminvitemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,16 @@ func (s *service) FindAcceptedUsers(ctx context.Context, req *invitepb.FindAccep
AcceptedUsers: acceptedUsers,
}, nil
}

func (s *service) DeleteAcceptedUser(ctx context.Context, req *invitepb.DeleteAcceptedUserRequest) (*invitepb.DeleteAcceptedUserResponse, error) {
user := ctxpkg.ContextMustGetUser(ctx)
if err := s.repo.DeleteRemoteUser(ctx, user.Id, req.RemoteUserId); err != nil {
return &invitepb.DeleteAcceptedUserResponse{
Status: status.NewInternal(ctx, err, "error deleting remote users: "+err.Error()),
}, nil
}

return &invitepb.DeleteAcceptedUserResponse{
Status: status.NewOK(ctx),
}, nil
}
9 changes: 7 additions & 2 deletions internal/grpc/services/ocmshareprovider/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,12 @@ func (s *service) ListOCMShares(ctx context.Context, req *ocm.ListOCMSharesReque

func (s *service) UpdateOCMShare(ctx context.Context, req *ocm.UpdateOCMShareRequest) (*ocm.UpdateOCMShareResponse, error) {
user := ctxpkg.ContextMustGetUser(ctx)
_, err := s.repo.UpdateShare(ctx, user, req.Ref, req.Field.GetPermissions()) // TODO(labkode): check what to update
if len(req.Field) == 0 {
return &ocm.UpdateOCMShareResponse{
Status: status.NewOK(ctx),
}, nil
}
_, err := s.repo.UpdateShare(ctx, user, req.Ref, req.Field...)
if err != nil {
if errors.Is(err, share.ErrShareNotFound) {
return &ocm.UpdateOCMShareResponse{
Expand Down Expand Up @@ -495,7 +500,7 @@ func (s *service) ListReceivedOCMShares(ctx context.Context, req *ocm.ListReceiv

func (s *service) UpdateReceivedOCMShare(ctx context.Context, req *ocm.UpdateReceivedOCMShareRequest) (*ocm.UpdateReceivedOCMShareResponse, error) {
user := ctxpkg.ContextMustGetUser(ctx)
_, err := s.repo.UpdateReceivedShare(ctx, user, req.Share, req.UpdateMask) // TODO(labkode): check what to update
_, err := s.repo.UpdateReceivedShare(ctx, user, req.Share, req.UpdateMask)
if err != nil {
if errors.Is(err, share.ErrShareNotFound) {
return &ocm.UpdateReceivedOCMShareResponse{
Expand Down
Loading