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-23 15:11:24 +03:00
|
|
|
const contextResource = getContextResource(ev);
|
2022-08-23 18:37:09 +03:00
|
|
|
const linkTarget = getLinkTarget(ev);
|
2022-08-17 14:50:30 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
get actor() {
|
|
|
|
return getActor();
|
|
|
|
},
|
2022-08-23 15:11:24 +03:00
|
|
|
contextResource,
|
2022-08-23 18:37:09 +03:00
|
|
|
linkTarget,
|
2022-08-17 14:50:30 +03:00
|
|
|
actionIcon,
|
|
|
|
action,
|
|
|
|
original: ev
|
|
|
|
};
|
|
|
|
}
|
2022-08-16 13:40:33 +03:00
|
|
|
}
|
|
|
|
|
2022-08-23 18:37:09 +03:00
|
|
|
function getLinkTarget(ev) {
|
|
|
|
let resourceType = ev.resource_type;
|
|
|
|
|
|
|
|
if (ev.event !== 'deleted') {
|
|
|
|
switch (ev.resource_type) {
|
|
|
|
case 'page':
|
|
|
|
case 'post':
|
|
|
|
if (!ev.resource.id) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resourceType === 'post') {
|
|
|
|
if (ev.context?.type) {
|
|
|
|
resourceType = ev.context?.type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
route: 'editor.edit',
|
|
|
|
models: [resourceType, ev.resource.id]
|
|
|
|
};
|
2022-08-23 19:06:12 +03:00
|
|
|
case 'integration':
|
|
|
|
if (!ev.resource.id) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
route: 'settings.integration',
|
|
|
|
models: [ev.resource.id]
|
|
|
|
};
|
2022-08-24 14:24:13 +03:00
|
|
|
case 'offer':
|
|
|
|
if (!ev.resource.id) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
route: 'offer',
|
|
|
|
models: [ev.resource.id]
|
|
|
|
};
|
2022-08-23 18:37:09 +03:00
|
|
|
case 'tag':
|
|
|
|
if (!ev.resource.slug) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
route: 'tag',
|
|
|
|
models: [ev.resource.slug]
|
|
|
|
};
|
|
|
|
case 'user':
|
|
|
|
if (!ev.resource.slug) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
route: 'settings.staff.user',
|
|
|
|
models: [ev.resource.slug]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
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';
|
2022-08-22 22:12:32 +03:00
|
|
|
} else if (resourceType === 'setting') {
|
|
|
|
resourceType = 'settings';
|
2022-08-22 16:30:13 +03:00
|
|
|
}
|
|
|
|
|
2022-08-23 18:37:09 +03:00
|
|
|
// Because a `page` and `post` both use the same model, we store the
|
|
|
|
// actual type in the context, so let's check if that exists
|
|
|
|
if (resourceType === 'post') {
|
|
|
|
if (ev.context?.type) {
|
|
|
|
resourceType = ev.context?.type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-22 16:30:13 +03:00
|
|
|
return `${ev.event} ${resourceType}`;
|
2022-08-16 13:40:33 +03:00
|
|
|
}
|
2022-08-23 15:11:24 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|