Skip to content

Commit

Permalink
add userType on shares and test
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Mar 31, 2023
1 parent b6d5f05 commit 45bcf92
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 8 deletions.
4 changes: 1 addition & 3 deletions internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ const (
// ShareTypeUser refers to user shares
ShareTypeUser ShareType = 0

// ShareTypeGuestUser refers to guest user shares
ShareTypeGuestUser ShareType = 4

// ShareTypePublicLink refers to public link shares
ShareTypePublicLink ShareType = 3

Expand Down Expand Up @@ -218,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ func (h *Handler) FindSharees(w http.ResponseWriter, r *http.Request) {
}

func (h *Handler) userAsMatch(u *userpb.User) *conversions.MatchData {
shareType := conversions.ShareTypeUser
if u.Id.Type == userpb.UserType_USER_TYPE_GUEST {
shareType = conversions.ShareTypeGuestUser
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(shareType),
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"))
})
})
})

0 comments on commit 45bcf92

Please sign in to comment.