mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-26 10:07:34 -05:00
feat(graph): add GET endpoints for single sharing permissions
Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
83615f23e5
commit
64a1ac8339
7 files changed
+581
No files matched your search
@@ -310,6 +310,150 @@ func (_c *DriveItemPermissionsProvider_DeleteSpaceRootPermission_Call) RunAndRet
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetPermission provides a mock function for the type DriveItemPermissionsProvider
|
||||
func (_mock *DriveItemPermissionsProvider) GetPermission(ctx context.Context, itemID *providerv1beta1.ResourceId, permissionID string) (libregraph.Permission, error) {
|
||||
ret := _mock.Called(ctx, itemID, permissionID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetPermission")
|
||||
}
|
||||
|
||||
var r0 libregraph.Permission
|
||||
var r1 error
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, *providerv1beta1.ResourceId, string) (libregraph.Permission, error)); ok {
|
||||
return returnFunc(ctx, itemID, permissionID)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, *providerv1beta1.ResourceId, string) libregraph.Permission); ok {
|
||||
r0 = returnFunc(ctx, itemID, permissionID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(libregraph.Permission)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(1).(func(context.Context, *providerv1beta1.ResourceId, string) error); ok {
|
||||
r1 = returnFunc(ctx, itemID, permissionID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// DriveItemPermissionsProvider_GetPermission_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPermission'
|
||||
type DriveItemPermissionsProvider_GetPermission_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetPermission is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - itemID *providerv1beta1.ResourceId
|
||||
// - permissionID string
|
||||
func (_e *DriveItemPermissionsProvider_Expecter) GetPermission(ctx any, itemID any, permissionID any) *DriveItemPermissionsProvider_GetPermission_Call {
|
||||
return &DriveItemPermissionsProvider_GetPermission_Call{Call: _e.mock.On("GetPermission", ctx, itemID, permissionID)}
|
||||
}
|
||||
|
||||
func (_c *DriveItemPermissionsProvider_GetPermission_Call) Run(run func(ctx context.Context, itemID *providerv1beta1.ResourceId, permissionID string)) *DriveItemPermissionsProvider_GetPermission_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 context.Context
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(context.Context)
|
||||
}
|
||||
var arg1 *providerv1beta1.ResourceId
|
||||
if args[1] != nil {
|
||||
arg1 = args[1].(*providerv1beta1.ResourceId)
|
||||
}
|
||||
var arg2 string
|
||||
if args[2] != nil {
|
||||
arg2 = args[2].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *DriveItemPermissionsProvider_GetPermission_Call) Return(permission libregraph.Permission, err error) *DriveItemPermissionsProvider_GetPermission_Call {
|
||||
_c.Call.Return(permission, err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *DriveItemPermissionsProvider_GetPermission_Call) RunAndReturn(run func(ctx context.Context, itemID *providerv1beta1.ResourceId, permissionID string) (libregraph.Permission, error)) *DriveItemPermissionsProvider_GetPermission_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetSpaceRootPermission provides a mock function for the type DriveItemPermissionsProvider
|
||||
func (_mock *DriveItemPermissionsProvider) GetSpaceRootPermission(ctx context.Context, driveID *providerv1beta1.ResourceId, permissionID string) (libregraph.Permission, error) {
|
||||
ret := _mock.Called(ctx, driveID, permissionID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetSpaceRootPermission")
|
||||
}
|
||||
|
||||
var r0 libregraph.Permission
|
||||
var r1 error
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, *providerv1beta1.ResourceId, string) (libregraph.Permission, error)); ok {
|
||||
return returnFunc(ctx, driveID, permissionID)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, *providerv1beta1.ResourceId, string) libregraph.Permission); ok {
|
||||
r0 = returnFunc(ctx, driveID, permissionID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(libregraph.Permission)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(1).(func(context.Context, *providerv1beta1.ResourceId, string) error); ok {
|
||||
r1 = returnFunc(ctx, driveID, permissionID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// DriveItemPermissionsProvider_GetSpaceRootPermission_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSpaceRootPermission'
|
||||
type DriveItemPermissionsProvider_GetSpaceRootPermission_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetSpaceRootPermission is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - driveID *providerv1beta1.ResourceId
|
||||
// - permissionID string
|
||||
func (_e *DriveItemPermissionsProvider_Expecter) GetSpaceRootPermission(ctx any, driveID any, permissionID any) *DriveItemPermissionsProvider_GetSpaceRootPermission_Call {
|
||||
return &DriveItemPermissionsProvider_GetSpaceRootPermission_Call{Call: _e.mock.On("GetSpaceRootPermission", ctx, driveID, permissionID)}
|
||||
}
|
||||
|
||||
func (_c *DriveItemPermissionsProvider_GetSpaceRootPermission_Call) Run(run func(ctx context.Context, driveID *providerv1beta1.ResourceId, permissionID string)) *DriveItemPermissionsProvider_GetSpaceRootPermission_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 context.Context
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(context.Context)
|
||||
}
|
||||
var arg1 *providerv1beta1.ResourceId
|
||||
if args[1] != nil {
|
||||
arg1 = args[1].(*providerv1beta1.ResourceId)
|
||||
}
|
||||
var arg2 string
|
||||
if args[2] != nil {
|
||||
arg2 = args[2].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *DriveItemPermissionsProvider_GetSpaceRootPermission_Call) Return(permission libregraph.Permission, err error) *DriveItemPermissionsProvider_GetSpaceRootPermission_Call {
|
||||
_c.Call.Return(permission, err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *DriveItemPermissionsProvider_GetSpaceRootPermission_Call) RunAndReturn(run func(ctx context.Context, driveID *providerv1beta1.ResourceId, permissionID string) (libregraph.Permission, error)) *DriveItemPermissionsProvider_GetSpaceRootPermission_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Invite provides a mock function for the type DriveItemPermissionsProvider
|
||||
func (_mock *DriveItemPermissionsProvider) Invite(ctx context.Context, resourceId *providerv1beta1.ResourceId, invite libregraph.DriveItemInvite) (libregraph.Permission, error) {
|
||||
ret := _mock.Called(ctx, resourceId, invite)
|
||||
|
||||
@@ -62,6 +62,8 @@ type DriveItemPermissionsProvider interface {
|
||||
CreateSpaceRootLink(ctx context.Context, driveID *storageprovider.ResourceId, createLink libregraph.DriveItemCreateLink) (libregraph.Permission, error)
|
||||
SetPublicLinkPassword(ctx context.Context, driveItemID *storageprovider.ResourceId, permissionID string, password string) (libregraph.Permission, error)
|
||||
SetPublicLinkPasswordOnSpaceRoot(ctx context.Context, driveID *storageprovider.ResourceId, permissionID string, password string) (libregraph.Permission, error)
|
||||
GetPermission(ctx context.Context, itemID *storageprovider.ResourceId, permissionID string) (libregraph.Permission, error)
|
||||
GetSpaceRootPermission(ctx context.Context, driveID *storageprovider.ResourceId, permissionID string) (libregraph.Permission, error)
|
||||
}
|
||||
|
||||
// DriveItemPermissionsService contains the production business logic for everything that relates to permissions on drive items.
|
||||
@@ -687,6 +689,42 @@ func (s DriveItemPermissionsService) UpdateSpaceRootPermission(ctx context.Conte
|
||||
return s.UpdatePermission(ctx, rootResourceID, permissionID, newPermission)
|
||||
}
|
||||
|
||||
// GetPermission returns a single permission of a drive item.
|
||||
// It reuses ListPermissions, so only permissions visible in the listing of the item can be retrieved.
|
||||
func (s DriveItemPermissionsService) GetPermission(ctx context.Context, itemID *storageprovider.ResourceId, permissionID string) (libregraph.Permission, error) {
|
||||
collection, err := s.ListPermissions(ctx, itemID, ListPermissionsQueryOptions{})
|
||||
if err != nil {
|
||||
return libregraph.Permission{}, err
|
||||
}
|
||||
|
||||
for _, permission := range collection.Value {
|
||||
if permission.GetId() == permissionID {
|
||||
return permission, nil
|
||||
}
|
||||
}
|
||||
|
||||
return libregraph.Permission{}, errorcode.New(errorcode.ItemNotFound, "permission not found")
|
||||
}
|
||||
|
||||
// GetSpaceRootPermission returns a single permission on the root item of a project space
|
||||
func (s DriveItemPermissionsService) GetSpaceRootPermission(ctx context.Context, driveID *storageprovider.ResourceId, permissionID string) (libregraph.Permission, error) {
|
||||
gatewayClient, err := s.gatewaySelector.Next()
|
||||
if err != nil {
|
||||
return libregraph.Permission{}, err
|
||||
}
|
||||
|
||||
space, err := utils.GetSpace(ctx, storagespace.FormatResourceID(driveID), gatewayClient)
|
||||
if err != nil {
|
||||
return libregraph.Permission{}, errorcode.FromUtilsStatusCodeError(err)
|
||||
}
|
||||
|
||||
if space.GetSpaceType() != _spaceTypeProject {
|
||||
return libregraph.Permission{}, errorcode.New(errorcode.InvalidRequest, "unsupported space type")
|
||||
}
|
||||
|
||||
return s.GetPermission(ctx, space.GetRoot(), permissionID)
|
||||
}
|
||||
|
||||
// DriveItemPermissionsApi is the api that registers the http endpoints which expose needed operation to the graph api.
|
||||
// the business logic is delegated to the permissions service and further down to the cs3 client.
|
||||
type DriveItemPermissionsApi struct {
|
||||
@@ -1023,3 +1061,53 @@ func (api DriveItemPermissionsApi) UpdateSpaceRootPermission(w http.ResponseWrit
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, &updatedPermission)
|
||||
}
|
||||
|
||||
// GetPermission handles GetPermission requests
|
||||
func (api DriveItemPermissionsApi) GetPermission(w http.ResponseWriter, r *http.Request) {
|
||||
_, itemID, err := GetDriveAndItemIDParam(r, &api.logger)
|
||||
if err != nil {
|
||||
api.logger.Debug().Err(err).Msg(invalidIdMsg)
|
||||
errorcode.RenderError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
permissionID, err := url.PathUnescape(chi.URLParam(r, "permissionID"))
|
||||
if err != nil || permissionID == "" {
|
||||
api.logger.Debug().Err(err).Msg("could not parse permissionID")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "invalid permissionID")
|
||||
return
|
||||
}
|
||||
|
||||
permission, err := api.driveItemPermissionsService.GetPermission(r.Context(), itemID, permissionID)
|
||||
if err != nil {
|
||||
errorcode.RenderError(w, r, err)
|
||||
return
|
||||
}
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, &permission)
|
||||
}
|
||||
|
||||
// GetSpaceRootPermission handles GetPermission requests on a space root
|
||||
func (api DriveItemPermissionsApi) GetSpaceRootPermission(w http.ResponseWriter, r *http.Request) {
|
||||
driveID, err := parseIDParam(r, "driveID")
|
||||
if err != nil {
|
||||
api.logger.Debug().Err(err).Msg(parseDriveIDErrMsg)
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusUnprocessableEntity, parseDriveIDErrMsg)
|
||||
return
|
||||
}
|
||||
|
||||
permissionID, err := url.PathUnescape(chi.URLParam(r, "permissionID"))
|
||||
if err != nil || permissionID == "" {
|
||||
api.logger.Debug().Err(err).Msg("could not parse permissionID")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "invalid permissionID")
|
||||
return
|
||||
}
|
||||
|
||||
permission, err := api.driveItemPermissionsService.GetSpaceRootPermission(r.Context(), &driveID, permissionID)
|
||||
if err != nil {
|
||||
errorcode.RenderError(w, r, err)
|
||||
return
|
||||
}
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, &permission)
|
||||
}
|
||||
@@ -22,12 +22,15 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
libregraph "github.com/opencloud-eu/libre-graph-api-go"
|
||||
"github.com/opencloud-eu/opencloud/services/graph/pkg/config"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/tidwall/gjson"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
roleconversions "github.com/opencloud-eu/reva/v2/pkg/conversions"
|
||||
revactx "github.com/opencloud-eu/reva/v2/pkg/ctx"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/status"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/storagespace"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/utils"
|
||||
cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks"
|
||||
@@ -39,6 +42,7 @@ import (
|
||||
"github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode"
|
||||
identitycache "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/cache"
|
||||
"github.com/opencloud-eu/opencloud/services/graph/pkg/linktype"
|
||||
"github.com/opencloud-eu/opencloud/services/graph/pkg/metrics"
|
||||
svc "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0"
|
||||
"github.com/opencloud-eu/opencloud/services/graph/pkg/unifiedrole"
|
||||
)
|
||||
@@ -746,6 +750,73 @@ var _ = Describe("DriveItemPermissionsService", func() {
|
||||
})
|
||||
|
||||
})
|
||||
Describe("GetPermission", func() {
|
||||
viewLink := func(id string) *link.PublicShare {
|
||||
return &link.PublicShare{
|
||||
Id: &link.PublicShareId{OpaqueId: id},
|
||||
Token: id,
|
||||
ResourceId: driveItemId,
|
||||
Permissions: &link.PublicSharePermissions{Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions()},
|
||||
}
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
statResponse.Info = &provider.ResourceInfo{
|
||||
Id: driveItemId,
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
PermissionSet: roleconversions.NewEditorRole().CS3ResourcePermissions(),
|
||||
}
|
||||
})
|
||||
|
||||
It("returns not found for a permission that is not listed for the item", func() {
|
||||
// shares are only listed for the requested item; permissions of other resources
|
||||
// must not be resolved by ID (the strict gateway mock fails on GetShare/GetPublicShare)
|
||||
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
|
||||
gatewayClient.On("ListShares", mock.Anything, mock.MatchedBy(func(req *collaboration.ListSharesRequest) bool {
|
||||
return slices.ContainsFunc(req.GetFilters(), func(f *collaboration.Filter) bool {
|
||||
return utils.ResourceIDEqual(f.GetResourceId(), driveItemId)
|
||||
})
|
||||
})).Return(&collaboration.ListSharesResponse{Status: status.NewOK(ctx)}, nil)
|
||||
listPublicSharesResponse.Share = []*link.PublicShare{viewLink("aaaaaaaaaaaaaaa")}
|
||||
gatewayClient.On("ListPublicShares", mock.Anything, mock.MatchedBy(func(req *link.ListPublicSharesRequest) bool {
|
||||
return slices.ContainsFunc(req.GetFilters(), func(f *link.ListPublicSharesRequest_Filter) bool {
|
||||
return utils.ResourceIDEqual(f.GetResourceId(), driveItemId)
|
||||
})
|
||||
})).Return(listPublicSharesResponse, nil)
|
||||
|
||||
_, err := driveItemPermissionsService.GetPermission(ctx, driveItemId, "ccccccccccccccc")
|
||||
Expect(errorcode.IsErrorCode(err, errorcode.ItemNotFound)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("propagates stat errors without listing permissions", func() {
|
||||
statResponse.Status = status.NewPermissionDenied(ctx, nil, "denied")
|
||||
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
|
||||
|
||||
_, err := driveItemPermissionsService.GetPermission(ctx, driveItemId, "aaaaaaaaaaaaaaa")
|
||||
Expect(errorcode.IsErrorCode(err, errorcode.AccessDenied)).To(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("GetSpaceRootPermission", func() {
|
||||
DescribeTable("rejects space types other than project",
|
||||
func(spaceType string) {
|
||||
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
StorageSpaces: []*provider.StorageSpace{{
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "1$2"},
|
||||
SpaceType: spaceType,
|
||||
Root: &provider.ResourceId{StorageId: "1", SpaceId: "2", OpaqueId: "2"},
|
||||
}},
|
||||
}, nil)
|
||||
|
||||
_, err := driveItemPermissionsService.GetSpaceRootPermission(ctx, &provider.ResourceId{StorageId: "1", SpaceId: "2"}, "aaaaaaaaaaaaaaa")
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.InvalidRequest, "unsupported space type")))
|
||||
},
|
||||
Entry("personal", "personal"),
|
||||
Entry("virtual", "virtual"),
|
||||
)
|
||||
})
|
||||
|
||||
Describe("DeletePermission", func() {
|
||||
var (
|
||||
getShareResponse collaboration.GetShareResponse
|
||||
@@ -1494,6 +1565,175 @@ var _ = Describe("DriveItemPermissionsApi", func() {
|
||||
Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("GetPermission", func() {
|
||||
get := func() *httptest.ResponseRecorder {
|
||||
responseRecorder := httptest.NewRecorder()
|
||||
request := httptest.NewRequest(http.MethodGet, "/", nil).
|
||||
WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rCTX))
|
||||
httpAPI.GetPermission(responseRecorder, request)
|
||||
return responseRecorder
|
||||
}
|
||||
|
||||
It("passes the item and permission ID to the provider and renders the permission", func() {
|
||||
rCTX.URLParams.Add("itemID", "1$2!3")
|
||||
rCTX.URLParams.Add("permissionID", "perm%2Fid")
|
||||
mockProvider.On("GetPermission", mock.Anything, mock.Anything, mock.Anything).
|
||||
Return(func(ctx context.Context, itemID *provider.ResourceId, permissionID string) (libregraph.Permission, error) {
|
||||
Expect(storagespace.FormatResourceID(itemID)).To(Equal("1$2!3"))
|
||||
Expect(permissionID).To(Equal("perm/id"))
|
||||
return libregraph.Permission{Id: libregraph.PtrString("perm/id")}, nil
|
||||
}).Once()
|
||||
|
||||
rr := get()
|
||||
Expect(rr.Code).To(Equal(http.StatusOK))
|
||||
Expect(gjson.Get(rr.Body.String(), "id").String()).To(Equal("perm/id"))
|
||||
})
|
||||
|
||||
It("rejects an itemID that does not belong to the drive", func() {
|
||||
rCTX.URLParams.Add("itemID", "3$4!5")
|
||||
rCTX.URLParams.Add("permissionID", "permid")
|
||||
Expect(get().Code).To(Equal(http.StatusNotFound))
|
||||
})
|
||||
|
||||
It("rejects an empty permissionID", func() {
|
||||
rCTX.URLParams.Add("itemID", "1$2!3")
|
||||
Expect(get().Code).To(Equal(http.StatusBadRequest))
|
||||
})
|
||||
|
||||
It("renders a not found error of the provider", func() {
|
||||
rCTX.URLParams.Add("itemID", "1$2!3")
|
||||
rCTX.URLParams.Add("permissionID", "permid")
|
||||
mockProvider.On("GetPermission", mock.Anything, mock.Anything, mock.Anything).
|
||||
Return(libregraph.Permission{}, errorcode.New(errorcode.ItemNotFound, "permission not found")).Once()
|
||||
|
||||
Expect(get().Code).To(Equal(http.StatusNotFound))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("GetSpaceRootPermission", func() {
|
||||
It("rejects an invalid driveID", func() {
|
||||
rCTX = chi.NewRouteContext()
|
||||
rCTX.URLParams.Add("permissionID", "permid")
|
||||
responseRecorder := httptest.NewRecorder()
|
||||
request := httptest.NewRequest(http.MethodGet, "/", nil).
|
||||
WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rCTX))
|
||||
httpAPI.GetSpaceRootPermission(responseRecorder, request)
|
||||
|
||||
Expect(responseRecorder.Code).To(Equal(http.StatusUnprocessableEntity))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("DriveItemPermissions routes", func() {
|
||||
var (
|
||||
graphService svc.Service
|
||||
gatewayClient *cs3mocks.GatewayAPIClient
|
||||
ctx context.Context
|
||||
rr *httptest.ResponseRecorder
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = revactx.ContextSetUser(context.Background(), &userpb.User{Id: &userpb.UserId{OpaqueId: "user"}})
|
||||
rr = httptest.NewRecorder()
|
||||
|
||||
cfg := defaults.FullDefaultConfig()
|
||||
cfg.Identity.LDAP.CACert = ""
|
||||
cfg.TokenManager.JWTSecret = "loremipsum"
|
||||
cfg.Commons = &shared.Commons{}
|
||||
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
|
||||
|
||||
pool.RemoveSelector("GatewaySelector" + "eu.opencloud.api.gateway")
|
||||
gatewayClient = &cs3mocks.GatewayAPIClient{}
|
||||
gatewaySelector := pool.GetSelector[gateway.GatewayAPIClient](
|
||||
"GatewaySelector",
|
||||
"eu.opencloud.api.gateway",
|
||||
func(cc grpc.ClientConnInterface) gateway.GatewayAPIClient {
|
||||
return gatewayClient
|
||||
},
|
||||
)
|
||||
|
||||
logger := log.NewLogger()
|
||||
m, _ := metrics.New(prometheus.NewRegistry(), &logger, func([]string) (string, string) { return "", "" })
|
||||
|
||||
var err error
|
||||
graphService, err = svc.NewService(
|
||||
svc.Config(cfg),
|
||||
svc.Metrics(m),
|
||||
svc.WithGatewaySelector(gatewaySelector),
|
||||
svc.EventsPublisher(&mocks.Publisher{}),
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("GET .../items/{itemID}/permissions/{permissionID} returns the matching permission", func() {
|
||||
itemID := &provider.ResourceId{StorageId: "1", SpaceId: "2", OpaqueId: "3"}
|
||||
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Info: &provider.ResourceInfo{
|
||||
Id: itemID,
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
PermissionSet: roleconversions.NewEditorRole().CS3ResourcePermissions(),
|
||||
},
|
||||
}, nil)
|
||||
gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(&collaboration.ListSharesResponse{Status: status.NewOK(ctx)}, nil)
|
||||
viewLink := func(id string) *link.PublicShare {
|
||||
return &link.PublicShare{
|
||||
Id: &link.PublicShareId{OpaqueId: id},
|
||||
Token: id,
|
||||
ResourceId: itemID,
|
||||
Permissions: &link.PublicSharePermissions{Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions()},
|
||||
Ctime: &types.Timestamp{Seconds: uint64(time.Now().Unix())},
|
||||
}
|
||||
}
|
||||
gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(&link.ListPublicSharesResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Share: []*link.PublicShare{viewLink("aaaaaaaaaaaaaaa"), viewLink("bbbbbbbbbbbbbbb")},
|
||||
}, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1beta1/drives/1$2/items/1$2!3/permissions/bbbbbbbbbbbbbbb", nil).WithContext(ctx)
|
||||
graphService.ServeHTTP(rr, r)
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusOK))
|
||||
Expect(gjson.Get(rr.Body.String(), "id").String()).To(Equal("bbbbbbbbbbbbbbb"))
|
||||
Expect(gjson.Get(rr.Body.String(), "link.type").String()).To(Equal("view"))
|
||||
})
|
||||
|
||||
It("GET .../root/permissions/{permissionID} returns the matching permission of a project space", func() {
|
||||
rootID := &provider.ResourceId{StorageId: "1", SpaceId: "2", OpaqueId: "2"}
|
||||
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
StorageSpaces: []*provider.StorageSpace{{
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "1$2"},
|
||||
SpaceType: "project",
|
||||
Root: rootID,
|
||||
}},
|
||||
}, nil)
|
||||
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Info: &provider.ResourceInfo{
|
||||
Id: rootID,
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
PermissionSet: roleconversions.NewManagerRole().CS3ResourcePermissions(),
|
||||
},
|
||||
}, nil)
|
||||
gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(&collaboration.ListSharesResponse{Status: status.NewOK(ctx)}, nil)
|
||||
gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(&link.ListPublicSharesResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Share: []*link.PublicShare{{
|
||||
Id: &link.PublicShareId{OpaqueId: "aaaaaaaaaaaaaaa"},
|
||||
Token: "aaaaaaaaaaaaaaa",
|
||||
ResourceId: rootID,
|
||||
Permissions: &link.PublicSharePermissions{Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions()},
|
||||
}},
|
||||
}, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1beta1/drives/1$2/root/permissions/aaaaaaaaaaaaaaa", nil).WithContext(ctx)
|
||||
graphService.ServeHTTP(rr, r)
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusOK))
|
||||
Expect(gjson.Get(rr.Body.String(), "id").String()).To(Equal("aaaaaaaaaaaaaaa"))
|
||||
})
|
||||
})
|
||||
|
||||
func guestGrantee(mail string) *provider.Grantee {
|
||||
|
||||
@@ -264,6 +264,7 @@ func NewService(opts ...Option) (Graph, error) { //nolint:maintidx
|
||||
r.Route("/permissions", func(r chi.Router) {
|
||||
r.Get("/", driveItemPermissionsApi.ListSpaceRootPermissions)
|
||||
r.Route("/{permissionID}", func(r chi.Router) {
|
||||
r.Get("/", driveItemPermissionsApi.GetSpaceRootPermission)
|
||||
r.Delete("/", driveItemPermissionsApi.DeleteSpaceRootPermission)
|
||||
r.Patch("/", driveItemPermissionsApi.UpdateSpaceRootPermission)
|
||||
r.Post("/setPassword", driveItemPermissionsApi.SetSpaceRootLinkPassword)
|
||||
@@ -279,6 +280,7 @@ func NewService(opts ...Option) (Graph, error) { //nolint:maintidx
|
||||
r.Route("/permissions", func(r chi.Router) {
|
||||
r.Get("/", driveItemPermissionsApi.ListPermissions)
|
||||
r.Route("/{permissionID}", func(r chi.Router) {
|
||||
r.Get("/", driveItemPermissionsApi.GetPermission)
|
||||
r.Delete("/", driveItemPermissionsApi.DeletePermission)
|
||||
r.Patch("/", driveItemPermissionsApi.UpdatePermission)
|
||||
r.Post("/setPassword", driveItemPermissionsApi.SetLinkPassword)
|
||||
|
||||
@@ -2183,6 +2183,35 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $spaceId
|
||||
* @param string $permissionId
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getDrivePermission(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $user,
|
||||
string $password,
|
||||
string $spaceId,
|
||||
string $permissionId
|
||||
): ResponseInterface {
|
||||
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/root/permissions/$permissionId");
|
||||
return HttpRequestHelper::get(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password,
|
||||
self::getRequestHeaders()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
|
||||
@@ -1724,6 +1724,27 @@ class SharingNgContext implements Context {
|
||||
$this->featureContext->setResponse($this->getDrivePermissionsList($user, $space));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $space
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
#[When('user :user gets the last link permission of space :space using root endpoint of the Graph API')]
|
||||
public function userGetsTheLastLinkPermissionOfSpaceUsingRootEndpointOfTheGraphApi(string $user, string $space): void {
|
||||
$this->featureContext->setResponse(
|
||||
GraphHelper::getDrivePermission(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
($this->spacesContext->getSpaceByName($user, $space))["id"],
|
||||
$this->featureContext->shareNgGetLastCreatedLinkShareID()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $user
|
||||
|
||||
@@ -2926,3 +2926,60 @@ Feature: List a sharing permissions
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
Scenario: user gets a single link permission of a project space using root endpoint
|
||||
Given using spaces DAV path
|
||||
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
|
||||
And user "Alice" has created a space "new-space" with the default quota using the Graph API
|
||||
And user "Alice" has created the following space link share:
|
||||
| space | new-space |
|
||||
| permissionsRole | view |
|
||||
| password | %public% |
|
||||
When user "Alice" gets the last link permission of space "new-space" using root endpoint of the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the JSON data of the response should match
|
||||
"""
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["createdDateTime", "hasPassword", "id", "link"],
|
||||
"properties": {
|
||||
"createdDateTime": {
|
||||
"format": "date-time"
|
||||
},
|
||||
"hasPassword": {
|
||||
"const": true
|
||||
},
|
||||
"id": {
|
||||
"pattern": "^[a-zA-Z]{15}$"
|
||||
},
|
||||
"link": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"@libre.graph.displayName",
|
||||
"@libre.graph.quickLink",
|
||||
"preventsDownload",
|
||||
"type",
|
||||
"webUrl"
|
||||
],
|
||||
"properties": {
|
||||
"@libre.graph.displayName": {
|
||||
"const": ""
|
||||
},
|
||||
"@libre.graph.quickLink": {
|
||||
"const": false
|
||||
},
|
||||
"preventsDownload": {
|
||||
"const": false
|
||||
},
|
||||
"type": {
|
||||
"const": "view"
|
||||
},
|
||||
"webUrl": {
|
||||
"pattern": "^%base_url%/s/[a-zA-Z]{15}$"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
Reference in new issue
Block a user