mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat: return sharees when returning a workflow (#4312) (no-changelog)
This commit is contained in:
@@ -458,6 +458,13 @@ export function getWorkflowOwnerRole() {
|
||||
});
|
||||
}
|
||||
|
||||
export function getWorkflowEditorRole() {
|
||||
return Db.collections.Role.findOneOrFail({
|
||||
name: 'editor',
|
||||
scope: 'workflow',
|
||||
});
|
||||
}
|
||||
|
||||
export function getCredentialOwnerRole() {
|
||||
return Db.collections.Role.findOneOrFail({
|
||||
name: 'owner',
|
||||
@@ -607,6 +614,16 @@ export async function createWorkflow(attributes: Partial<WorkflowEntity> = {}, u
|
||||
return workflow;
|
||||
}
|
||||
|
||||
export async function shareWorkflowWithUsers(workflow: WorkflowEntity, users: User[]) {
|
||||
const role = await getWorkflowEditorRole();
|
||||
const sharedWorkflows = users.map((user) => ({
|
||||
user,
|
||||
workflow,
|
||||
role,
|
||||
}));
|
||||
return Db.collections.SharedWorkflow.save(sharedWorkflows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a workflow in the DB (with a trigger) and optionally assign it to a user.
|
||||
* @param user user to assign the workflow to
|
||||
|
||||
Reference in New Issue
Block a user