diff --git a/packages/core/src/routes/organization/roles.ts b/packages/core/src/routes/organization/roles.ts index 48a85ad3b..5e24e461d 100644 --- a/packages/core/src/routes/organization/roles.ts +++ b/packages/core/src/routes/organization/roles.ts @@ -35,7 +35,7 @@ export default function organizationRoleRoutes( ) { 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( } ); + 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 & { organizationScopeIds: string[]; diff --git a/packages/integration-tests/src/tests/api/organization/organization-role.test.ts b/packages/integration-tests/src/tests/api/organization/organization-role.test.ts index 2ff9abf53..848e137ff 100644 --- a/packages/integration-tests/src/tests/api/organization/organization-role.test.ts +++ b/packages/integration-tests/src/tests/api/organization/organization-role.test.ts @@ -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 () => {