2022-08-17 14:50:30 +03:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-08-16 13:40:33 +03:00
|
|
|
|
2022-08-17 14:50:30 +03:00
|
|
|
export default class ParseAuditLogEvent extends Helper {
|
|
|
|
@service store;
|
|
|
|
|
|
|
|
compute([ev]) {
|
|
|
|
const action = getAction(ev);
|
|
|
|
const actionIcon = getActionIcon(ev);
|
2022-08-18 17:58:42 +03:00
|
|
|
const getActor = () => this.store.findRecord(ev.actor_type, ev.actor_id, {reload: false});
|
2022-08-17 15:43:01 +03:00
|
|
|
const getResource = () => this.store.findRecord(ev.resource_type, ev.resource_id, {reload: false});
|
2022-08-22 17:09:56 +03:00
|
|
|
const linkable = ['page', 'post'].includes(ev.resource_type);
|
2022-08-17 14:50:30 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
get actor() {
|
|
|
|
return getActor();
|
|
|
|
},
|
2022-08-17 15:43:01 +03:00
|
|
|
get resource() {
|
|
|
|
return getResource();
|
|
|
|
},
|
2022-08-22 17:09:56 +03:00
|
|
|
linkable,
|
2022-08-17 14:50:30 +03:00
|
|
|
actionIcon,
|
|
|
|
action,
|
|
|
|
original: ev
|
|
|
|
};
|
|
|
|
}
|
2022-08-16 13:40:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getActionIcon(ev) {
|
|
|
|
switch (ev.event) {
|
|
|
|
case 'added':
|
2022-08-22 20:14:17 +03:00
|
|
|
return 'add';
|
2022-08-16 13:40:33 +03:00
|
|
|
case 'edited':
|
2022-08-22 20:14:17 +03:00
|
|
|
return 'pen';
|
2022-08-16 13:40:33 +03:00
|
|
|
case 'deleted':
|
2022-08-22 20:14:17 +03:00
|
|
|
return 'trash';
|
2022-08-16 13:40:33 +03:00
|
|
|
}
|
2022-08-17 15:54:54 +03:00
|
|
|
|
|
|
|
return 'info';
|
2022-08-16 13:40:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAction(ev) {
|
2022-08-22 16:30:13 +03:00
|
|
|
let resourceType = ev.resource_type;
|
|
|
|
|
|
|
|
if (resourceType === 'api_key') {
|
|
|
|
resourceType = 'API key';
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${ev.event} ${resourceType}`;
|
2022-08-16 13:40:33 +03:00
|
|
|
}
|