mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
refactor: Add credential information to workflow list (no-changelog) (#4700)
This commit is contained in:
parent
5059c57f4a
commit
36dc5f0e66
|
@ -9,7 +9,10 @@ import { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||||
import { RoleService } from '@/role/role.service';
|
import { RoleService } from '@/role/role.service';
|
||||||
import { UserService } from '@/user/user.service';
|
import { UserService } from '@/user/user.service';
|
||||||
import { WorkflowsService } from './workflows.services';
|
import { WorkflowsService } from './workflows.services';
|
||||||
import type { WorkflowWithSharingsAndCredentials } from './workflows.types';
|
import type {
|
||||||
|
CredentialUsedByWorkflow,
|
||||||
|
WorkflowWithSharingsAndCredentials,
|
||||||
|
} from './workflows.types';
|
||||||
import { EECredentialsService as EECredentials } from '@/credentials/credentials.service.ee';
|
import { EECredentialsService as EECredentials } from '@/credentials/credentials.service.ee';
|
||||||
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
|
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
|
||||||
|
|
||||||
|
@ -129,16 +132,28 @@ export class EEWorkflowsService extends WorkflowsService {
|
||||||
where: {
|
where: {
|
||||||
id: In(Array.from(credentialIdsUsedByWorkflow)),
|
id: In(Array.from(credentialIdsUsedByWorkflow)),
|
||||||
},
|
},
|
||||||
|
relations: ['shared', 'shared.user', 'shared.role'],
|
||||||
});
|
});
|
||||||
const userCredentialIds = userCredentials.map((credential) => credential.id.toString());
|
const userCredentialIds = userCredentials.map((credential) => credential.id.toString());
|
||||||
workflowCredentials.forEach((credential) => {
|
workflowCredentials.forEach((credential) => {
|
||||||
const credentialId = credential.id.toString();
|
const credentialId = credential.id.toString();
|
||||||
workflow.usedCredentials?.push({
|
const workflowCredential: CredentialUsedByWorkflow = {
|
||||||
id: credential.id.toString(),
|
id: credential.id.toString(),
|
||||||
name: credential.name,
|
name: credential.name,
|
||||||
type: credential.type,
|
type: credential.type,
|
||||||
currentUserHasAccess: userCredentialIds.includes(credentialId),
|
currentUserHasAccess: userCredentialIds.includes(credentialId),
|
||||||
|
sharedWith: [],
|
||||||
|
ownedBy: null,
|
||||||
|
};
|
||||||
|
credential.shared?.forEach(({ user, role }) => {
|
||||||
|
const { id, email, firstName, lastName } = user;
|
||||||
|
if (role.name === 'owner') {
|
||||||
|
workflowCredential.ownedBy = { id, email, firstName, lastName };
|
||||||
|
} else {
|
||||||
|
workflowCredential.sharedWith?.push({ id, email, firstName, lastName });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
workflow.usedCredentials?.push(workflowCredential);
|
||||||
});
|
});
|
||||||
|
|
||||||
return workflow;
|
return workflow;
|
||||||
|
|
|
@ -14,4 +14,6 @@ export interface CredentialUsedByWorkflow {
|
||||||
name: string;
|
name: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
currentUserHasAccess: boolean;
|
currentUserHasAccess: boolean;
|
||||||
|
ownedBy?: IUser | null;
|
||||||
|
sharedWith?: IUser[];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue