mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): get all scopes for a role (#2967)
This commit is contained in:
parent
aef690778d
commit
39bc1a82f1
3 changed files with 9 additions and 9 deletions
|
@ -65,12 +65,7 @@ describe('role scope routes', () => {
|
|||
findScopesByIds.mockResolvedValueOnce([mockScope]);
|
||||
const response = await roleRequester.get(`/roles/${mockRole.id}/scopes`);
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual([
|
||||
{
|
||||
...mockScope,
|
||||
resource: mockResource,
|
||||
},
|
||||
]);
|
||||
expect(response.body).toEqual([mockScope]);
|
||||
});
|
||||
|
||||
it('POST /roles/:id/scopes', async () => {
|
||||
|
|
|
@ -22,7 +22,7 @@ export default function roleScopeRoutes<T extends AuthedRouter>(
|
|||
|
||||
router.get(
|
||||
'/roles/:id/scopes',
|
||||
koaPagination(),
|
||||
koaPagination({ isOptional: true }),
|
||||
koaGuard({
|
||||
params: object({ id: string().min(1) }),
|
||||
}),
|
||||
|
@ -30,7 +30,7 @@ export default function roleScopeRoutes<T extends AuthedRouter>(
|
|||
const {
|
||||
params: { id },
|
||||
} = ctx.guard;
|
||||
const { limit, offset } = ctx.pagination;
|
||||
const { limit, offset, disabled } = ctx.pagination;
|
||||
const { searchParams } = ctx.request.URL;
|
||||
await findRoleById(id);
|
||||
|
||||
|
@ -41,6 +41,12 @@ export default function roleScopeRoutes<T extends AuthedRouter>(
|
|||
const rolesScopes = await findRolesScopesByRoleId(id);
|
||||
const scopeIds = rolesScopes.map(({ scopeId }) => scopeId);
|
||||
|
||||
if (disabled) {
|
||||
ctx.body = await searchScopesByScopeIds(scopeIds, search);
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
const [{ count }, scopes] = await Promise.all([
|
||||
countScopesByScopeIds(scopeIds, search),
|
||||
searchScopesByScopeIds(scopeIds, search, limit, offset),
|
||||
|
|
|
@ -17,7 +17,6 @@ describe('roles scopes', () => {
|
|||
|
||||
expect(scopes.length).toBe(1);
|
||||
expect(scopes[0]).toHaveProperty('id', scope.id);
|
||||
expect(scopes[0]).toHaveProperty('resource.id', resource.id);
|
||||
});
|
||||
|
||||
it('should assign scopes to role successfully', async () => {
|
||||
|
|
Loading…
Reference in a new issue