Add model name to entry events

This commit is contained in:
Rémi de Juvigny 2023-01-13 10:20:18 +01:00
parent a91a9016ad
commit 3a227b6f1e
7 changed files with 34 additions and 21 deletions

View File

@ -48,10 +48,13 @@ const ActionBody = ({ status, data, formattedDate }) => {
id: 'Settings.permissions.auditLogs.action', id: 'Settings.permissions.auditLogs.action',
defaultMessage: 'Action', defaultMessage: 'Action',
})} })}
actionName={formatMessage({ actionName={formatMessage(
{
id: `Settings.permissions.auditLogs.${action}`, id: `Settings.permissions.auditLogs.${action}`,
defaultMessage: getDefaultMessage(action), defaultMessage: getDefaultMessage(action),
})} },
{ model: payload?.model }
)}
/> />
<ActionItem <ActionItem
actionLabel={formatMessage({ actionLabel={formatMessage({

View File

@ -14,16 +14,19 @@ const TableRows = ({ headers, rows, onOpenModal }) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const formatTimeStamp = useFormatTimeStamp(); const formatTimeStamp = useFormatTimeStamp();
const getCellValue = ({ type, value }) => { const getCellValue = ({ type, value, model }) => {
if (type === 'date') { if (type === 'date') {
return formatTimeStamp(value); return formatTimeStamp(value);
} }
if (type === 'action') { if (type === 'action') {
return formatMessage({ return formatMessage(
{
id: `Settings.permissions.auditLogs.${value}`, id: `Settings.permissions.auditLogs.${value}`,
defaultMessage: getDefaultMessage(value), defaultMessage: getDefaultMessage(value),
}); },
{ model }
);
} }
return value || '-'; return value || '-';
@ -46,6 +49,7 @@ const TableRows = ({ headers, rows, onOpenModal }) => {
{getCellValue({ {getCellValue({
type: key, type: key,
value: cellFormatter ? cellFormatter(data[name]) : data[name], value: cellFormatter ? cellFormatter(data[name]) : data[name],
model: data.payload?.model,
})} })}
</Typography> </Typography>
</Td> </Td>

View File

@ -96,7 +96,7 @@ describe('ADMIN | Pages | AUDIT LOGS | ListView', () => {
await waitFor(() => { await waitFor(() => {
expect(screen.getByText('Create role')).toBeInTheDocument(); expect(screen.getByText('Create role')).toBeInTheDocument();
expect(screen.getByText('Delete role')).toBeInTheDocument(); expect(screen.getByText('Delete role')).toBeInTheDocument();
expect(screen.getByText('Create entry')).toBeInTheDocument(); expect(screen.getByText('Create entry (article)')).toBeInTheDocument();
expect(screen.getByText('Admin logout')).toBeInTheDocument(); expect(screen.getByText('Admin logout')).toBeInTheDocument();
}); });
}); });

View File

@ -8,6 +8,7 @@ const TEST_PAGE_DATA = [
fullname: 'test user', fullname: 'test user',
email: 'test@test.com', email: 'test@test.com',
}, },
payload: {},
}, },
{ {
id: 2, id: 2,
@ -18,12 +19,16 @@ const TEST_PAGE_DATA = [
fullname: 'test user', fullname: 'test user',
email: 'test@test.com', email: 'test@test.com',
}, },
payload: {},
}, },
{ {
id: 3, id: 3,
action: 'entry.create', action: 'entry.create',
date: '2022-12-27T17:34:00.673Z', date: '2022-12-27T17:34:00.673Z',
user: null, user: null,
payload: {
model: 'article',
},
}, },
{ {
id: 4, id: 4,
@ -34,6 +39,7 @@ const TEST_PAGE_DATA = [
fullname: 'test user', fullname: 'test user',
email: 'test@test.com', email: 'test@test.com',
}, },
payload: {},
}, },
]; ];

View File

@ -1,9 +1,9 @@
const actionTypes = { const actionTypes = {
'entry.create': 'Create entry', 'entry.create': 'Create entry ({model})',
'entry.update': 'Update entry', 'entry.update': 'Update entry ({model})',
'entry.delete': 'Delete entry', 'entry.delete': 'Delete entry ({model})',
'entry.publish': 'Publish entry', 'entry.publish': 'Publish entry ({model})',
'entry.unpublish': 'Unpublish entry', 'entry.unpublish': 'Unpublish entry ({model})',
'media.create': 'Create media', 'media.create': 'Create media',
'media.update': 'Update media', 'media.update': 'Update media',
'media.delete': 'Delete media', 'media.delete': 'Delete media',

View File

@ -181,11 +181,11 @@
"Settings.permissions.auditLogs.userId": "User ID", "Settings.permissions.auditLogs.userId": "User ID",
"Settings.permissions.auditLogs.details": "Log Details", "Settings.permissions.auditLogs.details": "Log Details",
"Settings.permissions.auditLogs.listview.header.subtitle": "Logs of all the activities that happened in your environment", "Settings.permissions.auditLogs.listview.header.subtitle": "Logs of all the activities that happened in your environment",
"Settings.permissions.auditLogs.entry.create": "Create entry", "Settings.permissions.auditLogs.entry.create": "Create entry ({model})",
"Settings.permissions.auditLogs.entry.update": "Update entry", "Settings.permissions.auditLogs.entry.update": "Update entry ({model})",
"Settings.permissions.auditLogs.entry.delete": "Delete entry", "Settings.permissions.auditLogs.entry.delete": "Delete entry ({model})",
"Settings.permissions.auditLogs.entry.publish": "Publish entry", "Settings.permissions.auditLogs.entry.publish": "Publish entry ({model})",
"Settings.permissions.auditLogs.entry.unpublish": "Unpublish entry", "Settings.permissions.auditLogs.entry.unpublish": "Unpublish entry ({model})",
"Settings.permissions.auditLogs.media.create": "Create media", "Settings.permissions.auditLogs.media.create": "Create media",
"Settings.permissions.auditLogs.media.update": "Update media", "Settings.permissions.auditLogs.media.update": "Update media",
"Settings.permissions.auditLogs.media.delete": "Delete media", "Settings.permissions.auditLogs.media.delete": "Delete media",

View File

@ -24,7 +24,7 @@ const provider = {
findMany(query) { findMany(query) {
return strapi.entityService.findPage('admin::audit-log', { return strapi.entityService.findPage('admin::audit-log', {
populate: ['user'], populate: ['user'],
fields: ['action', 'date'], fields: ['action', 'date', 'payload'],
...query, ...query,
}); });
}, },