Merge branch 'origin/main' into 'next-release/main'

This commit is contained in:
oauth committed 2026-11-13 17:53:05 +00:00
commit 3e41f5e5a2
4 files changed
+87 -10

No files matched your search

@@ -23,6 +23,7 @@ import (
"github.com/go-chi/render"
libregraph "github.com/opencloud-eu/libre-graph-api-go"
revactx "github.com/opencloud-eu/reva/v2/pkg/ctx"
"github.com/opencloud-eu/reva/v2/pkg/errtypes"
"github.com/opencloud-eu/reva/v2/pkg/publicshare"
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
"github.com/opencloud-eu/reva/v2/pkg/share"
@@ -633,7 +634,12 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID
driveItems, err = s.listPublicShares(ctx, []*link.ListPublicSharesRequest_Filter{
publicshare.ResourceIDFilter(itemID),
}, driveItems)
if err != nil {
switch {
case err != nil && strings.Contains(err.Error(), errtypes.AlreadyExists("").Error()):
// the public share manager reports an already exists error when its metadata space is
// not accessible, e.g. after an upgrade. Still list the user and space permissions.
logger.Warn().Err(err).Str(_logKeyItemID, storagespace.FormatResourceID(itemID)).Msg("could not list public shares, skipping link permissions")
case err != nil:
errorEvent(&logger, err).Str(_logKeyItemID, storagespace.FormatResourceID(itemID)).Msg("could not list public shares")
return collectionOfPermissions, err
}
@@ -153,12 +153,18 @@ func (api DriveItemPermissionsApi) CreateLink(w http.ResponseWriter, r *http.Req
logger := api.logger.SubloggerWithRequestID(r.Context())
logger.Info().Msg("calling create link")
_, driveItemID, err := GetDriveAndItemIDParam(r, &logger)
driveID, driveItemID, err := GetDriveAndItemIDParam(r, &logger)
if err != nil {
errorcode.RenderError(w, r, err)
return
}
if IsShareJail(driveID) && driveID.GetSpaceId() == driveItemID.GetOpaqueId() {
logger.Debug().Interface("driveItemID", driveItemID).Msg("cannot create link on shares space root")
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "cannot create link on shares space root")
return
}
var createLink libregraph.DriveItemCreateLink
if err = StrictJSONUnmarshal(r.Body, &createLink); err != nil {
logger.Error().Err(err).Interface("body", r.Body).Msg("could not create link: invalid body schema definition")
@@ -42,6 +42,7 @@ import (
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/errtypes"
"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"
@@ -1771,6 +1772,48 @@ var _ = Describe("DriveItemPermissionsService", func() {
Expect(len(permissions.LibreGraphPermissionsRolesAllowedValues)).ToNot(BeZero())
Expect(len(permissions.Value)).To(Equal(2))
})
It("still returns the user shares when listing public shares reports an already exists error", func() {
statResponse.Info.PermissionSet = roleconversions.NewEditorRole().CS3ResourcePermissions()
listSharesResponse.Shares = []*collaboration.Share{
{
Id: &collaboration.ShareId{OpaqueId: "1"},
Permissions: &collaboration.SharePermissions{
Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions(),
},
ResourceId: &provider.ResourceId{
StorageId: "1",
SpaceId: "2",
OpaqueId: "3",
},
Grantee: &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_USER,
Id: &provider.Grantee_UserId{
UserId: &userpb.UserId{
OpaqueId: "user-id",
},
},
},
},
}
listPublicSharesResponse.Status = status.NewInternal(ctx, errtypes.AlreadyExists("user service-user does not have access to metadata space jsoncs3-public-share-manager-metadata, but it exists").Error())
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(listSharesResponse, nil)
gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil)
gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(listPublicSharesResponse, nil)
permissions, err := driveItemPermissionsService.ListPermissions(context.Background(), itemID, svc.ListPermissionsQueryOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(len(permissions.Value)).To(Equal(1))
})
It("fails when listing public shares fails for other reasons", func() {
listPublicSharesResponse.Status = status.NewInternal(ctx, "error listing public shares")
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(listSharesResponse, nil)
gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(listPublicSharesResponse, nil)
_, err := driveItemPermissionsService.ListPermissions(context.Background(), itemID, svc.ListPermissionsQueryOptions{})
Expect(err).To(HaveOccurred())
})
It("returns role denied", func() {
statResponse.Info.PermissionSet = roleconversions.NewManagerRole().CS3ResourcePermissions()
statResponse.Info.Type = provider.ResourceType_RESOURCE_TYPE_CONTAINER
@@ -3719,6 +3762,27 @@ var _ = Describe("DriveItemPermissionsApi", func() {
Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest))
})
})
Describe("CreateLink", func() {
It("rejects links on the shares space root", func() {
shareJailID := utils.ShareStorageProviderID + "$" + utils.ShareStorageSpaceID
rCTX = chi.NewRouteContext()
rCTX.URLParams.Add("driveID", shareJailID)
rCTX.URLParams.Add("itemID", shareJailID+"!"+utils.ShareStorageSpaceID)
responseRecorder := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodPost, "/", bytes.NewBufferString(`{"type":"view"}`)).
WithContext(
context.WithValue(context.Background(), chi.RouteCtxKey, rCTX),
)
httpAPI.CreateLink(responseRecorder, request)
Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest))
jsonData := gjson.Get(responseRecorder.Body.String(), "error")
Expect(jsonData.Get("message").String()).To(Equal("cannot create link on shares space root"))
})
})
Describe("ListPermissions", func() {
It("calls the ListPermissions provider with the correct arguments", func() {
rCTX.URLParams.Add("itemID", "1$2!3")
@@ -1279,10 +1279,10 @@ Feature: Create a link share for a resource
"""
Examples:
| permissions-role | drive | message |
| view | Shares | no share permission |
| edit | Shares | no share permission |
| upload | Shares | no share permission |
| createOnly | Shares | no share permission |
| view | Shares | cannot create link on shares space root |
| edit | Shares | cannot create link on shares space root |
| upload | Shares | cannot create link on shares space root |
| createOnly | Shares | cannot create link on shares space root |
| view | Personal | cannot create link on personal space root |
| edit | Personal | cannot create link on personal space root |
| upload | Personal | cannot create link on personal space root |
@@ -1394,6 +1394,7 @@ Feature: Create a link share for a resource
Examples:
| drive | message |
| Personal | cannot create link on personal space root |
| Shares | cannot create link on shares space root |
Scenario Outline: try to create an internal link share with password of a Personal and Shares drives using permissions endpoint
@@ -1427,7 +1428,7 @@ Feature: Create a link share for a resource
]
},
"message": {
"const": "password is redundant for the internal link"
"const": "<message>"
}
}
}
@@ -1435,9 +1436,9 @@ Feature: Create a link share for a resource
}
"""
Examples:
| drive |
| Personal |
| Shares |
| drive | message |
| Personal | password is redundant for the internal link |
| Shares | cannot create link on shares space root |
Scenario: create an internal link share of a project-space using permissions endpoint