Ghost/ghost/admin/app/helpers/parse-audit-log-event.js
Daniel Lockyer 9effa119c6 Implemented context on Actions events
refs https://github.com/TryGhost/Toolbox/issues/356

- in order to show data that we might not necessarily still have around
  (ie. when you delete a post, you might want the title), we're going to
  start utilizing the `context` column
- right now, we store the `primary_name` for deleted events, and we also
  store the `setting` `key` and `group` so we can reference it in the
  audit log
2022-08-23 14:58:41 +02:00

69 lines
1.7 KiB
JavaScript

import Helper from '@ember/component/helper';
import {inject as service} from '@ember/service';
export default class ParseAuditLogEvent extends Helper {
@service store;
compute([ev]) {
const action = getAction(ev);
const actionIcon = getActionIcon(ev);
const getActor = () => this.store.findRecord(ev.actor_type, ev.actor_id, {reload: false});
const getResource = () => this.store.findRecord(ev.resource_type, ev.resource_id, {reload: false});
const contextResource = getContextResource(ev);
const linkable = ['page', 'post'].includes(ev.resource_type) && ev.event !== 'deleted';
return {
get actor() {
return getActor();
},
get resource() {
return getResource();
},
contextResource,
linkable,
actionIcon,
action,
original: ev
};
}
}
function getActionIcon(ev) {
switch (ev.event) {
case 'added':
return 'add';
case 'edited':
return 'pen';
case 'deleted':
return 'trash';
}
return 'info';
}
function getAction(ev) {
let resourceType = ev.resource_type;
if (resourceType === 'api_key') {
resourceType = 'API key';
} else if (resourceType === 'setting') {
resourceType = 'settings';
}
return `${ev.event} ${resourceType}`;
}
function getContextResource(ev) {
if (ev.resource_type === 'setting') {
if (ev.context?.group && ev.context?.key) {
return {
first: ev.context.group,
second: ev.context.key
};
}
}
return null;
}