Skip to content

Commit

Permalink
wip: add basic structure for invitation graph beta api
Browse files Browse the repository at this point in the history
  • Loading branch information
fschade committed Nov 8, 2023
1 parent f008d66 commit 5cce604
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
15 changes: 15 additions & 0 deletions changelog/unreleased/enhancement-sharing-ng.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Enhancement: Add Sharing NG endpoints

We've added new sharing ng endpoints to the graph beta api.
The following endpoints are added:

* /v1beta1/drives/{drive-id}/items/{item-id}/createLink (create a sharing link)

https://github.com/owncloud/ocis/pull/7633
https://github.com/owncloud/ocis/pull/7686
https://github.com/owncloud/ocis/pull/7684
https://github.com/owncloud/ocis/pull/7683
https://github.com/owncloud/ocis/pull/7239
https://github.com/owncloud/libre-graph-api/pull/112
https://github.com/owncloud/ocis/issues/7436
https://github.com/owncloud/ocis/issues/6993
53 changes: 52 additions & 1 deletion services/graph/pkg/service/v0/driveitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/go-chi/render"
libregraph "github.com/owncloud/libre-graph-api-go"
"golang.org/x/crypto/sha3"

"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
"golang.org/x/crypto/sha3"
)

// GetRootDriveChildren implements the Service interface.
Expand Down Expand Up @@ -234,6 +235,56 @@ func (g Graph) GetDriveItemChildren(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, &ListResponse{Value: files})
}

// Invite invites a user to a storage drive (space).
func (g Graph) Invite(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

driveID, err := storagespace.ParseID(chi.URLParam(r, "driveID"))
if err != nil {
errorcode.RenderError(w, r, errorcode.New(errorcode.InvalidRequest, err.Error()))
return
}

driveItemID, err := storagespace.ParseID(chi.URLParam(r, "driveItemID"))
if err != nil {
errorcode.RenderError(w, r, errorcode.New(errorcode.InvalidRequest, err.Error()))
return
}

if driveID.StorageId != driveItemID.StorageId || driveID.SpaceId != driveItemID.SpaceId {
errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, "Item does not exist")
return
}

gatewayClient, err := g.gatewaySelector.Next()
if err != nil {
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
return
}

statResponse, err := gatewayClient.Stat(ctx, &storageprovider.StatRequest{Ref: &storageprovider.Reference{ResourceId: &driveItemID}})
if err != nil {
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
return
}
switch statResponse.Status.Code {
case cs3rpc.Code_CODE_OK:
// ok
case cs3rpc.Code_CODE_NOT_FOUND:
errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, statResponse.Status.Message)
return
case cs3rpc.Code_CODE_PERMISSION_DENIED:
errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, statResponse.Status.Message) // do not leak existence? check what graph does
return
case cs3rpc.Code_CODE_UNAUTHENTICATED:
errorcode.Unauthenticated.Render(w, r, http.StatusUnauthorized, statResponse.Status.Message) // do not leak existence? check what graph does
return
default:
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, statResponse.Status.Message)
return
}
}

func (g Graph) getDriveItem(ctx context.Context, ref storageprovider.Reference) (*libregraph.DriveItem, error) {
gatewayClient, err := g.gatewaySelector.Next()
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion services/graph/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
ldapv3 "github.com/go-ldap/ldap/v3"
"github.com/jellydator/ttlcache/v3"
libregraph "github.com/owncloud/libre-graph-api-go"
microstore "go-micro.dev/v4/store"

ocisldap "github.com/owncloud/ocis/v2/ocis-pkg/ldap"
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
"github.com/owncloud/ocis/v2/ocis-pkg/roles"
Expand All @@ -25,7 +27,6 @@ import (
"github.com/owncloud/ocis/v2/services/graph/pkg/identity"
"github.com/owncloud/ocis/v2/services/graph/pkg/identity/ldap"
graphm "github.com/owncloud/ocis/v2/services/graph/pkg/middleware"
microstore "go-micro.dev/v4/store"
)

const (
Expand Down Expand Up @@ -105,6 +106,8 @@ type Service interface {
GetDriveItem(w http.ResponseWriter, r *http.Request)
GetDriveItemChildren(w http.ResponseWriter, r *http.Request)

Invite(w http.ResponseWriter, r *http.Request)

GetTags(w http.ResponseWriter, r *http.Request)
AssignTags(w http.ResponseWriter, r *http.Request)
UnassignTags(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -202,6 +205,7 @@ func NewService(opts ...Option) (Graph, error) {
r.Use(middleware.StripSlashes)
r.Route("/v1beta1", func(r chi.Router) {
r.Get("/me/drive/sharedByMe", svc.GetSharedByMe)
r.Get("/drives/{driveID}/items/{driveItemID}/createLink", svc.Invite)
})
r.Route("/v1.0", func(r chi.Router) {
r.Route("/extensions/org.libregraph", func(r chi.Router) {
Expand Down

0 comments on commit 5cce604

Please sign in to comment.