Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit
This commit introduces a new module, `auditOwner.js`, which includes functions for resolving audit owner details and generating display names for actors. The `resolveAuditOwner` function determines the owner type based on the actor's object type, defaulting to 'user' if not specified. The `actorDisplayName` function formats the display name based on the actor's properties, enhancing the clarity of audit logs. Additionally, the `AUDIT_OWNER_TYPES` constant is exported for use in other modules. Updates to existing files incorporate these new functions for improved audit logging and notification handling.
23 lines
615 B
JavaScript
23 lines
615 B
JavaScript
const AUDIT_OWNER_TYPES = ['user', 'printer', 'host', 'marketplace'];
|
|
|
|
export function resolveAuditOwner(actor) {
|
|
const ownerType = AUDIT_OWNER_TYPES.includes(actor?._objectType)
|
|
? actor._objectType
|
|
: 'user';
|
|
return {
|
|
owner: actor?._id,
|
|
ownerType,
|
|
};
|
|
}
|
|
|
|
export function actorDisplayName(actor) {
|
|
if (actor?._objectType === 'marketplace' || actor?._objectType === 'host') {
|
|
return actor.name || actor._objectType;
|
|
}
|
|
const firstName = actor?.firstName ?? 'unknown';
|
|
const lastName = actor?.lastName ?? '';
|
|
return `${firstName} ${lastName}`.trim();
|
|
}
|
|
|
|
export { AUDIT_OWNER_TYPES };
|