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-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-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':
|
|
|
|
return 'add-stroke';
|
|
|
|
case 'edited':
|
|
|
|
return 'content';
|
|
|
|
case 'deleted':
|
|
|
|
return 'cross-circle';
|
|
|
|
}
|
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
|
|
|
}
|