mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-14 21:33:34 -04:00
reduce drives in listing of graph /me/drives API
This commit is contained in:
committed by
Michael Barz
parent
78a6af3af5
commit
ab71b21fc7
6
changelog/unreleased/graph-me-drives.md
Normal file
6
changelog/unreleased/graph-me-drives.md
Normal file
@@ -0,0 +1,6 @@
|
||||
Change: Reduce drives in graph /me/drives API
|
||||
|
||||
Reduced the drives in the graph `/me/drives` API to only the drives the user has access to.
|
||||
The endpoint `/drives` will list all drives when the user has the permission.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/3629
|
||||
@@ -31,8 +31,19 @@ import (
|
||||
merrors "go-micro.dev/v4/errors"
|
||||
)
|
||||
|
||||
// GetDrives implements the Service interface.
|
||||
// GetDrives lists all drives the current user has access to
|
||||
func (g Graph) GetDrives(w http.ResponseWriter, r *http.Request) {
|
||||
g.getDrives(w, r, false)
|
||||
}
|
||||
|
||||
// GetAllDrives lists all drives, including other user's drives, if the current
|
||||
// user has the permission.
|
||||
func (g Graph) GetAllDrives(w http.ResponseWriter, r *http.Request) {
|
||||
g.getDrives(w, r, true)
|
||||
}
|
||||
|
||||
// getDrives implements the Service interface.
|
||||
func (g Graph) getDrives(w http.ResponseWriter, r *http.Request, unrestricted bool) {
|
||||
sanitizedPath := strings.TrimPrefix(r.URL.Path, "/graph/v1.0/")
|
||||
// Parse the request with odata parser
|
||||
odataReq, err := godata.ParseRequest(r.Context(), sanitizedPath, r.URL.Query())
|
||||
@@ -41,7 +52,10 @@ func (g Graph) GetDrives(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
g.logger.Info().Interface("query", r.URL.Query()).Msg("Calling GetDrives")
|
||||
g.logger.Debug().
|
||||
Interface("query", r.URL.Query()).
|
||||
Bool("unrestricted", unrestricted).
|
||||
Msg("Calling getDrives")
|
||||
ctx := r.Context()
|
||||
|
||||
filters, err := generateCs3Filters(odataReq)
|
||||
@@ -50,7 +64,7 @@ func (g Graph) GetDrives(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.NotSupported.Render(w, r, http.StatusNotImplemented, err.Error())
|
||||
return
|
||||
}
|
||||
res, err := g.ListStorageSpacesWithFilters(ctx, filters)
|
||||
res, err := g.ListStorageSpacesWithFilters(ctx, filters, unrestricted)
|
||||
switch {
|
||||
case err != nil:
|
||||
g.logger.Error().Err(err).Msg(ListStorageSpacesTransportErr)
|
||||
@@ -106,7 +120,7 @@ func (g Graph) GetSingleDrive(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
filters := []*storageprovider.ListStorageSpacesRequest_Filter{listStorageSpacesIDFilter(driveID)}
|
||||
res, err := g.ListStorageSpacesWithFilters(ctx, filters)
|
||||
res, err := g.ListStorageSpacesWithFilters(ctx, filters, true)
|
||||
switch {
|
||||
case err != nil:
|
||||
g.logger.Error().Err(err).Msg(ListStorageSpacesTransportErr)
|
||||
@@ -399,7 +413,7 @@ func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, storageSpaces
|
||||
}
|
||||
|
||||
// ListStorageSpacesWithFilters List Storage Spaces using filters
|
||||
func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*storageprovider.ListStorageSpacesRequest_Filter) (*storageprovider.ListStorageSpacesResponse, error) {
|
||||
func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*storageprovider.ListStorageSpacesRequest_Filter, unrestricted bool) (*storageprovider.ListStorageSpacesResponse, error) {
|
||||
client := g.GetGatewayClient()
|
||||
|
||||
permissions := make(map[string]struct{}, 1)
|
||||
@@ -424,6 +438,10 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor
|
||||
Decoder: "json",
|
||||
Value: value,
|
||||
},
|
||||
"unrestricted": {
|
||||
Decoder: "plain",
|
||||
Value: []byte(strconv.FormatBool(unrestricted)),
|
||||
},
|
||||
}},
|
||||
Filters: filters,
|
||||
})
|
||||
|
||||
@@ -173,7 +173,7 @@ func NewService(opts ...Option) Service {
|
||||
account.JWTSecret(options.Config.TokenManager.JWTSecret)),
|
||||
)
|
||||
r.Route("/drives", func(r chi.Router) {
|
||||
r.Get("/", svc.GetDrives)
|
||||
r.Get("/", svc.GetAllDrives)
|
||||
r.Post("/", svc.CreateDrive)
|
||||
r.Route("/{driveID}", func(r chi.Router) {
|
||||
r.Patch("/", svc.UpdateDrive)
|
||||
|
||||
3
go.mod
3
go.mod
@@ -9,7 +9,7 @@ require (
|
||||
github.com/blevesearch/bleve/v2 v2.3.2
|
||||
github.com/coreos/go-oidc/v3 v3.1.0
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde
|
||||
github.com/cs3org/reva/v2 v2.0.0-20220429143817-1cbc34114b5a
|
||||
github.com/cs3org/reva/v2 v2.0.0-20220429105953-71d0c17a5e8f
|
||||
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
|
||||
@@ -274,4 +274,3 @@ require (
|
||||
|
||||
// we need to use a fork to make the windows build pass
|
||||
replace github.com/pkg/xattr => github.com/micbar/xattr v0.4.6-0.20220215112335-88e74d648fb7
|
||||
replace github.com/cs3org/reva/v2 => ../reva
|
||||
|
||||
6
go.sum
6
go.sum
@@ -236,6 +236,8 @@ github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBW
|
||||
github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
|
||||
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
|
||||
github.com/c0rby/reva/v2 v2.0.0-20220429095703-bbac276f2cb4 h1:NAAz/6zTxFa0RBui856DKPIi4cF5jU7FHcbX+n25DM0=
|
||||
github.com/c0rby/reva/v2 v2.0.0-20220429095703-bbac276f2cb4/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
|
||||
@@ -318,8 +320,8 @@ github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde h1:WrD9O8ZaWvsm0
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
|
||||
github.com/cs3org/reva v1.18.0 h1:MbPS5ZAa8RzKcTxAVeSDdISB3XXqLIxqB03BTN5ReBY=
|
||||
github.com/cs3org/reva v1.18.0/go.mod h1:e5VDUDu4vVWIeVkZcW//n6UZzhGGMa+Tz/whCiX3N6o=
|
||||
github.com/cs3org/reva/v2 v2.0.0-20220429143817-1cbc34114b5a h1:Uq+iVa+re1qyeva3lEDEHwqkXv9ImeXBP30ke6IYf+U=
|
||||
github.com/cs3org/reva/v2 v2.0.0-20220429143817-1cbc34114b5a/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng=
|
||||
github.com/cs3org/reva/v2 v2.0.0-20220429105953-71d0c17a5e8f h1:UH9T67KTeWfKCmUQcR8jNSPDSoXaEjS6zkFykILO13w=
|
||||
github.com/cs3org/reva/v2 v2.0.0-20220429105953-71d0c17a5e8f/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng=
|
||||
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=
|
||||
|
||||
Reference in New Issue
Block a user