mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
9effa119c6
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
69 lines
1.7 KiB
JavaScript
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;
|
|
}
|