0
Fork 0
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:
wangsijie 2023-01-17 13:05:07 +08:00 committed by GitHub
parent aef690778d
commit 39bc1a82f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View file

@ -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 () => {

View file

@ -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),

View file

@ -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 () => {