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

feat: list roles while listing members of org #394

Merged
merged 1 commit into from
Oct 19, 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
VERSION := $(shell git describe --tags ${TAG})
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto ui
.DEFAULT_GOAL := build
PROTON_COMMIT := "958e1444b33991a6b6c961cf85ab959c3612c71a"
PROTON_COMMIT := "a643dfe2bec324941bab05cec4061324a0f6b643"

ui:
@echo " > generating ui build"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ docker pull raystack/frontier:latest
To pull a specific version:

```
docker pull raystack/frontier:0.7.6
docker pull raystack/frontier:0.7.17
```

## Usage
Expand Down
34 changes: 33 additions & 1 deletion internal/api/v1beta1/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package v1beta1
import (
"context"

"github.com/raystack/frontier/core/role"
"go.uber.org/zap"

"github.com/raystack/frontier/core/audit"
"github.com/raystack/frontier/pkg/utils"

Expand Down Expand Up @@ -290,7 +293,36 @@ func (h Handler) ListOrganizationUsers(ctx context.Context, request *frontierv1b
usersPB = append(usersPB, u)
}

return &frontierv1beta1.ListOrganizationUsersResponse{Users: usersPB}, nil
var rolePairPBs []*frontierv1beta1.ListOrganizationUsersResponse_RolePair
if request.GetWithRoles() {
for _, user := range users {
roles, err := h.policyService.ListForUser(ctx, user.ID, schema.OrganizationNamespace, request.GetId())
if err != nil {
logger.Error(err.Error())
return nil, grpcInternalServerError
}

rolesPb := utils.Filter(utils.Map(roles, func(role role.Role) *frontierv1beta1.Role {
pb, err := transformRoleToPB(role)
if err != nil {
logger.Error("failed to transform role for group", zap.Error(err))
return nil
}
return &pb
}), func(role *frontierv1beta1.Role) bool {
return role != nil
})
rolePairPBs = append(rolePairPBs, &frontierv1beta1.ListOrganizationUsersResponse_RolePair{
UserId: user.ID,
Roles: rolesPb,
})
}
}

return &frontierv1beta1.ListOrganizationUsersResponse{
Users: usersPB,
RolePairs: rolePairPBs,
}, nil
}

func (h Handler) ListOrganizationServiceUsers(ctx context.Context, request *frontierv1beta1.ListOrganizationServiceUsersRequest) (*frontierv1beta1.ListOrganizationServiceUsersResponse, error) {
Expand Down
19 changes: 19 additions & 0 deletions proto/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,10 @@ paths:
in: query
required: false
type: string
- name: withRoles
in: query
required: false
type: boolean
tags:
- Organization
post:
Expand Down Expand Up @@ -7251,6 +7255,21 @@ definitions:
items:
type: object
$ref: '#/definitions/v1beta1User'
rolePairs:
type: array
items:
type: object
$ref: '#/definitions/v1beta1ListOrganizationUsersResponseRolePair'
v1beta1ListOrganizationUsersResponseRolePair:
type: object
properties:
userId:
type: string
roles:
type: array
items:
type: object
$ref: '#/definitions/v1beta1Role'
v1beta1ListOrganizationsByCurrentUserResponse:
type: object
properties:
Expand Down
Loading
Loading