feat: RBAC (#8922)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
Co-authored-by: Val <68596159+valya@users.noreply.github.com>
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
Co-authored-by: Valya Bullions <valya@n8n.io>
Co-authored-by: Danny Martini <danny@n8n.io>
Co-authored-by: Danny Martini <despair.blue@gmail.com>
Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
Co-authored-by: Omar Ajoue <krynble@gmail.com>
Co-authored-by: oleg <me@olegivaniv.com>
Co-authored-by: Michael Kret <michael.k@radency.com>
Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com>
Co-authored-by: Elias Meire <elias@meire.dev>
Co-authored-by: Giulio Andreini <andreini@netseven.it>
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
Co-authored-by: Ayato Hayashi <go12limchangyong@gmail.com>
This commit is contained in:
Csaba Tuncsik
2024-05-17 10:53:15 +02:00
committed by GitHub
parent b1f977ebd0
commit 596c472ecc
292 changed files with 14129 additions and 3989 deletions

View File

@@ -21,16 +21,20 @@ import {
} from './shared/db/workflows';
import type { User } from '@db/entities/User';
import type { Project } from '@/databases/entities/Project';
import { getPersonalProject } from './shared/db/projects';
describe('ImportService', () => {
let importService: ImportService;
let tagRepository: TagRepository;
let owner: User;
let ownerPersonalProject: Project;
beforeAll(async () => {
await testDb.init();
owner = await createOwner();
ownerPersonalProject = await getPersonalProject(owner);
tagRepository = Container.get(TagRepository);
@@ -52,7 +56,7 @@ describe('ImportService', () => {
test('should import credless and tagless workflow', async () => {
const workflowToImport = await createWorkflow();
await importService.importWorkflows([workflowToImport], owner.id);
await importService.importWorkflows([workflowToImport], ownerPersonalProject.id);
const dbWorkflow = await getWorkflowById(workflowToImport.id);
@@ -64,27 +68,32 @@ describe('ImportService', () => {
test('should make user owner of imported workflow', async () => {
const workflowToImport = newWorkflow();
await importService.importWorkflows([workflowToImport], owner.id);
await importService.importWorkflows([workflowToImport], ownerPersonalProject.id);
const dbSharing = await Container.get(SharedWorkflowRepository).findOneOrFail({
where: { workflowId: workflowToImport.id, userId: owner.id, role: 'workflow:owner' },
where: {
workflowId: workflowToImport.id,
projectId: ownerPersonalProject.id,
role: 'workflow:owner',
},
});
expect(dbSharing.userId).toBe(owner.id);
expect(dbSharing.projectId).toBe(ownerPersonalProject.id);
});
test('should not change the owner if it already exists', async () => {
const member = await createMember();
const memberPersonalProject = await getPersonalProject(member);
const workflowToImport = await createWorkflow(undefined, owner);
await importService.importWorkflows([workflowToImport], member.id);
await importService.importWorkflows([workflowToImport], memberPersonalProject.id);
const sharings = await getAllSharedWorkflows();
expect(sharings).toMatchObject([
expect.objectContaining({
workflowId: workflowToImport.id,
userId: owner.id,
projectId: ownerPersonalProject.id,
role: 'workflow:owner',
}),
]);
@@ -93,7 +102,7 @@ describe('ImportService', () => {
test('should deactivate imported workflow if active', async () => {
const workflowToImport = await createWorkflow({ active: true });
await importService.importWorkflows([workflowToImport], owner.id);
await importService.importWorkflows([workflowToImport], ownerPersonalProject.id);
const dbWorkflow = await getWorkflowById(workflowToImport.id);
@@ -121,7 +130,7 @@ describe('ImportService', () => {
const workflowToImport = await createWorkflow({ nodes });
await importService.importWorkflows([workflowToImport], owner.id);
await importService.importWorkflows([workflowToImport], ownerPersonalProject.id);
const dbWorkflow = await getWorkflowById(workflowToImport.id);
@@ -141,7 +150,7 @@ describe('ImportService', () => {
const workflowToImport = await createWorkflow({ tags: [tag] });
await importService.importWorkflows([workflowToImport], owner.id);
await importService.importWorkflows([workflowToImport], ownerPersonalProject.id);
const dbWorkflow = await Container.get(WorkflowRepository).findOneOrFail({
where: { id: workflowToImport.id },
@@ -162,7 +171,7 @@ describe('ImportService', () => {
const workflowToImport = await createWorkflow({ tags: [tag] });
await importService.importWorkflows([workflowToImport], owner.id);
await importService.importWorkflows([workflowToImport], ownerPersonalProject.id);
const dbWorkflow = await Container.get(WorkflowRepository).findOneOrFail({
where: { id: workflowToImport.id },
@@ -181,7 +190,7 @@ describe('ImportService', () => {
const workflowToImport = await createWorkflow({ tags: [tag] });
await importService.importWorkflows([workflowToImport], owner.id);
await importService.importWorkflows([workflowToImport], ownerPersonalProject.id);
const dbWorkflow = await Container.get(WorkflowRepository).findOneOrFail({
where: { id: workflowToImport.id },