From 366d1c2c10d8d22014ec482164fe1243e87ae43f Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Wed, 31 May 2023 14:41:31 +0200 Subject: [PATCH] Fix the empty exact list while searching for a sharee #issue-4265 --- changelog/unreleased/fix-empty-exact-list.md | 7 +++++ go.mod | 2 +- go.sum | 2 ++ .../expected-failures-API-on-OCIS-storage.md | 10 +------ .../services/owncloud/ocs/conversions/main.go | 2 +- .../handlers/apps/sharing/sharees/sharees.go | 27 ++++++++++++++++--- vendor/modules.txt | 2 +- 7 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 changelog/unreleased/fix-empty-exact-list.md diff --git a/changelog/unreleased/fix-empty-exact-list.md b/changelog/unreleased/fix-empty-exact-list.md new file mode 100644 index 0000000000..e80474d977 --- /dev/null +++ b/changelog/unreleased/fix-empty-exact-list.md @@ -0,0 +1,7 @@ +Bugfix: Empty exact list while searching for a sharee + +We fixed a bug in the sharing api, it always returns an empty exact list while searching for a sharee + +https://github.com/owncloud/ocis/pull/6398 +https://github.com/cs3org/reva/pull/3877 +https://github.com/owncloud/ocis/issues/4265 diff --git a/go.mod b/go.mod index 8ef934c820..a808c51f17 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/coreos/go-oidc v2.2.1+incompatible github.com/coreos/go-oidc/v3 v3.6.0 github.com/cs3org/go-cs3apis v0.0.0-20230516150832-730ac860c71d - github.com/cs3org/reva/v2 v2.13.4-0.20230531095732-bc9a3b635ec3 + github.com/cs3org/reva/v2 v2.13.4-0.20230531122629-be4a2122a96c github.com/disintegration/imaging v1.6.2 github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e github.com/egirna/icap-client v0.1.1 diff --git a/go.sum b/go.sum index 03fc0831dc..037214eef2 100644 --- a/go.sum +++ b/go.sum @@ -631,6 +631,8 @@ github.com/crewjam/saml v0.4.13 h1:TYHggH/hwP7eArqiXSJUvtOPNzQDyQ7vwmwEqlFWhMc= github.com/crewjam/saml v0.4.13/go.mod h1:igEejV+fihTIlHXYP8zOec3V5A8y3lws5bQBFsTm4gA= github.com/cs3org/reva/v2 v2.13.4-0.20230531095732-bc9a3b635ec3 h1:T+W3zPmlPAaHlKhzBcW809PvcGUJJ+v1QF+JzdPRegU= github.com/cs3org/reva/v2 v2.13.4-0.20230531095732-bc9a3b635ec3/go.mod h1:vMQqSn30fEPHO/GKC2WmGimlOPqvfSy4gdhRSpbvrWc= +github.com/cs3org/reva/v2 v2.13.4-0.20230531122629-be4a2122a96c h1:gv0m1qVAkUtF/9PAP9xwp+jkjtajCAeGEhiO6dDOMcI= +github.com/cs3org/reva/v2 v2.13.4-0.20230531122629-be4a2122a96c/go.mod h1:vMQqSn30fEPHO/GKC2WmGimlOPqvfSy4gdhRSpbvrWc= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index 63f75decc2..d3d855bc40 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -155,16 +155,8 @@ Synchronization features like etag propagation, setting mtime and locking files File and sync features in a shared scenario -#### [ocs sharing api always returns an empty exact list while searching for a sharee](https://github.com/owncloud/ocis/issues/4265) +#### Contain the remotes list in response to getting sharees while searching -- [coreApiSharees/sharees.feature:100](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L100) -- [coreApiSharees/sharees.feature:101](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L101) -- [coreApiSharees/sharees.feature:120](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L120) -- [coreApiSharees/sharees.feature:121](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L121) -- [coreApiSharees/sharees.feature:140](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L140) -- [coreApiSharees/sharees.feature:141](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L141) -- [coreApiSharees/sharees.feature:160](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L160) -- [coreApiSharees/sharees.feature:161](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L161) - [coreApiSharees/sharees.feature:180](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L180) - [coreApiSharees/sharees.feature:181](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharees/sharees.feature#L181) diff --git a/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/conversions/main.go b/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/conversions/main.go index a0c1f6f18c..307ed0f399 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/conversions/main.go +++ b/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/conversions/main.go @@ -214,7 +214,7 @@ type MatchData struct { type MatchValueData struct { ShareType int `json:"shareType" xml:"shareType"` ShareWith string `json:"shareWith" xml:"shareWith"` - ShareWithAdditionalInfo string `json:"shareWithAdditionalInfo" xml:"shareWithAdditionalInfo"` + ShareWithAdditionalInfo string `json:"shareWithAdditionalInfo" xml:"shareWithAdditionalInfo,omitempty"` UserType int `json:"userType" xml:"userType"` } diff --git a/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go b/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go index 55fdc73cf8..cdb027c2c9 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go +++ b/vendor/github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go @@ -20,6 +20,7 @@ package sharees import ( "net/http" + "strings" grouppb "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1" userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" @@ -67,10 +68,15 @@ func (h *Handler) FindSharees(w http.ResponseWriter, r *http.Request) { log.Debug().Int("count", len(usersRes.GetUsers())).Str("search", term).Msg("users found") userMatches := make([]*conversions.MatchData, 0, len(usersRes.GetUsers())) + exactUserMatches := make([]*conversions.MatchData, 0) for _, user := range usersRes.GetUsers() { match := h.userAsMatch(user) log.Debug().Interface("user", user).Interface("match", match).Msg("mapped") - userMatches = append(userMatches, match) + 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}) @@ -81,16 +87,21 @@ func (h *Handler) FindSharees(w http.ResponseWriter, r *http.Request) { log.Debug().Int("count", len(groupsRes.GetGroups())).Str("search", term).Msg("groups found") groupMatches := make([]*conversions.MatchData, 0, len(groupsRes.GetGroups())) + exactGroupMatches := make([]*conversions.MatchData, 0) for _, g := range groupsRes.GetGroups() { match := h.groupAsMatch(g) log.Debug().Interface("group", g).Interface("match", match).Msg("mapped") - groupMatches = append(groupMatches, match) + if h.isExactMatch(match, term) { + exactGroupMatches = append(exactGroupMatches, match) + } else { + groupMatches = append(groupMatches, match) + } } response.WriteOCSSuccess(w, r, &conversions.ShareeData{ Exact: &conversions.ExactMatchesData{ - Users: []*conversions.MatchData{}, - Groups: []*conversions.MatchData{}, + Users: exactUserMatches, + Groups: exactGroupMatches, Remotes: []*conversions.MatchData{}, }, Users: userMatches, @@ -132,3 +143,11 @@ func (h *Handler) groupAsMatch(g *grouppb.Group) *conversions.MatchData { func (h *Handler) getAdditionalInfoAttribute(u *userpb.User) string { return templates.WithUser(u, h.additionalInfoAttribute) } + +func (h *Handler) isExactMatch(match *conversions.MatchData, term string) bool { + if match == nil || match.Value == nil { + return false + } + return strings.EqualFold(match.Value.ShareWith, term) || strings.EqualFold(match.Value.ShareWithAdditionalInfo, term) || + strings.EqualFold(match.Label, term) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index c435c0cbc1..6e11668714 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -352,7 +352,7 @@ github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1 github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1 github.com/cs3org/go-cs3apis/cs3/tx/v1beta1 github.com/cs3org/go-cs3apis/cs3/types/v1beta1 -# github.com/cs3org/reva/v2 v2.13.4-0.20230531095732-bc9a3b635ec3 +# github.com/cs3org/reva/v2 v2.13.4-0.20230531122629-be4a2122a96c ## explicit; go 1.19 github.com/cs3org/reva/v2/cmd/revad/internal/grace github.com/cs3org/reva/v2/cmd/revad/runtime