Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "a" and "l" filters in grappa #1887

Merged
merged 3 commits into from Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog/unreleased/filter-ns-users-groups.md
@@ -0,0 +1,10 @@
Enhancement: Add "a" and "l" filter for grappa queries

This PR adds the namespace filters "a" and "l" for grappa queries.
With no filter will look into primary and e-groups, with "a" will look
into primary/secondary/service/e-groups and with "l" will look into
lightweight accounts.


https://github.com/cs3org/reva/pull/1887
https://github.com/cs3org/reva/issues/1773
15 changes: 15 additions & 0 deletions pkg/cbox/group/rest/rest.go
Expand Up @@ -282,6 +282,21 @@ func (m *manager) findGroupsByFilter(ctx context.Context, url string, groups map
}

func (m *manager) FindGroups(ctx context.Context, query string) ([]*grouppb.Group, error) {

// Look at namespaces filters. If the query starts with:
// "a" or none => get egroups
// other filters => get empty list

parts := strings.SplitN(query, ":", 2)

if len(parts) == 2 {
if parts[0] == "a" {
query = parts[1]
} else {
return []*grouppb.Group{}, nil
}
}

filters := []string{"groupIdentifier"}
if emailRegex.MatchString(query) {
parts := strings.Split(query, "@")
Expand Down
40 changes: 38 additions & 2 deletions pkg/cbox/user/rest/rest.go
Expand Up @@ -304,6 +304,19 @@ func (m *manager) findUsersByFilter(ctx context.Context, url string, users map[s

func (m *manager) FindUsers(ctx context.Context, query string) ([]*userpb.User, error) {

// Look at namespaces filters. If the query starts with:
// "a" => look into primary/secondary/service accounts
// "l" => look into lightweight accounts
// none => look into primary

parts := strings.SplitN(query, ":", 2)

var namespace string
if len(parts) == 2 {
// the query contains a namespace filter
namespace, query = parts[0], parts[1]
}

var filters []string
switch {
case usernameRegex.MatchString(query):
Expand All @@ -326,13 +339,36 @@ func (m *manager) FindUsers(ctx context.Context, query string) ([]*userpb.User,
}

userSlice := []*userpb.User{}
for _, v := range users {
userSlice = append(userSlice, v)

var accountsFilters []userpb.UserType
switch namespace {
case "":
accountsFilters = []userpb.UserType{userpb.UserType_USER_TYPE_PRIMARY}
case "a":
accountsFilters = []userpb.UserType{userpb.UserType_USER_TYPE_PRIMARY, userpb.UserType_USER_TYPE_SECONDARY, userpb.UserType_USER_TYPE_SERVICE}
case "l":
accountsFilters = []userpb.UserType{userpb.UserType_USER_TYPE_LIGHTWEIGHT}
}

for _, u := range users {
if isUserAnyType(u, accountsFilters) {
userSlice = append(userSlice, u)
}
}

return userSlice, nil
}

// isUserAnyType returns true if the user's type is one of types list
func isUserAnyType(user *userpb.User, types []userpb.UserType) bool {
for _, t := range types {
if user.GetId().Type == t {
return true
}
}
return false
}

func (m *manager) GetUserGroups(ctx context.Context, uid *userpb.UserId) ([]string, error) {

groups, err := m.fetchCachedUserGroups(uid)
Expand Down