Merge pull request #4072 from owncloud/fix-user-drives-endpoint

Add drives output & user filter
This commit is contained in:
Christian Richter
2022-08-01 12:09:27 +02:00
committed by GitHub
8 changed files with 70 additions and 4 deletions

View File

@@ -0,0 +1,7 @@
Enhancement: add drives field to users endpoint
We have added `$expand=drives` to the `/users/{id}/` endpoint
using the user filter implemented in reva.
https://github.com/owncloud/ocis/pull/4072
https://github.com/cs3org/reva/pull/3046

View File

@@ -4,3 +4,4 @@ Updated reva to version x.x.x. This update includes:
* TODO:
https://github.com/owncloud/ocis/pull/4272
https://github.com/cs3org/reva/pull/3096

2
go.mod
View File

@@ -10,7 +10,7 @@ require (
github.com/blevesearch/bleve_index_api v1.0.2
github.com/coreos/go-oidc/v3 v3.2.0
github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3
github.com/cs3org/reva/v2 v2.7.3-0.20220725090601-c11d9547a9ed
github.com/cs3org/reva/v2 v2.7.3-0.20220729123357-51c6d5d0c041
github.com/disintegration/imaging v1.6.2
github.com/ggwhite/go-masker v1.0.9
github.com/go-chi/chi/v5 v5.0.7

6
go.sum
View File

@@ -285,8 +285,10 @@ github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4=
github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A=
github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3 h1:QSQ2DGKPMChB4vHSs1Os9TnOJl21BrzKX9D5EtQfDog=
github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva/v2 v2.7.3-0.20220725090601-c11d9547a9ed h1:ATWmYtf21gDXK1lcrxLHZPYLw5t3SzdRxf5DmOxpXkE=
github.com/cs3org/reva/v2 v2.7.3-0.20220725090601-c11d9547a9ed/go.mod h1:9FpnWdVFw7ld3iOiuzHHQeCyVH/Ct9h03PZV9ZRplPM=
github.com/cs3org/reva/v2 v2.7.3-0.20220727111802-29f9f53c2f19 h1:Pu08T+aUlr/MTxBlqdoJx/i8ujtg5zSxGkulBbp89J8=
github.com/cs3org/reva/v2 v2.7.3-0.20220727111802-29f9f53c2f19/go.mod h1:9FpnWdVFw7ld3iOiuzHHQeCyVH/Ct9h03PZV9ZRplPM=
github.com/cs3org/reva/v2 v2.7.3-0.20220729123357-51c6d5d0c041 h1:ObeKsyxTeYJoPyKqjz6qBjd9Q4kDjT1Fht3lGzOOfdc=
github.com/cs3org/reva/v2 v2.7.3-0.20220729123357-51c6d5d0c041/go.mod h1:9FpnWdVFw7ld3iOiuzHHQeCyVH/Ct9h03PZV9ZRplPM=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=

View File

@@ -203,7 +203,6 @@ func createGroupModelFromCS3(g *cs3group.Group) *libregraph.Group {
OnPremisesDomainName: &g.Id.Idp,
OnPremisesSamAccountName: &g.GroupName,
DisplayName: &g.DisplayName,
Mail: &g.Mail,
// TODO when to fetch and expand memberof, usernames or ids?
}
}

View File

@@ -733,6 +733,17 @@ func listStorageSpacesIDFilter(id string) *storageprovider.ListStorageSpacesRequ
}
}
func listStorageSpacesUserFilter(id string) *storageprovider.ListStorageSpacesRequest_Filter {
return &storageprovider.ListStorageSpacesRequest_Filter{
Type: storageprovider.ListStorageSpacesRequest_Filter_TYPE_USER,
Term: &storageprovider.ListStorageSpacesRequest_Filter_User{
User: &userv1beta1.UserId{
OpaqueId: id,
},
},
}
}
func listStorageSpacesTypeFilter(spaceType string) *storageprovider.ListStorageSpacesRequest_Filter {
return &storageprovider.ListStorageSpacesRequest_Filter{
Type: storageprovider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE,

View File

@@ -11,9 +11,12 @@ import (
"strings"
"github.com/CiscoM31/godata"
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
libregraph "github.com/owncloud/libre-graph-api-go"
@@ -21,6 +24,7 @@ import (
"github.com/owncloud/ocis/v2/services/graph/pkg/identity"
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
settingssvc "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0"
"golang.org/x/exp/slices"
)
// GetMe implements the Service interface.
@@ -171,6 +175,43 @@ func (g Graph) GetUser(w http.ResponseWriter, r *http.Request) {
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
}
}
sel := strings.Split(r.URL.Query().Get("$select"), ",")
exp := strings.Split(r.URL.Query().Get("$expand"), ",")
if slices.Contains(sel, "drive") || slices.Contains(sel, "drives") || slices.Contains(exp, "drive") || slices.Contains(exp, "drives") {
wdu, err := url.Parse(g.config.Spaces.WebDavBase + g.config.Spaces.WebDavPath)
f := listStorageSpacesUserFilter(user.GetId())
lspr, err := g.gatewayClient.ListStorageSpaces(r.Context(), &storageprovider.ListStorageSpacesRequest{
Opaque: nil,
Filters: []*storageprovider.ListStorageSpacesRequest_Filter{f},
})
if err != nil {
g.logger.Err(err).Interface("query", r.URL.Query()).Msg("error getting storages")
render.Status(r, http.StatusInternalServerError)
render.JSON(w, r, user)
return
}
if lspr.Status.Code != cs3rpc.Code_CODE_OK {
// in case of NOT_OK, we can just return the user object with empty drives
render.Status(r, status.HTTPStatusFromCode(http.StatusOK))
render.JSON(w, r, user)
return
}
drives := []libregraph.Drive{}
for _, sp := range lspr.GetStorageSpaces() {
d, err := g.cs3StorageSpaceToDrive(r.Context(), wdu, sp)
if err != nil {
g.logger.Err(err).Interface("query", r.URL.Query()).Msg("error converting space to drive")
}
if slices.Contains(sel, "drive") || slices.Contains(exp, "drive") {
if *d.DriveType == "personal" {
drives = append(drives, *d)
}
} else {
drives = append(drives, *d)
}
}
user.Drives = drives
}
render.Status(r, http.StatusOK)
render.JSON(w, r, user)

View File

@@ -45,3 +45,8 @@ The expected failures in this file are from features in the owncloud/ocis repo.
### [A space manager cannot see the public links of another manager](https://github.com/owncloud/ocis/issues/4260)
- [apiSpaces/editPublicLinkOfSpace.feature:67](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature#L67)
### [User without space manager role cannot restore space](https://github.com/owncloud/ocis/issues/4027)
- [apiSpaces/restoreSpaces.feature:63](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/restoreSpaces.feature#L63)
- [apiSpaces/restoreSpaces.feature:64](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/restoreSpaces.feature#L64)