From a39896cb38fa6ec462fb430282b1fd1e0563446a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 20 Nov 2023 15:19:37 +0100 Subject: [PATCH] Include remote users in the sharee response --- .../handlers/apps/sharing/sharees/sharees.go | 49 ++++++++++++++----- .../handlers/apps/sharing/shares/remote.go | 2 +- pkg/conversions/main.go | 1 + 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go index 3feaf9096c8..7d1a46aad35 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go @@ -24,6 +24,8 @@ import ( grouppb "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1" userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + invitepb "github.com/cs3org/go-cs3apis/cs3/ocm/invite/v1beta1" + rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" "github.com/cs3org/reva/v2/pkg/conversions" "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/config" @@ -79,6 +81,25 @@ func (h *Handler) FindSharees(w http.ResponseWriter, r *http.Request) { } } + remoteUsersRes, err := gwc.FindAcceptedUsers(r.Context(), &invitepb.FindAcceptedUsersRequest{Filter: term}) + if err != nil { + response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error searching remote users", err) + return + } + if remoteUsersRes.Status.Code != rpc.Code_CODE_OK { + response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error searching remote users", nil) + return + } + for _, user := range remoteUsersRes.GetAcceptedUsers() { + match := h.userAsMatch(user) + log.Debug().Interface("user", user).Interface("match", match).Msg("mapped") + if h.isExactMatch(match, term) { + exactUserMatches = append(exactUserMatches, match) + } else { + userMatches = append(userMatches, match) + } + } + groupsRes, err := gwc.FindGroups(r.Context(), &grouppb.FindGroupsRequest{Filter: term, SkipFetchingMembers: true}) if err != nil { response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error searching groups", err) @@ -111,21 +132,27 @@ 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 + data := &conversions.MatchValueData{ + ShareType: int(conversions.ShareTypeUser), + // api compatibility with oc10: mark guest users in share invite dialogue + UserType: 0, + // api compatibility with oc10: always use the username + ShareWith: u.Username, + ShareWithAdditionalInfo: h.getAdditionalInfoAttribute(u), + } + + switch u.Id.Type { + case userpb.UserType_USER_TYPE_GUEST, userpb.UserType_USER_TYPE_LIGHTWEIGHT: + data.UserType = 1 + case userpb.UserType_USER_TYPE_FEDERATED: + data.ShareType = int(conversions.ShareTypeFederatedCloudShare) + data.ShareWith = u.Id.OpaqueId + data.ShareWithProvider = u.Id.Idp } 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), - }, + Value: data, } } diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go index c118f559c86..7cbf4946822 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/remote.go @@ -49,7 +49,7 @@ func (h *Handler) createFederatedCloudShare(w http.ResponseWriter, r *http.Reque return } - shareWithUser, shareWithProvider := r.FormValue("shareWithUser"), r.FormValue("shareWithProvider") + shareWithUser, shareWithProvider := r.FormValue("shareWith"), r.FormValue("shareWithProvider") if shareWithUser == "" || shareWithProvider == "" { response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, "missing shareWith parameters", nil) return diff --git a/pkg/conversions/main.go b/pkg/conversions/main.go index c6f9cc85480..6ff462be8d8 100644 --- a/pkg/conversions/main.go +++ b/pkg/conversions/main.go @@ -224,6 +224,7 @@ type MatchData struct { type MatchValueData struct { ShareType int `json:"shareType" xml:"shareType"` ShareWith string `json:"shareWith" xml:"shareWith"` + ShareWithProvider string `json:"shareWithProvider" xml:"shareWithProvider"` ShareWithAdditionalInfo string `json:"shareWithAdditionalInfo" xml:"shareWithAdditionalInfo,omitempty"` UserType int `json:"userType" xml:"userType"` }