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

This commit is contained in:
Andreas Fitzek
2025-08-25 14:29:28 +02:00
committed by GitHub
parent b62c957c71
commit a21a03d4b0
117 changed files with 410 additions and 875 deletions

View File

@@ -1,14 +1,12 @@
import type { SourceControlledFile } from '@n8n/api-types';
import {
type Variables,
type FolderWithWorkflowAndSubFolderCount,
type TagEntity,
type User,
type FolderRepository,
type TagRepository,
type WorkflowEntity,
GLOBAL_MEMBER_ROLE,
GLOBAL_ADMIN_ROLE,
import type {
Variables,
FolderWithWorkflowAndSubFolderCount,
TagEntity,
User,
FolderRepository,
TagRepository,
WorkflowEntity,
} from '@n8n/db';
import { Container } from '@n8n/di';
import { mock } from 'jest-mock-extended';
@@ -151,9 +149,8 @@ describe('SourceControlService', () => {
describe('getStatus', () => {
it('ensure updatedAt field for last deleted tag', async () => {
// ARRANGE
const user = mock<User>({
role: GLOBAL_ADMIN_ROLE,
});
const user = mock<User>();
user.role = 'global:admin';
sourceControlImportService.getRemoteVersionIdsFromFiles.mockResolvedValue([]);
sourceControlImportService.getLocalVersionIdsFromDb.mockResolvedValue([]);
@@ -207,9 +204,8 @@ describe('SourceControlService', () => {
it('ensure updatedAt field for last deleted folder', async () => {
// ARRANGE
const user = mock<User>({
role: GLOBAL_ADMIN_ROLE,
});
const user = mock<User>();
user.role = 'global:admin';
sourceControlImportService.getRemoteVersionIdsFromFiles.mockResolvedValue([]);
sourceControlImportService.getLocalVersionIdsFromDb.mockResolvedValue([]);
@@ -266,9 +262,8 @@ describe('SourceControlService', () => {
it('conflict depends on the value of `direction`', async () => {
// ARRANGE
const user = mock<User>({
role: GLOBAL_ADMIN_ROLE,
});
const user = mock<User>();
user.role = 'global:admin';
// Define a credential that does only exist locally.
// Pulling this would delete it so it should be marked as a conflict.
@@ -373,9 +368,8 @@ describe('SourceControlService', () => {
it('should throw `ForbiddenError` if direction is pull and user is not allowed to globally pull', async () => {
// ARRANGE
const user = mock<User>({
role: GLOBAL_MEMBER_ROLE,
});
const user = mock<User>();
user.role = 'global:member';
// ACT
await expect(
@@ -393,7 +387,7 @@ describe('SourceControlService', () => {
'should return file content for $type',
async ({ type, id, content }) => {
jest.spyOn(gitService, 'getFileContent').mockResolvedValue(content);
const user = mock<User>({ id: 'user-id', role: GLOBAL_ADMIN_ROLE });
const user = mock<User>({ id: 'user-id', role: 'global:admin' });
const result = await sourceControlService.getRemoteFileEntity({ user, type, id });
@@ -404,7 +398,7 @@ describe('SourceControlService', () => {
it.each<SourceControlledFile['type']>(['folders', 'credential', 'tags', 'variables'])(
'should throw an error if the file type is not handled',
async (type) => {
const user = mock<User>({ id: 'user-id', role: { slug: 'global:admin' } });
const user = mock<User>({ id: 'user-id', role: 'global:admin' });
await expect(
sourceControlService.getRemoteFileEntity({ user, type, id: 'unknown' }),
).rejects.toThrow(`Unsupported file type: ${type}`);
@@ -413,7 +407,7 @@ describe('SourceControlService', () => {
it('should fail if the git service fails to get the file content', async () => {
jest.spyOn(gitService, 'getFileContent').mockRejectedValue(new Error('Git service error'));
const user = mock<User>({ id: 'user-id', role: { slug: 'global:admin' } });
const user = mock<User>({ id: 'user-id', role: 'global:admin' });
await expect(
sourceControlService.getRemoteFileEntity({ user, type: 'workflow', id: '1234' }),
@@ -423,7 +417,7 @@ describe('SourceControlService', () => {
it('should throw an error if the user does not have access to the project', async () => {
const user = mock<User>({
id: 'user-id',
role: { slug: 'global:member' },
role: 'global:member',
});
jest
.spyOn(sourceControlScopedService, 'getWorkflowsInAdminProjectsFromContext')
@@ -435,7 +429,7 @@ describe('SourceControlService', () => {
});
it('should return content for an authorized workflow', async () => {
const user = mock<User>({ id: 'user-id', role: { slug: 'global:member' } });
const user = mock<User>({ id: 'user-id', role: 'global:member' });
jest
.spyOn(sourceControlScopedService, 'getWorkflowsInAdminProjectsFromContext')
.mockResolvedValue([{ id: '1234' } as WorkflowEntity]);