Skip to content
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

Set correct share type when listing shares #3759

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Set correct share type when listing shares

This fixes so that we can differentiate between guest/member users for shares.

https://github.com/cs3org/reva/pull/3759
4 changes: 3 additions & 1 deletion internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ type MatchValueData struct {
ShareType int `json:"shareType" xml:"shareType"`
ShareWith string `json:"shareWith" xml:"shareWith"`
ShareWithAdditionalInfo string `json:"shareWithAdditionalInfo" xml:"shareWithAdditionalInfo"`
UserType int `json:"userType" xml:"userType"`
}

// CS3Share2ShareData converts a cs3api user share into shareData data model
Expand All @@ -229,7 +230,8 @@ func CS3Share2ShareData(ctx context.Context, share *collaboration.Share) (*Share
if share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
sd.ShareType = ShareTypeUser
sd.ShareWith = LocalUserIDToString(share.Grantee.GetUserId())
if share.GetGrantee().GetUserId().GetType() == userpb.UserType_USER_TYPE_LIGHTWEIGHT {
shareType := share.GetGrantee().GetUserId().GetType()
if shareType == userpb.UserType_USER_TYPE_LIGHTWEIGHT || shareType == userpb.UserType_USER_TYPE_GUEST {
sd.ShareWithUserType = ShareWithUserTypeGuest
} else {
sd.ShareWithUserType = ShareWithUserTypeUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,17 @@ func (h *Handler) FindSharees(w http.ResponseWriter, r *http.Request) {
}

func (h *Handler) userAsMatch(u *userpb.User) *conversions.MatchData {
var ocsUserType int
if u.Id.Type == userpb.UserType_USER_TYPE_GUEST || u.Id.Type == userpb.UserType_USER_TYPE_LIGHTWEIGHT {
ocsUserType = 1
}

return &conversions.MatchData{
Label: u.DisplayName,
Value: &conversions.MatchValueData{
ShareType: int(conversions.ShareTypeUser),
// api compatibility with oc10: mark guest users in share invite dialogue
UserType: ocsUserType,
// api compatibility with oc10: always use the username
ShareWith: u.Username,
ShareWithAdditionalInfo: h.getAdditionalInfoAttribute(u),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ var _ = Describe("The ocs API", func() {
)
type (
share struct {
ID string `xml:"id"`
ID string `xml:"id"`
ShareType string `xml:"share_type"`
ShareWithUserType string `xml:"share_with_user_type"`
}
data struct {
Shares []share `xml:"element"`
Expand Down Expand Up @@ -440,7 +442,109 @@ var _ = Describe("The ocs API", func() {
s1 := res.Data.Shares[0]
s2 := res.Data.Shares[1]
Expect(s1.ID).To(Equal("11"))
Expect(s1.ShareType).To(Equal("0"))
Expect(s1.ShareWithUserType).To(Equal("0"))
Expect(s2.ID).To(Equal("12"))
Expect(s2.ShareType).To(Equal("0"))
Expect(s2.ShareWithUserType).To(Equal("0"))
})
})
Describe("List Guest Shares", func() {
BeforeEach(func() {
resID := &provider.ResourceId{
StorageId: "share1-storageid",
SpaceId: "space-1",
OpaqueId: "share1",
}
userGuest := &userpb.User{
Id: &userpb.UserId{
OpaqueId: helpers.User0ID,
Type: userpb.UserType_USER_TYPE_GUEST,
},
}
client.On("ListReceivedShares", mock.Anything, mock.Anything, mock.Anything).Return(&collaboration.ListReceivedSharesResponse{
Status: status.NewOK(context.Background()),
Shares: []*collaboration.ReceivedShare{
{
State: collaboration.ShareState_SHARE_STATE_ACCEPTED,
Share: &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: "10"},
Grantee: &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_USER,
Id: &provider.Grantee_UserId{
UserId: userGuest.Id,
},
},
Creator: user.Id,
ResourceId: resID,
Permissions: &collaboration.SharePermissions{
Permissions: &provider.ResourcePermissions{
Stat: true,
ListContainer: true,
},
},
},
MountPoint: &provider.Reference{Path: "share1"},
},
},
}, nil)

client.On("ListShares", mock.Anything, mock.Anything).Return(&collaboration.ListSharesResponse{
Status: status.NewOK(context.Background()),
Shares: []*collaboration.Share{
{
Id: &collaboration.ShareId{OpaqueId: "10"},
Grantee: &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_USER,
Id: &provider.Grantee_UserId{
UserId: userGuest.Id,
},
},
Creator: user.Id,
ResourceId: resID,
Permissions: &collaboration.SharePermissions{
Permissions: &provider.ResourcePermissions{
Stat: true,
ListContainer: true,
},
},
},
},
}, nil)

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: "/share1",
Id: resID,
Owner: user.Id,
PermissionSet: &provider.ResourcePermissions{
Stat: true,
},
Size: 10,
},
}, nil)

client.On("GetUser", mock.Anything, mock.Anything).Return(&userpb.GetUserResponse{
Status: status.NewOK(context.Background()),
User: user,
}, nil)
})
It("lists guest shares as creator", func() {
req := httptest.NewRequest("GET", "/apps/files_sharing/api/v1/shares?reshares=true", nil).WithContext(ctx)
w := httptest.NewRecorder()
h.ListShares(w, req)
Expect(w.Result().StatusCode).To(Equal(200))

res := &response{}
err := xml.Unmarshal(w.Body.Bytes(), res)
Expect(err).ToNot(HaveOccurred())
Expect(len(res.Data.Shares)).To(Equal(1))
s := res.Data.Shares[0]
Expect(s.ID).To(Equal("10"))
Expect(s.ShareWithUserType).To(Equal("1"))
Expect(s.ShareType).To(Equal("0"))
})
})
})