Skip to content

Commit

Permalink
Bring back public link sharing of project space roots
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed May 15, 2023
1 parent e00c55c commit c607fd0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/allow-public-sharing-project-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Bring back public link sharing of project space roots

We reenabled sharing of project space roots

https://github.com/cs3org/reva/pull/3890
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
ctx := r.Context()
log := appctx.GetLogger(ctx)

c, err := pool.GetGatewayServiceClient(h.gatewayAddr)
c, err := h.getClient()
if err != nil {
return nil, &ocsError{
Code: response.MetaServerError.StatusCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (h *Handler) CreateShare(w http.ResponseWriter, r *http.Request) {
}
sublog := appctx.GetLogger(ctx).With().Interface("ref", ref).Logger()

statReq := provider.StatRequest{Ref: &ref}
statReq := provider.StatRequest{Ref: &ref, FieldMask: &fieldmaskpb.FieldMask{Paths: []string{"space"}}}
statRes, err := client.Stat(ctx, &statReq)
if err != nil {
sublog.Debug().Err(err).Msg("CreateShare: error on stat call")
Expand All @@ -233,6 +233,7 @@ func (h *Handler) CreateShare(w http.ResponseWriter, r *http.Request) {

// check that this is a valid share
if statRes.Info.Id.OpaqueId == statRes.Info.Id.SpaceId &&
statRes.GetInfo().GetSpace().GetSpaceType() == "personal" &&
(shareType != int(conversions.ShareTypeSpaceMembershipUser) && shareType != int(conversions.ShareTypeSpaceMembershipGroup)) {
response.WriteOCSError(w, r, http.StatusBadRequest, "Can not share space root", nil)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/config"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares"
Expand Down Expand Up @@ -101,7 +104,7 @@ var _ = Describe("The ocs API", func() {
}, nil)
})

Context("when sharing the space root", func() {
Context("when sharing the personal space root", func() {
BeforeEach(func() {
client.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{
Status: status.NewOK(context.Background()),
Expand All @@ -121,6 +124,9 @@ var _ = Describe("The ocs API", func() {
RemoveGrant: true,
},
Size: 10,
Space: &provider.StorageSpace{
SpaceType: "personal",
},
},
}, nil)
})
Expand All @@ -144,6 +150,71 @@ var _ = Describe("The ocs API", func() {
})
})

Context("when sharing a project space root via link", func() {
BeforeEach(func() {
var (
resID = &provider.ResourceId{
StorageId: "share1-storageid",
OpaqueId: "share1",
}
)

client.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{
Status: status.NewOK(context.Background()),
Info: &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Path: "/",
Id: resID,
Owner: user.Id,
PermissionSet: &provider.ResourcePermissions{
Stat: true,
ListContainer: true,
GetPath: true,
GetQuota: true,
InitiateFileDownload: true,
AddGrant: true,
ListGrants: true,
ListRecycle: true,
UpdateGrant: true,
RemoveGrant: true,
},
Size: 10,
Space: &provider.StorageSpace{
SpaceType: "project",
},
},
}, nil)

client.On("CheckPermission", mock.Anything, mock.Anything, mock.Anything).Return(&permissions.CheckPermissionResponse{
Status: &rpc.Status{Code: rpc.Code_CODE_OK},
}, nil)

client.On("CreatePublicShare", mock.Anything, mock.Anything).Return(&link.CreatePublicShareResponse{
Status: status.NewOK(context.Background()),
Share: &link.PublicShare{
Token: "foo",
Creator: user.Id,
Owner: user.Id,
},
}, nil)
})

It("creates a link share", func() {
form := url.Values{}
form.Add("shareType", "3")
form.Add("path", "/")
form.Add("space", "storageid!spaceid")
form.Add("permissions", "1")
req := httptest.NewRequest("POST", "/apps/files_sharing/api/v1/shares", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req = req.WithContext(ctx)

w := httptest.NewRecorder()
h.CreateShare(w, req)
Expect(w.Result().StatusCode).To(Equal(200))
})
})

Context("when sharing a resource", func() {
var (
resID = &provider.ResourceId{
Expand Down

0 comments on commit c607fd0

Please sign in to comment.