0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -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,14 +1,23 @@
export default function parseAuditLogEvent(ev) { import Helper from '@ember/component/helper';
const actorName = getActorName(ev); import {inject as service} from '@ember/service';
const action = getAction(ev);
const actionIcon = getActionIcon(ev);
return { export default class ParseAuditLogEvent extends Helper {
actorName, @service store;
actionIcon,
action, compute([ev]) {
original: 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) { function getActionIcon(ev) {
@ -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>