From 2d1d810198f7ecb6aeb2a5a6247cae7fa81cfd8e Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 17 Aug 2022 12:50:30 +0100 Subject: [PATCH] Fetched actor record to display real name when listing audit log events no issue - switched `parse-audit-log-event` to a class helper to get access to dependency injection - added `get actor()` to the parsed event object - uses the store to find the related user record, returning an already loaded record if it exists otherwise fetches the record - allows use of `event.actor.*` in templates because they are promise-aware and will be filled in once the record is loaded --- .../app/helpers/parse-audit-log-event.js | 33 +++++++++++-------- .../app/templates/settings/audit-log.hbs | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ghost/admin/app/helpers/parse-audit-log-event.js b/ghost/admin/app/helpers/parse-audit-log-event.js index 76ed51f6a7..8df9475916 100644 --- a/ghost/admin/app/helpers/parse-audit-log-event.js +++ b/ghost/admin/app/helpers/parse-audit-log-event.js @@ -1,14 +1,23 @@ -export default function parseAuditLogEvent(ev) { - const actorName = getActorName(ev); - const action = getAction(ev); - const actionIcon = getActionIcon(ev); +import Helper from '@ember/component/helper'; +import {inject as service} from '@ember/service'; - return { - actorName, - actionIcon, - action, - original: ev - }; +export default class ParseAuditLogEvent extends Helper { + @service store; + + compute([ev]) { + const action = getAction(ev); + const actionIcon = getActionIcon(ev); + const getActor = () => this.store.findRecord('user', ev.actor_id, {reload: false}); + + return { + get actor() { + return getActor(); + }, + actionIcon, + action, + original: ev + }; + } } function getActionIcon(ev) { @@ -22,10 +31,6 @@ function getActionIcon(ev) { } } -function getActorName(ev) { - return ev.actor_id; -} - function getAction(ev) { return `${ev.event} ${ev.resource_type}`; } diff --git a/ghost/admin/app/templates/settings/audit-log.hbs b/ghost/admin/app/templates/settings/audit-log.hbs index 68ac9e0ac9..4d46587972 100644 --- a/ghost/admin/app/templates/settings/audit-log.hbs +++ b/ghost/admin/app/templates/settings/audit-log.hbs @@ -25,7 +25,7 @@
-

{{ev.actorName}}

+

{{ev.actor.name}}