Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable users to list all spaces #2692

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/list-all-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add API to list all spaces

Added a graph endpoint to enable users with the `list-all-spaces` permission to list all spaces.

https://github.com/owncloud/ocis/pull/2692
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/blevesearch/bleve/v2 v2.2.1
github.com/coreos/go-oidc/v3 v3.1.0
github.com/cs3org/go-cs3apis v0.0.0-20211018122138-391b29bd7803
github.com/cs3org/reva v1.15.0
github.com/cs3org/reva v1.15.1-0.20211027114107-4879bf6be97a
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.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20211018122138-391b29bd7803 h1:R/6llgTNKxQQ7GaSTgFn6Fp8N50wIlagmdR7WY5LntM=
github.com/cs3org/go-cs3apis v0.0.0-20211018122138-391b29bd7803/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva v1.15.0 h1:06Nso0/2ySmt/bXbXip/QQ1bUPwBUuqYm2zJXrYiR2A=
github.com/cs3org/reva v1.15.0/go.mod h1:Pwo2bbUCXDfGPIxh1392/a7393H7S+roP7ccip67wTI=
github.com/cs3org/reva v1.15.1-0.20211027114107-4879bf6be97a h1:rg00QAtWaC4vQMWJzp6m5UQfO1WgBg9g9tXz8jvjGtA=
github.com/cs3org/reva v1.15.1-0.20211027114107-4879bf6be97a/go.mod h1:Pwo2bbUCXDfGPIxh1392/a7393H7S+roP7ccip67wTI=
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=
Expand Down
22 changes: 22 additions & 0 deletions graph/pkg/service/v0/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,29 @@ func (g Graph) GetDrives(w http.ResponseWriter, r *http.Request) {
return
}

permissions := make(map[string]struct{}, 1)
s := sproto.NewPermissionService("com.owncloud.api.settings", grpc.DefaultClient)

_, err = s.GetPermissionByID(ctx, &sproto.GetPermissionByIDRequest{
PermissionId: settingsSvc.ListAllSpacesPermissionID,
})

// No error means the user has the permission
if err == nil {
permissions[settingsSvc.ListAllSpacesPermissionName] = struct{}{}
}
value, err := json.Marshal(permissions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why not using a plain text encoder? Since you're setting the map to be of capacity 1, I imagine for the purposes of this only and not with scaling in mind. IIRC we discussed it was a hack and could easily use a plain text encoder and save some bytes 🤷 . The encoded json stikl takes up 22 bytes (with an example title). See this playground

if err != nil {
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be a good spot to add a trace and set the state to error. There should be one in the context if tracing is enabled, and use the default traceprovider (which writes to nil) if none is configured, it's safe code, and we will benefit from the trace :D we should get in the habit of doing so I guess

return
}
res, err := client.ListStorageSpaces(ctx, &storageprovider.ListStorageSpacesRequest{
Opaque: &types.Opaque{Map: map[string]*types.OpaqueEntry{
"permissions": {
Decoder: "json",
Value: value,
},
}},
// TODO add filters?
})
switch {
Expand Down
1 change: 1 addition & 0 deletions graph/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewService(opts ...Option) Service {
account.JWTSecret(options.Config.TokenManager.JWTSecret)),
)
r.Route("/drives", func(r chi.Router) {
r.Get("/", svc.GetDrives)
r.Post("/", svc.CreateDrive)
})
r.Route("/Drive({firstSegmentIdentifier})", func(r chi.Router) {
Expand Down
23 changes: 23 additions & 0 deletions settings/pkg/service/v0/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const (
// SetSpaceQuotaPermissionName is the hardcoded setting name for the set space quota permission
SetSpaceQuotaPermissionName string = "set-space-quota"

// ListAllSpacesPermissionID is the hardcoded setting UUID for the list all spaces permission
ListAllSpacesPermissionID string = "016f6ddd-9501-4a0a-8ebe-64a20ee8ec82"
// ListAllSpacesPermissionName is the hardcoded setting name for the list all spaces permission
ListAllSpacesPermissionName string = "list-all-spaces"

// CreateSpacePermissionID is the hardcoded setting UUID for the create space permission
CreateSpacePermissionID string = "79e13b30-3e22-11eb-bc51-0b9f0bad9a58"
// CreateSpacePermissionName is the hardcoded setting name for the create space permission
Expand Down Expand Up @@ -378,6 +383,24 @@ func generatePermissionRequests() []*settings.AddSettingToBundleRequest {
},
},
},
{
BundleId: BundleUUIDRoleAdmin,
Setting: &settings.Setting{
Id: ListAllSpacesPermissionID,
Name: ListAllSpacesPermissionName,
DisplayName: "List All Spaces",
Description: "This permission allows list all spaces.",
Resource: &settings.Resource{
Type: settings.Resource_TYPE_SYSTEM,
},
Value: &settings.Setting_PermissionValue{
PermissionValue: &settings.Permission{
Operation: settings.Permission_OPERATION_READ,
Constraint: settings.Permission_CONSTRAINT_ALL,
},
},
},
},
}
}

Expand Down