Fix the empty exact list while searching for a sharee #issue-4265

This commit is contained in:
Roman Perekhod
2023-05-31 14:41:31 +02:00
parent aff8a7dfb5
commit 366d1c2c10
7 changed files with 36 additions and 16 deletions

View File

@@ -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

2
go.mod
View File

@@ -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

2
go.sum
View File

@@ -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=

View File

@@ -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)

View File

@@ -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"`
}

View File

@@ -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)
}

2
vendor/modules.txt vendored
View File

@@ -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