Skip to content

Commit

Permalink
Merge pull request #9980 from dragonchaser/fix-ocm-share-updates
Browse files Browse the repository at this point in the history
Fix ocm share updates
  • Loading branch information
2403905 authored Sep 11, 2024
2 parents 2839484 + 3a4c0f3 commit 0fa0c5e
Show file tree
Hide file tree
Showing 10 changed files with 388 additions and 53 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/allow-update-ocm-shares.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Allow update of ocm shares

We fixed a bug that prevented ocm shares to be updated or removed.

https://github.com/owncloud/ocis/pull/9980
https://github.com/owncloud/ocis/issues/9926
2 changes: 2 additions & 0 deletions changelog/unreleased/bump-reva.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Enhancement: Bump reva

Bumps reva version

https://github.com/owncloud/ocis/pull/9980
https://github.com/owncloud/ocis/pull/9981
https://github.com/owncloud/ocis/pull/9981
https://github.com/owncloud/ocis/pull/9920
https://github.com/owncloud/ocis/pull/9879
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/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-oidc/v3 v3.11.0
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb
github.com/cs3org/reva/v2 v2.23.1-0.20240905133054-2de6ff31c4e3
github.com/cs3org/reva/v2 v2.24.1-0.20240911132317-de8cea1f9e72
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
github.com/egirna/icap-client v0.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c=
github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME=
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb h1:KmYZDReplv/yfwc1LNYpDcVhVujC3Pasv6WjXx1haSU=
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
github.com/cs3org/reva/v2 v2.23.1-0.20240905133054-2de6ff31c4e3 h1:L1fD7ShX6W17e5YMgWpcmCq2KVHQy48gFrnc261iohQ=
github.com/cs3org/reva/v2 v2.23.1-0.20240905133054-2de6ff31c4e3/go.mod h1:p7CHBXcg6sSqB+0JMNDfC1S7TSh9FghXkw1kTV3KcJI=
github.com/cs3org/reva/v2 v2.24.1-0.20240911132317-de8cea1f9e72 h1:J1CCIbBOKVGEqEng3OwZzeX5jVLb8iTzM251D2C8oyo=
github.com/cs3org/reva/v2 v2.24.1-0.20240911132317-de8cea1f9e72/go.mod h1:p7CHBXcg6sSqB+0JMNDfC1S7TSh9FghXkw1kTV3KcJI=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
Expand Down
46 changes: 37 additions & 9 deletions services/graph/pkg/service/v0/api_driveitem_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import (
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
libregraph "github.com/owncloud/libre-graph-api-go"

revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/publicshare"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/v2/pkg/share"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
libregraph "github.com/owncloud/libre-graph-api-go"

"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
l10n_pkg "github.com/owncloud/ocis/v2/services/graph/pkg/l10n"
Expand Down Expand Up @@ -71,6 +72,7 @@ const (
Public
User
Space
OCM
)

// NewDriveItemPermissionsService creates a new DriveItemPermissionsService
Expand Down Expand Up @@ -463,6 +465,13 @@ func (s DriveItemPermissionsService) DeletePermission(ctx context.Context, itemI
}
}

if sharedResourceID == nil && s.config.IncludeOCMSharees {
sharedResourceID, err = s.getOCMPermissionResourceID(ctx, permissionID)
if err == nil {
permissionType = OCM
}
}

switch {
case err != nil:
return err
Expand All @@ -486,10 +495,12 @@ func (s DriveItemPermissionsService) DeletePermission(ctx context.Context, itemI
return s.removePublicShare(ctx, permissionID)
case Space:
return s.removeSpacePermission(ctx, permissionID, sharedResourceID)
case OCM:
return s.removeOCMPermission(ctx, permissionID)
default:
// This should never be reached
return errorcode.New(errorcode.GeneralException, "failed to delete permission")
}

// This should never be reached
return errorcode.New(errorcode.GeneralException, "failed to delete permission")
}

// DeleteSpaceRootPermission deletes a permission on the root item of a project space
Expand All @@ -515,6 +526,13 @@ func (s DriveItemPermissionsService) DeleteSpaceRootPermission(ctx context.Conte
// UpdatePermission updates a permission on a drive item
func (s DriveItemPermissionsService) UpdatePermission(ctx context.Context, itemID *storageprovider.ResourceId, permissionID string, newPermission libregraph.Permission) (libregraph.Permission, error) {
oldPermission, sharedResourceID, err := s.getPermissionByID(ctx, permissionID, itemID)

// try to get the permission from ocm if the permission was not found first place
if err != nil && s.config.IncludeOCMSharees {
oldPermission, sharedResourceID, err = s.getOCMPermissionByID(ctx, permissionID, itemID)
}

// if we still can't find the permission, return an error
if err != nil {
return libregraph.Permission{}, err
}
Expand All @@ -537,10 +555,20 @@ func (s DriveItemPermissionsService) UpdatePermission(ctx context.Context, itemI

// This is a user share
updatedPermission, err := s.updateUserShare(ctx, permissionID, sharedResourceID, &newPermission)
if err != nil {
return libregraph.Permission{}, err
if err == nil && updatedPermission != nil {
return *updatedPermission, nil
}
return *updatedPermission, nil

// This is an ocm share
if s.config.IncludeOCMSharees {
updatePermission, err := s.updateOCMPermission(ctx, permissionID, itemID, &newPermission)
if err == nil {
return *updatePermission, nil
}
}

return libregraph.Permission{}, err

}

// UpdateSpaceRootPermission updates a permission on the root item of a project space
Expand Down
Loading

0 comments on commit 0fa0c5e

Please sign in to comment.