mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 15:53:16 +03:00
66438ff4ed
- using the resource type verbatim wasn't going to work with `api_key` because it needs splitting and capitalizing
49 lines
1.1 KiB
JavaScript
49 lines
1.1 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});
|
|
|
|
return {
|
|
get actor() {
|
|
return getActor();
|
|
},
|
|
get resource() {
|
|
return getResource();
|
|
},
|
|
actionIcon,
|
|
action,
|
|
original: ev
|
|
};
|
|
}
|
|
}
|
|
|
|
function getActionIcon(ev) {
|
|
switch (ev.event) {
|
|
case 'added':
|
|
return 'add-stroke';
|
|
case 'edited':
|
|
return 'content';
|
|
case 'deleted':
|
|
return 'cross-circle';
|
|
}
|
|
|
|
return 'info';
|
|
}
|
|
|
|
function getAction(ev) {
|
|
let resourceType = ev.resource_type;
|
|
|
|
if (resourceType === 'api_key') {
|
|
resourceType = 'API key';
|
|
}
|
|
|
|
return `${ev.event} ${resourceType}`;
|
|
}
|