Skip to content

Commit

Permalink
Fix the empty exact list while searching for a sharee #4265
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed May 11, 2023
1 parent 562ede3 commit 27df93d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-empty-exact-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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/cs3org/reva/pull/3877
https://github.com/owncloud/ocis/issues/4265
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 strings.EqualFold(match.Value.ShareWith, term) {
exactUserMatches = append(exactUserMatches, match)
} else {
userMatches = append(userMatches, match)
}
}

groupsRes, err := gwc.FindGroups(r.Context(), &grouppb.FindGroupsRequest{Filter: term, SkipFetchingMembers: true})
Expand All @@ -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 strings.EqualFold(match.Value.ShareWith, 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,
Expand Down

0 comments on commit 27df93d

Please sign in to comment.