refactor: Add credential information to workflow list (no-changelog) (#4700)

This commit is contained in:
Omar Ajoue 2022-11-23 15:34:17 +01:00 committed by GitHub
parent 5059c57f4a
commit 36dc5f0e66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -9,7 +9,10 @@ import { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { RoleService } from '@/role/role.service';
import { UserService } from '@/user/user.service';
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 { getSharedWorkflowIds } from '@/WorkflowHelpers';
@ -129,16 +132,28 @@ export class EEWorkflowsService extends WorkflowsService {
where: {
id: In(Array.from(credentialIdsUsedByWorkflow)),
},
relations: ['shared', 'shared.user', 'shared.role'],
});
const userCredentialIds = userCredentials.map((credential) => credential.id.toString());
workflowCredentials.forEach((credential) => {
const credentialId = credential.id.toString();
workflow.usedCredentials?.push({
const workflowCredential: CredentialUsedByWorkflow = {
id: credential.id.toString(),
name: credential.name,
type: credential.type,
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;

View file

@ -14,4 +14,6 @@ export interface CredentialUsedByWorkflow {
name: string;
type?: string;
currentUserHasAccess: boolean;
ownedBy?: IUser | null;
sharedWith?: IUser[];
}