chore(core): Use roles from database in global roles (#17853)

This commit is contained in:
Andreas Fitzek
2025-08-22 16:02:01 +02:00
committed by GitHub
parent 350f84c49f
commit a8e4387f4d
117 changed files with 875 additions and 410 deletions

View File

@@ -2,7 +2,7 @@ import type { ApiKeyWithRawValue } from '@n8n/api-types';
import { testDb, randomValidPassword, mockInstance } from '@n8n/backend-test-utils';
import { GlobalConfig } from '@n8n/config';
import type { User } from '@n8n/db';
import { ApiKeyRepository } from '@n8n/db';
import { ApiKeyRepository, GLOBAL_MEMBER_ROLE, GLOBAL_OWNER_ROLE } from '@n8n/db';
import { Container } from '@n8n/di';
import {
getApiKeyScopesForRole,
@@ -59,7 +59,7 @@ describe('Owner shell', () => {
let ownerShell: User;
beforeEach(async () => {
ownerShell = await createUserShell('global:owner');
ownerShell = await createUserShell(GLOBAL_OWNER_ROLE);
});
test('POST /api-keys should create an api key with no expiration', async () => {
@@ -304,9 +304,9 @@ describe('Owner shell', () => {
const scopes = apiKeyScopesResponse.body.data as ApiKeyScope[];
const scopesForRole = getApiKeyScopesForRole(ownerShell.role);
const scopesForRole = getApiKeyScopesForRole(ownerShell);
expect(scopes).toEqual(scopesForRole);
expect(scopes.sort()).toEqual(scopesForRole.sort());
});
});
@@ -317,7 +317,7 @@ describe('Member', () => {
beforeEach(async () => {
member = await createUser({
password: memberPassword,
role: 'global:member',
role: GLOBAL_MEMBER_ROLE,
});
await utils.setInstanceOwnerSetUp(true);
});
@@ -328,6 +328,7 @@ describe('Member', () => {
.post('/api-keys')
.send({ label: 'My API Key', expiresAt: null, scopes: ['workflow:create'] });
console.log(newApiKeyResponse.body);
expect(newApiKeyResponse.statusCode).toBe(200);
expect(newApiKeyResponse.body.data.apiKey).toBeDefined();
expect(newApiKeyResponse.body.data.apiKey).not.toBeNull();
@@ -492,8 +493,8 @@ describe('Member', () => {
const scopes = apiKeyScopesResponse.body.data as ApiKeyScope[];
const scopesForRole = getApiKeyScopesForRole(member.role);
const scopesForRole = getApiKeyScopesForRole(member);
expect(scopes).toEqual(scopesForRole);
expect(scopes.sort()).toEqual(scopesForRole.sort());
});
});