-
Notifications
You must be signed in to change notification settings - Fork 189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
if err != nil { | ||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
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