From 1e21e230566d31d01ba7740b7057761ae0108cd9 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 29 Jun 2022 16:00:00 +0200 Subject: [PATCH 1/5] add drives output Signed-off-by: Christian Richter --- services/graph/pkg/identity/cs3.go | 1 - services/graph/pkg/service/v0/drives.go | 11 +++++++++ services/graph/pkg/service/v0/users.go | 31 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/services/graph/pkg/identity/cs3.go b/services/graph/pkg/identity/cs3.go index 039edbfb8..a42bbdbc4 100644 --- a/services/graph/pkg/identity/cs3.go +++ b/services/graph/pkg/identity/cs3.go @@ -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? } } diff --git a/services/graph/pkg/service/v0/drives.go b/services/graph/pkg/service/v0/drives.go index 9ec9984db..fd8c25709 100644 --- a/services/graph/pkg/service/v0/drives.go +++ b/services/graph/pkg/service/v0/drives.go @@ -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, diff --git a/services/graph/pkg/service/v0/users.go b/services/graph/pkg/service/v0/users.go index 96f8e9cc7..d5b845bef 100644 --- a/services/graph/pkg/service/v0/users.go +++ b/services/graph/pkg/service/v0/users.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/CiscoM31/godata" + 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" @@ -21,6 +22,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 +173,35 @@ 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) + // TODO: filter this request for the user + 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") + } + 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) From a030459c70fed8bf1ce28083e8d19dafef44c6db Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 18 Jul 2022 13:26:10 +0200 Subject: [PATCH 2/5] incorporate requested changes Signed-off-by: Christian Richter --- services/graph/pkg/service/v0/users.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/graph/pkg/service/v0/users.go b/services/graph/pkg/service/v0/users.go index d5b845bef..8fa16c173 100644 --- a/services/graph/pkg/service/v0/users.go +++ b/services/graph/pkg/service/v0/users.go @@ -11,10 +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" @@ -177,7 +179,6 @@ func (g Graph) GetUser(w http.ResponseWriter, r *http.Request) { 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) - // TODO: filter this request for the user f := listStorageSpacesUserFilter(user.GetId()) lspr, err := g.gatewayClient.ListStorageSpaces(r.Context(), &storageprovider.ListStorageSpacesRequest{ Opaque: nil, @@ -185,6 +186,15 @@ func (g Graph) GetUser(w http.ResponseWriter, r *http.Request) { }) 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() { From 7d844960a14c3f69620f02822d51411eb42c929c Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 19 Jul 2022 12:01:21 +0200 Subject: [PATCH 3/5] add changelog Signed-off-by: Christian Richter --- changelog/unreleased/add-drives-endpoint-and-userfilter.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/add-drives-endpoint-and-userfilter.md diff --git a/changelog/unreleased/add-drives-endpoint-and-userfilter.md b/changelog/unreleased/add-drives-endpoint-and-userfilter.md new file mode 100644 index 000000000..98035fd41 --- /dev/null +++ b/changelog/unreleased/add-drives-endpoint-and-userfilter.md @@ -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 \ No newline at end of file From 3da88ef6088e691146df705f96ccd8cd612e6e50 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 27 Jul 2022 15:22:03 +0200 Subject: [PATCH 4/5] use reva/v2@edge Signed-off-by: Christian Richter --- changelog/unreleased/update-reva-beta.6.md | 1 + go.mod | 2 +- go.sum | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/changelog/unreleased/update-reva-beta.6.md b/changelog/unreleased/update-reva-beta.6.md index 2bcd4071d..98b18edba 100644 --- a/changelog/unreleased/update-reva-beta.6.md +++ b/changelog/unreleased/update-reva-beta.6.md @@ -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 \ No newline at end of file diff --git a/go.mod b/go.mod index b2ca0c18f..d5282be1f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e09cf638c..92811f459 100644 --- a/go.sum +++ b/go.sum @@ -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= From 32123487277dcd0345552da861c90f6b9700d523 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 1 Aug 2022 10:12:30 +0200 Subject: [PATCH 5/5] add expected failures Signed-off-by: Christian Richter --- .../acceptance/expected-failures-localAPI-on-OCIS-storage.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 2fe0ae8d1..0e74c2fda 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -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) +