SearchProjectUsers returns a list of users that match the given search/email query.
(ctx context.Context, req *adminv1.SearchProjectUsersRequest)
| 585 | |
| 586 | // SearchProjectUsers returns a list of users that match the given search/email query. |
| 587 | func (s *Server) SearchProjectUsers(ctx context.Context, req *adminv1.SearchProjectUsersRequest) (*adminv1.SearchProjectUsersResponse, error) { |
| 588 | observability.AddRequestAttributes(ctx, |
| 589 | attribute.String("args.org", req.Org), |
| 590 | attribute.String("args.project", req.Project), |
| 591 | attribute.String("args.email_query", req.EmailQuery), |
| 592 | ) |
| 593 | |
| 594 | proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project) |
| 595 | if err != nil { |
| 596 | return nil, err |
| 597 | } |
| 598 | |
| 599 | claims := auth.GetClaims(ctx) |
| 600 | if !claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID).ManageProject { |
| 601 | return nil, status.Error(codes.PermissionDenied, "not authorized to search project users") |
| 602 | } |
| 603 | |
| 604 | token, err := unmarshalPageToken(req.PageToken) |
| 605 | if err != nil { |
| 606 | return nil, err |
| 607 | } |
| 608 | |
| 609 | pageSize := validPageSize(req.PageSize) |
| 610 | |
| 611 | users, err := s.admin.DB.SearchProjectUsers(ctx, proj.ID, req.EmailQuery, token.Val, pageSize) |
| 612 | if err != nil { |
| 613 | return nil, err |
| 614 | } |
| 615 | |
| 616 | nextToken := "" |
| 617 | if len(users) >= pageSize { |
| 618 | nextToken = marshalPageToken(users[len(users)-1].Email) |
| 619 | } |
| 620 | |
| 621 | dtos := make([]*adminv1.User, len(users)) |
| 622 | for i, user := range users { |
| 623 | dtos[i] = s.userToPB(user, false) |
| 624 | } |
| 625 | |
| 626 | return &adminv1.SearchProjectUsersResponse{ |
| 627 | Users: dtos, |
| 628 | NextPageToken: nextToken, |
| 629 | }, nil |
| 630 | } |
| 631 | |
| 632 | func (s *Server) userToPB(u *database.User, isCurrentUser bool) *adminv1.User { |
| 633 | // Compute a HMAC-SHA256 hash of the email if Pylon identity verification is configured. |
nothing calls this directly
no test coverage detected