0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(core): add scopes and resource scopes to org role detail api

This commit is contained in:
wangsijie 2024-04-09 15:23:39 +08:00
parent 9482a9c901
commit fb4ac3b476
No known key found for this signature in database
GPG key ID: C72642FE24F7D42B
2 changed files with 29 additions and 4 deletions

View file

@ -35,7 +35,7 @@ export default function organizationRoleRoutes<T extends AuthedRouter>(
) {
const router = new SchemaRouter(OrganizationRoles, roles, {
middlewares: [koaQuotaGuard({ key: 'organizationsEnabled', quota, methods: ['POST', 'PUT'] })],
disabled: { get: true, post: true },
disabled: { get: true, post: true, getById: EnvSet.values.isDevFeaturesEnabled },
errorHandler,
searchFields: ['name'],
});
@ -64,6 +64,21 @@ export default function organizationRoleRoutes<T extends AuthedRouter>(
}
);
if (EnvSet.values.isDevFeaturesEnabled) {
router.get(
'/:id',
koaGuard({
params: z.object({ id: z.string() }),
response: organizationRoleWithScopesGuard,
status: [200],
}),
async (ctx, next) => {
ctx.body = await roles.findById(ctx.guard.params.id);
return next();
}
);
}
/** Allows to carry an initial set of scopes for creating a new organization role. */
type CreateOrganizationRolePayload = Omit<CreateOrganizationRole, 'id'> & {
organizationScopeIds: string[];

View file

@ -40,6 +40,13 @@ describe('organization role APIs', () => {
expect(isKeyInObject(body, 'code') && body.code).toBe('entity.unique_integrity_violation');
});
it('should get organization role by id successfully', async () => {
const createdRole = await roleApi.create({ name: 'test' + randomId() });
const role = await roleApi.get(createdRole.id);
expect(role).toHaveProperty('name', createdRole.name);
});
it('should get organization roles successfully', async () => {
const [name1, name2] = ['test' + randomId(), 'test' + randomId()];
await Promise.all([
@ -86,11 +93,14 @@ describe('organization role APIs', () => {
expect(roles[0]).toHaveProperty('name', name1);
});
it('should be able to create and get organization roles by id', async () => {
it('should be able to create and get organization role by id', async () => {
const createdRole = await roleApi.create({ name: 'test' + randomId() });
const { scopes, ...role } = await roleApi.get(createdRole.id);
const role = await roleApi.get(createdRole.id);
expect(role).toStrictEqual(createdRole);
expect(role).toMatchObject({
...createdRole,
resourceScopes: [],
});
});
it('should be able to create a new organization with initial organization scopes and resource scopes', async () => {