mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -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]);
|
findScopesByIds.mockResolvedValueOnce([mockScope]);
|
||||||
const response = await roleRequester.get(`/roles/${mockRole.id}/scopes`);
|
const response = await roleRequester.get(`/roles/${mockRole.id}/scopes`);
|
||||||
expect(response.status).toEqual(200);
|
expect(response.status).toEqual(200);
|
||||||
expect(response.body).toEqual([
|
expect(response.body).toEqual([mockScope]);
|
||||||
{
|
|
||||||
...mockScope,
|
|
||||||
resource: mockResource,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('POST /roles/:id/scopes', async () => {
|
it('POST /roles/:id/scopes', async () => {
|
||||||
|
|
|
@ -22,7 +22,7 @@ export default function roleScopeRoutes<T extends AuthedRouter>(
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/roles/:id/scopes',
|
'/roles/:id/scopes',
|
||||||
koaPagination(),
|
koaPagination({ isOptional: true }),
|
||||||
koaGuard({
|
koaGuard({
|
||||||
params: object({ id: string().min(1) }),
|
params: object({ id: string().min(1) }),
|
||||||
}),
|
}),
|
||||||
|
@ -30,7 +30,7 @@ export default function roleScopeRoutes<T extends AuthedRouter>(
|
||||||
const {
|
const {
|
||||||
params: { id },
|
params: { id },
|
||||||
} = ctx.guard;
|
} = ctx.guard;
|
||||||
const { limit, offset } = ctx.pagination;
|
const { limit, offset, disabled } = ctx.pagination;
|
||||||
const { searchParams } = ctx.request.URL;
|
const { searchParams } = ctx.request.URL;
|
||||||
await findRoleById(id);
|
await findRoleById(id);
|
||||||
|
|
||||||
|
@ -41,6 +41,12 @@ export default function roleScopeRoutes<T extends AuthedRouter>(
|
||||||
const rolesScopes = await findRolesScopesByRoleId(id);
|
const rolesScopes = await findRolesScopesByRoleId(id);
|
||||||
const scopeIds = rolesScopes.map(({ scopeId }) => scopeId);
|
const scopeIds = rolesScopes.map(({ scopeId }) => scopeId);
|
||||||
|
|
||||||
|
if (disabled) {
|
||||||
|
ctx.body = await searchScopesByScopeIds(scopeIds, search);
|
||||||
|
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
const [{ count }, scopes] = await Promise.all([
|
const [{ count }, scopes] = await Promise.all([
|
||||||
countScopesByScopeIds(scopeIds, search),
|
countScopesByScopeIds(scopeIds, search),
|
||||||
searchScopesByScopeIds(scopeIds, search, limit, offset),
|
searchScopesByScopeIds(scopeIds, search, limit, offset),
|
||||||
|
|
|
@ -17,7 +17,6 @@ describe('roles scopes', () => {
|
||||||
|
|
||||||
expect(scopes.length).toBe(1);
|
expect(scopes.length).toBe(1);
|
||||||
expect(scopes[0]).toHaveProperty('id', scope.id);
|
expect(scopes[0]).toHaveProperty('id', scope.id);
|
||||||
expect(scopes[0]).toHaveProperty('resource.id', resource.id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should assign scopes to role successfully', async () => {
|
it('should assign scopes to role successfully', async () => {
|
||||||
|
|
Loading…
Reference in a new issue