0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

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
This commit is contained in:
Kevin Ansfield 2022-08-17 12:50:30 +01:00 committed by Daniel Lockyer
parent 9f294fa900
commit 2d1d810198
2 changed files with 20 additions and 15 deletions

View file

@ -1,15 +1,24 @@
export default function parseAuditLogEvent(ev) { import Helper from '@ember/component/helper';
const actorName = getActorName(ev); import {inject as service} from '@ember/service';
export default class ParseAuditLogEvent extends Helper {
@service store;
compute([ev]) {
const action = getAction(ev); const action = getAction(ev);
const actionIcon = getActionIcon(ev); const actionIcon = getActionIcon(ev);
const getActor = () => this.store.findRecord('user', ev.actor_id, {reload: false});
return { return {
actorName, get actor() {
return getActor();
},
actionIcon, actionIcon,
action, action,
original: ev original: ev
}; };
} }
}
function getActionIcon(ev) { function getActionIcon(ev) {
switch (ev.event) { switch (ev.event) {
@ -22,10 +31,6 @@ function getActionIcon(ev) {
} }
} }
function getActorName(ev) {
return ev.actor_id;
}
function getAction(ev) { function getAction(ev) {
return `${ev.event} ${ev.resource_type}`; return `${ev.event} ${ev.resource_type}`;
} }

View file

@ -25,7 +25,7 @@
<div class="gh-list-data"> <div class="gh-list-data">
<div class="flex items-center"> <div class="flex items-center">
<div class="w-80"> <div class="w-80">
<h3 class="ma0 pa0 gh-members-list-name">{{ev.actorName}}</h3> <h3 class="ma0 pa0 gh-members-list-name">{{ev.actor.name}}</h3>
</div> </div>
</div> </div>
</div> </div>