fix(core): Consolidate ownership and sharing data on workflows and credentials (#7920)
## Summary Ensure `ownedBy` and `sharedWith` are present and uniform for credentials and workflows. Details in story: https://linear.app/n8n/issue/PAY-987
This commit is contained in:
@@ -211,7 +211,13 @@ describe('GET /workflows', () => {
|
||||
updatedAt: any(String),
|
||||
tags: [{ id: any(String), name: 'A' }],
|
||||
versionId: any(String),
|
||||
ownedBy: { id: owner.id },
|
||||
ownedBy: {
|
||||
id: owner.id,
|
||||
email: any(String),
|
||||
firstName: any(String),
|
||||
lastName: any(String),
|
||||
},
|
||||
sharedWith: [],
|
||||
}),
|
||||
objectContaining({
|
||||
id: any(String),
|
||||
@@ -221,7 +227,13 @@ describe('GET /workflows', () => {
|
||||
updatedAt: any(String),
|
||||
tags: [],
|
||||
versionId: any(String),
|
||||
ownedBy: { id: owner.id },
|
||||
ownedBy: {
|
||||
id: owner.id,
|
||||
email: any(String),
|
||||
firstName: any(String),
|
||||
lastName: any(String),
|
||||
},
|
||||
sharedWith: [],
|
||||
}),
|
||||
]),
|
||||
});
|
||||
@@ -231,7 +243,7 @@ describe('GET /workflows', () => {
|
||||
);
|
||||
|
||||
expect(found.nodes).toBeUndefined();
|
||||
expect(found.sharedWith).toBeUndefined();
|
||||
expect(found.sharedWith).toHaveLength(0);
|
||||
expect(found.usedCredentials).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -412,8 +424,26 @@ describe('GET /workflows', () => {
|
||||
expect(response.body).toEqual({
|
||||
count: 2,
|
||||
data: arrayContaining([
|
||||
{ id: any(String), ownedBy: { id: owner.id } },
|
||||
{ id: any(String), ownedBy: { id: owner.id } },
|
||||
{
|
||||
id: any(String),
|
||||
ownedBy: {
|
||||
id: owner.id,
|
||||
email: any(String),
|
||||
firstName: any(String),
|
||||
lastName: any(String),
|
||||
},
|
||||
sharedWith: [],
|
||||
},
|
||||
{
|
||||
id: any(String),
|
||||
ownedBy: {
|
||||
id: owner.id,
|
||||
email: any(String),
|
||||
firstName: any(String),
|
||||
lastName: any(String),
|
||||
},
|
||||
sharedWith: [],
|
||||
},
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
randomInteger,
|
||||
randomName,
|
||||
} from '../../integration/shared/random';
|
||||
import { WorkflowEntity } from '@/databases/entities/WorkflowEntity';
|
||||
|
||||
const wfOwnerRole = () =>
|
||||
Object.assign(new Role(), {
|
||||
@@ -94,7 +95,7 @@ describe('OwnershipService', () => {
|
||||
});
|
||||
|
||||
describe('addOwnedByAndSharedWith()', () => {
|
||||
test('should add ownedBy and sharedWith to credential', async () => {
|
||||
test('should add `ownedBy` and `sharedWith` to credential', async () => {
|
||||
const owner = mockUser();
|
||||
const editor = mockUser();
|
||||
|
||||
@@ -124,6 +125,36 @@ describe('OwnershipService', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test('should add `ownedBy` and `sharedWith` to workflow', async () => {
|
||||
const owner = mockUser();
|
||||
const editor = mockUser();
|
||||
|
||||
const workflow = new WorkflowEntity();
|
||||
|
||||
workflow.shared = [
|
||||
{ role: mockCredRole('owner'), user: owner },
|
||||
{ role: mockCredRole('editor'), user: editor },
|
||||
] as SharedWorkflow[];
|
||||
|
||||
const { ownedBy, sharedWith } = ownershipService.addOwnedByAndSharedWith(workflow);
|
||||
|
||||
expect(ownedBy).toStrictEqual({
|
||||
id: owner.id,
|
||||
email: owner.email,
|
||||
firstName: owner.firstName,
|
||||
lastName: owner.lastName,
|
||||
});
|
||||
|
||||
expect(sharedWith).toStrictEqual([
|
||||
{
|
||||
id: editor.id,
|
||||
email: editor.email,
|
||||
firstName: editor.firstName,
|
||||
lastName: editor.lastName,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('should produce an empty sharedWith if no sharee', async () => {
|
||||
const owner = mockUser();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user