diff --git a/src/lib/db/access-store.ts b/src/lib/db/access-store.ts index 1c6f9202d5..6bf9194257 100644 --- a/src/lib/db/access-store.ts +++ b/src/lib/db/access-store.ts @@ -918,7 +918,9 @@ export class AccessStore implements IAccessStore { SELECT r.name FROM role_user ru INNER JOIN roles r on ru.role_id = r.id - WHERE ru.user_id = u.id and r.type='root' + WHERE ru.user_id = u.id and r.type IN (${ROOT_ROLE_TYPES.map( + (type) => `'${type}'`, + ).join(',')}) ) r, LATERAL ( SELECT ARRAY ( SELECT g.name FROM group_user gu diff --git a/src/test/e2e/services/access-service.e2e.test.ts b/src/test/e2e/services/access-service.e2e.test.ts index a992f8dc9f..06b7e99658 100644 --- a/src/test/e2e/services/access-service.e2e.test.ts +++ b/src/test/e2e/services/access-service.e2e.test.ts @@ -17,7 +17,10 @@ import { } from '../../../lib/types'; import { createTestConfig } from '../../config/test-config'; import { DEFAULT_PROJECT } from '../../../lib/types/project'; -import { ALL_PROJECTS } from '../../../lib/util/constants'; +import { + ALL_PROJECTS, + CUSTOM_ROOT_ROLE_TYPE, +} from '../../../lib/util/constants'; import { createAccessService, createFeatureToggleService, @@ -1848,3 +1851,33 @@ test('access overview should have group access for groups that they are in', asy expect(userAccess.groupProjects).toStrictEqual(['default']); }); + +test('access overview should include users with custom root roles', async () => { + const email = 'ratatoskr@yggdrasil.com'; + + const customRole = await accessService.createRole({ + name: 'Mischievous Messenger', + type: CUSTOM_ROOT_ROLE_TYPE, + description: + 'A squirrel that runs up and down the world tree, carrying messages.', + permissions: [{ name: permissions.CREATE_ADDON }], + createdByUserId: 1, + }); + + const { userStore } = stores; + const user = await userStore.insert({ + name: 'Ratatoskr', + email, + }); + + await accessService.setUserRootRole(user.id, customRole.id); + + const accessOverView: IUserAccessOverview[] = + await accessService.getUserAccessOverview(); + const userAccess = accessOverView.find( + (overviewRow) => overviewRow.userId === user.id, + )!; + + expect(userAccess.userId).toBe(user.id); + expect(userAccess.rootRole).toBe('Mischievous Messenger'); +});