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

Search OCM accepted users #3666

Merged
merged 2 commits into from
Feb 21, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/ocm-find-accepted-users-filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Search OCM accepted users

Adds the prefix `sm:` to the FindUser endpoint,
to filter only the OCM accepted users.

https://github.com/cs3org/reva/pull/3666
32 changes: 32 additions & 0 deletions internal/grpc/services/gateway/userprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ package gateway

import (
"context"
"strings"

user "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/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/pkg/errors"
Expand Down Expand Up @@ -60,6 +63,35 @@ func (s *svc) GetUserByClaim(ctx context.Context, req *user.GetUserByClaimReques
}

func (s *svc) FindUsers(ctx context.Context, req *user.FindUsersRequest) (*user.FindUsersResponse, error) {
if strings.HasPrefix(req.Filter, "sm:") {
c, err := pool.GetOCMInviteManagerClient(pool.Endpoint(s.c.OCMInviteManagerEndpoint))
if err != nil {
return &user.FindUsersResponse{
Status: status.NewInternal(ctx, err, "error getting auth client"),
}, nil
}

term := strings.TrimPrefix(req.Filter, "sm:")

res, err := c.FindAcceptedUsers(ctx, &invitepb.FindAcceptedUsersRequest{
Filter: term,
})
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling FindAcceptedUsers")
}

if res.Status.Code != rpc.Code_CODE_OK {
return &user.FindUsersResponse{
Status: status.NewInternal(ctx, errors.New(res.Status.Message), res.Status.Message),
}, nil
}

return &user.FindUsersResponse{
Status: status.NewOK(ctx),
Users: res.AcceptedUsers,
}, nil
}

c, err := pool.GetUserProviderServiceClient(pool.Endpoint(s.c.UserProviderEndpoint))
if err != nil {
return &user.FindUsersResponse{
Expand Down