diff --git a/go.mod b/go.mod index f96e0f108..1fe1f0cca 100644 --- a/go.mod +++ b/go.mod @@ -79,6 +79,7 @@ require ( ) replace ( + github.com/cs3org/reva => ../../refs/reva github.com/crewjam/saml => github.com/crewjam/saml v0.4.5 go.etcd.io/etcd/api/v3 => go.etcd.io/etcd/api/v3 v3.0.0-20210204162551-dae29bb719dd go.etcd.io/etcd/pkg/v3 => go.etcd.io/etcd/pkg/v3 v3.0.0-20210204162551-dae29bb719dd diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index 1097f8c12..931227e7e 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -8,16 +8,18 @@ import ( "path" "time" - ctxpkg "github.com/cs3org/reva/pkg/ctx" - cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" + ctxpkg "github.com/cs3org/reva/pkg/ctx" "github.com/go-chi/chi/v5" "github.com/go-chi/render" "github.com/owncloud/ocis/graph/pkg/service/v0/errorcode" + "github.com/owncloud/ocis/ocis-pkg/service/grpc" + sproto "github.com/owncloud/ocis/settings/pkg/proto/v0" + settingsSvc "github.com/owncloud/ocis/settings/pkg/service/v0" msgraph "github.com/owncloud/open-graph-api-go" ) @@ -142,6 +144,17 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { return } + s := sproto.NewPermissionService("com.owncloud.api.settings", grpc.DefaultClient) + + _, err := s.GetPermissionByID(r.Context(), &sproto.GetPermissionByIDRequest{ + PermissionId: settingsSvc.CreateSpacePermissionID, + }) + if err != nil { + // if the permission is not existing for the user in context we can assume we don't have it. Return 401. + errorcode.GeneralException.Render(w, r, http.StatusUnauthorized, "insufficient permissions to create a space.") + return + } + client, err := g.GetClient() if err != nil { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) diff --git a/graph/pkg/service/v0/service.go b/graph/pkg/service/v0/service.go index f5c74780a..c8a96ecae 100644 --- a/graph/pkg/service/v0/service.go +++ b/graph/pkg/service/v0/service.go @@ -3,6 +3,9 @@ package svc import ( "net/http" + "github.com/owncloud/ocis/ocis-pkg/account" + opkgm "github.com/owncloud/ocis/ocis-pkg/middleware" + "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) @@ -51,6 +54,10 @@ func NewService(opts ...Option) Service { }) }) r.Route("/drives", func(r chi.Router) { + r.Use(opkgm.ExtractAccountUUID( + account.Logger(options.Logger), + account.JWTSecret(options.Config.TokenManager.JWTSecret)), + ) // This route is non-compliant with MS Graph implementation; creating a drive is not supported. There // is no official MS SDK support for this method. r.Post("/{drive-name}", svc.CreateDrive)