Merge pull request #3243 from opencloud-eu/fix/graph-get-user-drive-id-or-name

feat(graph): accept user name or id in GetUserDrive
This commit is contained in:
Andre Duffeck authored and GitHub committed 2026-11-27 11:27:19 +01:00
commit fd9bb83f78
3 files changed
+49 -1

No files matched your search

+1
View File
@@ -99,6 +99,7 @@ type Service interface { //nolint:interfacebloat
GetDrivesV1Beta1(w http.ResponseWriter, r *http.Request)
GetSingleDrive(w http.ResponseWriter, r *http.Request)
GetSingleDriveV1Beta1(w http.ResponseWriter, r *http.Request)
GetUserDrive(w http.ResponseWriter, r *http.Request)
GetAllDrivesV1(w http.ResponseWriter, r *http.Request)
GetAllDrivesV1Beta1(w http.ResponseWriter, r *http.Request)
CreateDrive(w http.ResponseWriter, r *http.Request)
+11 -1
View File
@@ -147,13 +147,15 @@ func (g Graph) GetUserDrive(w http.ResponseWriter, r *http.Request) {
log = log.With().Str("userID", userID).Logger()
_, expandPermissions, err := parseDriveRequest(r)
odataReq, expandPermissions, err := parseDriveRequest(r)
if err != nil {
log.Debug().Err(err).Msg("could not get drives: error parsing odata request")
errorcode.RenderError(w, r, err)
return
}
// Empty {user-id} is the current user (/me/drive); a non-empty one may be
// an id or a name, so resolve it to the opaque id the filter expects.
if userID == "" {
u, ok := revactx.ContextGetUser(ctx)
if !ok {
@@ -162,6 +164,14 @@ func (g Graph) GetUserDrive(w http.ResponseWriter, r *http.Request) {
return
}
userID = u.GetId().GetOpaqueId()
} else {
user, err := g.identityBackend.GetUser(ctx, userID, odataReq)
if err != nil {
log.Debug().Err(err).Str("userID", userID).Msg("could not get user drive: failed to resolve user")
errorcode.RenderError(w, r, err)
return
}
userID = user.GetId()
}
log.Debug().Msg("calling list storage spaces with user and personal filter")
@@ -180,6 +180,43 @@ var _ = Describe("Users", func() {
Expect(err).ToNot(HaveOccurred())
})
Describe("GetUserDrive", func() {
It("resolves the user by name before looking up the personal space", func() {
user := &libregraph.User{}
user.SetId("user1")
// A name in the path must be resolved to the user id via the
// identity backend before the storage space filter runs.
permissionService.On("GetPermissionByID", mock.Anything, mock.Anything).Return(&settings.GetPermissionByIDResponse{}, nil)
identityBackend.On("GetUser", mock.Anything, "alice", mock.Anything).Return(user, nil)
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
Status: status.NewOK(ctx),
StorageSpaces: []*provider.StorageSpace{
{
Id: &provider.StorageSpaceId{OpaqueId: "drive1"},
Root: &provider.ResourceId{StorageId: "storage", SpaceId: "space", OpaqueId: "space"},
SpaceType: "personal",
},
},
}, nil)
gatewayClient.On("GetQuota", mock.Anything, mock.Anything, mock.Anything).Return(&provider.GetQuotaResponse{
Status: status.NewOK(ctx),
TotalBytes: 10,
}, nil)
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).
Return(&settings.GetValueResponse{}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users/alice/drive", nil)
rctx := chi.NewRouteContext()
rctx.URLParams.Add("userID", "alice")
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
svc.GetUserDrive(rr, r)
Expect(rr.Code).To(Equal(http.StatusOK))
identityBackend.AssertCalled(GinkgoT(), "GetUser", mock.Anything, "alice", mock.Anything)
})
})
Describe("GetMe", func() {
It("handles missing user", func() {
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me", nil)