From 3a59c7ec4c2677fb83861fcd8fca284b3db46c61 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 7 Mar 2022 17:51:27 +0100 Subject: [PATCH] add driveAlias to the graphAPI --- changelog/unreleased/space-aliases.md | 5 ++++ go.mod | 2 +- go.sum | 4 +-- graph/pkg/service/v0/drives.go | 25 +++++++++++-------- .../features/apiSpaces/listSpaces.feature | 2 ++ 5 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 changelog/unreleased/space-aliases.md diff --git a/changelog/unreleased/space-aliases.md b/changelog/unreleased/space-aliases.md new file mode 100644 index 00000000000..4d291c09458 --- /dev/null +++ b/changelog/unreleased/space-aliases.md @@ -0,0 +1,5 @@ +Enhancement: Add space aliases + +Space aliases can be used to resolve spaceIDs in a client. + +https://github.com/owncloud/ocis/pull/3283 diff --git a/go.mod b/go.mod index a593e47f8c9..9a44aa5f8e4 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/blevesearch/bleve/v2 v2.3.1 github.com/coreos/go-oidc/v3 v3.1.0 github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 - github.com/cs3org/reva/v2 v2.0.0-20220314085001-8e5b22a20a3f + github.com/cs3org/reva/v2 v2.0.0-20220315083752-d008faf40d48 github.com/disintegration/imaging v1.6.2 github.com/glauth/glauth/v2 v2.0.0-20211021011345-ef3151c28733 github.com/go-chi/chi/v5 v5.0.7 diff --git a/go.sum b/go.sum index 757c94253e4..3734404fa80 100644 --- a/go.sum +++ b/go.sum @@ -341,8 +341,8 @@ github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD9 github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 h1:1jqPH58jCxvbaJ9WLIJ7W2/m622bWS6ChptzljSG6IQ= github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva/v2 v2.0.0-20220314085001-8e5b22a20a3f h1:tv7v6OjbFoDFNB2ikGC+LLaWEOIAJnrZjyO5LRTDL0g= -github.com/cs3org/reva/v2 v2.0.0-20220314085001-8e5b22a20a3f/go.mod h1:XNtK1HEClNzmz5vyQa2DUw4KH3oqBjQoEsV1LhAGlV0= +github.com/cs3org/reva/v2 v2.0.0-20220315083752-d008faf40d48 h1:BLaNoseOPNvE5Khyc0DnUBFb29oiRja1RRCLBQcrjOQ= +github.com/cs3org/reva/v2 v2.0.0-20220315083752-d008faf40d48/go.mod h1:XNtK1HEClNzmz5vyQa2DUw4KH3oqBjQoEsV1LhAGlV0= 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= diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index e3e16186164..a82f284223c 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -218,6 +218,10 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { csr.Opaque = utils.AppendPlainToOpaque(csr.Opaque, "description", *drive.Description) } + if drive.DriveAlias != nil { + csr.Opaque = utils.AppendPlainToOpaque(csr.Opaque, "spaceAlias", *drive.DriveAlias) + } + resp, err := client.CreateStorageSpace(r.Context(), &csr) if err != nil { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) @@ -303,24 +307,19 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { } } - // Note: this is the Opaque prop of the space itself - opaque := make(map[string]*types.OpaqueEntry) if drive.Description != nil { - opaque["description"] = &types.OpaqueEntry{ - Decoder: "plain", - Value: []byte(*drive.Description), - } + updateSpaceRequest.StorageSpace.Opaque = utils.AppendPlainToOpaque(updateSpaceRequest.StorageSpace.Opaque, "description", *drive.Description) + } + + if drive.DriveAlias != nil { + updateSpaceRequest.StorageSpace.Opaque = utils.AppendPlainToOpaque(updateSpaceRequest.StorageSpace.Opaque, "spaceAlias", *drive.DriveAlias) } for _, special := range drive.Special { if special.Id != nil { - opaque[*special.SpecialFolder.Name] = &types.OpaqueEntry{ - Decoder: "plain", - Value: []byte(*special.Id), - } + updateSpaceRequest.StorageSpace.Opaque = utils.AppendPlainToOpaque(updateSpaceRequest.StorageSpace.Opaque, *special.SpecialFolder.Name, *special.Id) } } - updateSpaceRequest.StorageSpace.Opaque = &types.Opaque{Map: opaque} if drive.Name != nil { updateSpaceRequest.StorageSpace.Name = *drive.Name @@ -508,6 +507,10 @@ func (g Graph) cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.S drive.Description = libregraph.PtrString(string(description.Value)) } + if alias, ok := space.Opaque.Map["spaceAlias"]; ok { + drive.DriveAlias = libregraph.PtrString(string(alias.Value)) + } + if v, ok := space.Opaque.Map["trashed"]; ok { deleted := &libregraph.Deleted{} deleted.SetState(string(v.Value)) diff --git a/tests/acceptance/features/apiSpaces/listSpaces.feature b/tests/acceptance/features/apiSpaces/listSpaces.feature index 920700154a8..b0af266c50d 100644 --- a/tests/acceptance/features/apiSpaces/listSpaces.feature +++ b/tests/acceptance/features/apiSpaces/listSpaces.feature @@ -15,6 +15,7 @@ Feature: List and create spaces And the json responded should contain a space "Alice Hansen" with these key and value pairs: | key | value | | driveType | personal | + | driveAlias | personal/Alice | | id | %space_id% | | name | Alice Hansen | | quota@@@state | normal | @@ -61,6 +62,7 @@ Feature: List and create spaces And the json responded should contain a space "Project Mars" with these key and value pairs: | key | value | | driveType | project | + | driveAlias | project/project-mars | | name | Project Mars | | quota@@@total | 1000000000 | | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |