Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Audit Logs feature #15536

Merged
merged 176 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
b00348c
added audit logs page
madhurisandbhor Nov 17, 2022
ea39f71
added test case
madhurisandbhor Nov 17, 2022
cd943a2
updated test cases, removed snapshot
madhurisandbhor Nov 18, 2022
c591861
added audit logs list component and modal dialog
madhurisandbhor Nov 24, 2022
4439cc4
minor changes
madhurisandbhor Nov 25, 2022
6e8b615
updated review comments
madhurisandbhor Nov 25, 2022
ca74f49
minor change
madhurisandbhor Nov 25, 2022
cfc2fb5
Init audit logs service
remidej Dec 5, 2022
fe3ae1d
Test audit log service
markkaylor Dec 5, 2022
353e9a4
Pr feedback
markkaylor Dec 6, 2022
972bdd7
Move service to the ee folder
markkaylor Dec 6, 2022
c8f4c5a
Execute missing CE register
alexandrebodin Dec 7, 2022
d24ab05
Refactor the event hub
remidej Dec 8, 2022
c29a2a8
Remove logs
remidej Dec 8, 2022
84bdd98
Merge branch 'audit-logs/event-hub-refactoring' into audit-logs/service
remidej Dec 8, 2022
2a2801e
Refactor audit logs service
remidej Dec 8, 2022
d6d9f88
wip update audit logs tests
remidej Dec 8, 2022
3f01d36
Apply feedback
remidej Dec 9, 2022
32d4196
Merge branch 'audit-logs/event-hub-refactoring' into audit-logs/service
remidej Dec 9, 2022
d61eda4
Clear listeners on destroy
remidej Dec 9, 2022
a7520d8
Add aliases and tests
remidej Dec 9, 2022
6dced3a
Add event hub tests
remidej Dec 9, 2022
07dee82
Merge branch 'audit-logs/event-hub-refactoring' of github.com:strapi/…
Feranchz Dec 11, 2022
04f7212
WIP: Changes on the test when audit logs are enabled or not
Feranchz Dec 11, 2022
b410f12
Apply feedback
remidej Dec 12, 2022
34278a7
fix destroy alias
remidej Dec 12, 2022
325c70a
Merge pull request #15128 from strapi/audit-logs/event-hub-refactoring
remidej Dec 12, 2022
bdda90e
Merge remote-tracking branch 'origin/feature/audit-logs' into audit-l…
remidej Dec 12, 2022
964654b
Move audit logs register
Feranchz Dec 12, 2022
a1ba416
added missing border radius
madhurisandbhor Dec 12, 2022
6af468b
Change auditLogs method to register
Feranchz Dec 13, 2022
fd0c592
Fixed auditlogs tests making waitinf for the emit
Feranchz Dec 13, 2022
c28f0d7
Waiting for expect in the reject test on auditlogs
Feranchz Dec 13, 2022
b51ac6c
Merge pull request #15159 from strapi/audit-logs/css-issue
madhurisandbhor Dec 13, 2022
1dce8ff
updated right prop for border radius
madhurisandbhor Dec 13, 2022
9171c48
Merge pull request #15170 from strapi/audit-logs/modal-css
madhurisandbhor Dec 14, 2022
fb73cb6
Process audit log events
remidej Dec 14, 2022
46ac677
Return inline object
remidej Dec 14, 2022
6c061e1
Sanitize emitted auth events
remidej Dec 16, 2022
95b98af
Emit create user
markkaylor Dec 16, 2022
47a6ea1
Emit delete user
markkaylor Dec 16, 2022
fdda09f
Emit update user
markkaylor Dec 16, 2022
e410fdd
Emit read user
markkaylor Dec 16, 2022
6f8bed7
Fix update user
markkaylor Dec 16, 2022
723e713
Remove read events
markkaylor Dec 16, 2022
dc7cd64
Apply unsubscribe feedback
remidej Dec 16, 2022
00e9d7a
Emitting events for creating/update/delete/permission in a role
Feranchz Dec 16, 2022
5362403
Use object with users key for bulk delete
markkaylor Dec 16, 2022
8121614
Fix tests
markkaylor Dec 16, 2022
e982b6a
Merge pull request #15086 from strapi/audit-logs/service
remidej Dec 16, 2022
b239d0a
Extract getEventMap function
remidej Dec 19, 2022
88521b5
Restore service file instead of folder
remidej Dec 19, 2022
e64caae
Merge remote-tracking branch 'origin/feature/audit-logs' into audit-l…
remidej Dec 19, 2022
bf2162d
Add tests
remidej Dec 19, 2022
130503f
Merge remote-tracking branch 'origin/audit-logs/process-events' into …
remidej Dec 19, 2022
6dd78f6
Merge pull request #15179 from strapi/audit-logs/process-events
remidej Dec 19, 2022
938e080
Merge pull request #15199 from strapi/process-events/emit-user-events
remidej Dec 19, 2022
d8ae7ad
Merge remote-tracking branch 'origin/main' into feature/audit-logs
remidej Dec 19, 2022
70e88d2
Add logout event to audit logs
remidej Dec 20, 2022
5e4ebde
Emit events for content type crud actions
remidej Dec 20, 2022
d26434b
Dont use an emitWrapper in the audit logs roles events
Feranchz Dec 21, 2022
6e63a82
Merge pull request #15222 from strapi/audit-logs/ctb-events
remidej Dec 21, 2022
1f5d2d8
Merge branch 'feature/audit-logs' into audit-logs/emit-logout
remidej Dec 21, 2022
569b490
Merge pull request #15219 from strapi/audit-logs/emit-logout
remidej Dec 21, 2022
b158657
Merge with feature branch
Feranchz Dec 21, 2022
4cb4d3e
Init audit log local provider package
remidej Dec 20, 2022
25816f8
Register invisible audit log collection type
remidej Dec 20, 2022
bc890ae
Save audit log events to database
remidej Dec 20, 2022
d90f352
Update tests
remidej Dec 21, 2022
6a7cef3
Make provider register async
remidej Dec 21, 2022
e4a9fd9
Creating new events for the permissions and handle them on the servic…
Feranchz Dec 21, 2022
e1e0fdb
Delete old process-event file
Feranchz Dec 21, 2022
ab54a49
Edit in permission events' name and in roles emitting
Feranchz Dec 21, 2022
91926bd
More tests
remidej Dec 21, 2022
1dac28b
Merge pull request #15200 from strapi/process-events/emit-roles-events
Feranchz Dec 21, 2022
89021f7
Merge branch 'audit-logs/local-provider' of github.com:strapi/strapi …
Feranchz Dec 21, 2022
2ab05a1
Restore await executeCERegister
remidej Dec 21, 2022
7ba3793
Merge branch 'feature/audit-logs' into audit-logs/local-provider
remidej Dec 21, 2022
45085fc
New audit logs endpoint
Feranchz Dec 22, 2022
99bf01d
Store provider on the audit log service object
remidej Dec 22, 2022
fbaa410
Add pagination and order in the audit logs endpoint & tests
Feranchz Dec 22, 2022
21ce750
merge from local-providers branch
Feranchz Dec 22, 2022
13dfc1e
improves on audit logs submission form
Feranchz Dec 22, 2022
7703a69
Merge pull request #15233 from strapi/audit-logs/local-provider
remidej Dec 22, 2022
6a0e1a1
Merge branch 'feature/audit-logs' into audit-logs/logs-endpoint
remidej Dec 23, 2022
a32ddfe
Merge pull request #15244 from strapi/audit-logs/logs-endpoint
Feranchz Dec 23, 2022
feaa2a6
Event hub tiny optimization
remidej Dec 23, 2022
5462cd3
Use object for user event payloads
remidej Dec 23, 2022
a60014d
Find one auditlog endpoint and remove payload from findMany endpoint
Feranchz Dec 23, 2022
19350c6
Merge pull request #15263 from strapi/audit-logs/one-audit-log-endpoint
Feranchz Dec 23, 2022
477cd21
Merge pull request #15262 from strapi/audit-logs/polishing
remidej Dec 23, 2022
b90589d
Change audit logs endpoints to return just the fullname and not all t…
Feranchz Dec 28, 2022
10dbf10
audit logs api mapping, updated test cases
madhurisandbhor Dec 28, 2022
7489dc2
Add getFullname function
Feranchz Dec 29, 2022
eeceb3d
Use getFullname in both endpoints
Feranchz Dec 29, 2022
e5a6e00
added actionTypes object
madhurisandbhor Dec 29, 2022
c28edee
renamed user key to fullname
madhurisandbhor Dec 29, 2022
b7a6b4e
updated test description
madhurisandbhor Dec 29, 2022
dc992ff
updated table test cases
madhurisandbhor Dec 29, 2022
c7e1098
Return user object with less info
Feranchz Dec 30, 2022
6f975b3
Add delete expired logs methods and add the cron
Feranchz Dec 30, 2022
b9c09e1
Merge pull request #15286 from strapi/audit-logs/endpoints-changes
Feranchz Dec 30, 2022
2d67484
Merge branch 'feature/audit-logs' of github.com:strapi/strapi into au…
Feranchz Dec 30, 2022
4e63373
Start mapping to the new user object
Feranchz Dec 30, 2022
e53c354
Create a new admin-actions file for EE and add audit logs actions
Feranchz Jan 2, 2023
b16517a
Better name to the delete expired events job
Feranchz Jan 2, 2023
01ca9a6
typo fix
Feranchz Jan 2, 2023
09241c7
Remove todo comment
Feranchz Jan 2, 2023
56526f7
Merge pull request #15315 from strapi/audit-logs/actions-and-permissions
Feranchz Jan 2, 2023
569da42
Merge fix and small change
Feranchz Jan 2, 2023
4396ac5
Merge pull request #15301 from strapi/audit-logs/delete-methods
Feranchz Jan 2, 2023
f6a591a
Delete CellValue component and make it a function
Feranchz Jan 3, 2023
287aac9
Merge remote-tracking branch 'origin/audit-logs/list-api-mapping' int…
remidej Jan 3, 2023
484dc50
Merge branch 'feature/audit-logs' of github.com:strapi/strapi into au…
Feranchz Jan 3, 2023
55666f4
Start using useFetchClient and sort values
Feranchz Jan 3, 2023
b316520
Change of getDefaultMessage function without the switch
Feranchz Jan 3, 2023
995938b
Small fixs
Feranchz Jan 3, 2023
9818909
Use real data on audit log modal
remidej Jan 4, 2023
74ab737
Fix on tests and others
Feranchz Jan 4, 2023
00edca9
Fix typo
Feranchz Jan 4, 2023
706d393
Improves on audit logs page
Feranchz Jan 5, 2023
f5bf3b2
Move directories
Feranchz Jan 5, 2023
a93e1b0
Merge pull request #15293 from strapi/audit-logs/list-api-mapping
Feranchz Jan 5, 2023
9e0ed51
Merge remote-tracking branch 'origin/feature/audit-logs' into audit-l…
remidej Jan 5, 2023
b1746fc
Add pagination to audit logs page
Feranchz Jan 6, 2023
a72a540
Add live data to audit log modal
remidej Jan 6, 2023
b9a503c
pageSize defaults to 50 on audit logs page
Feranchz Jan 9, 2023
4a2cc23
Fix tests
Feranchz Jan 9, 2023
26f750d
feedback
remidej Jan 9, 2023
9b5dd1b
Fix modal labelledBy
remidej Jan 9, 2023
38ccee0
Merge pull request #15370 from strapi/audit-logs/api-modal
remidej Jan 9, 2023
65e29e5
Merge fix
Feranchz Jan 10, 2023
ebd758c
Merge pull request #15368 from strapi/audit-logs/pagination
Feranchz Jan 10, 2023
8aa4124
Add JSON component to modal
markkaylor Jan 11, 2023
71fcb0f
Update component import
markkaylor Jan 11, 2023
a91a901
Add user ID to audit log modal
remidej Jan 12, 2023
3a227b6
Add model name to entry events
remidej Jan 13, 2023
7e30022
Use experimental json input release
markkaylor Jan 13, 2023
a56b281
Merge pull request #15429 from strapi/audit-logs/log-details
remidej Jan 13, 2023
a0f0b2d
Merge pull request #15411 from strapi/audit-logs/modal-json-compo
markkaylor Jan 13, 2023
d302dcd
Sort audit logs by new by default
remidej Jan 16, 2023
2f3f9f4
Fix test
remidej Jan 17, 2023
13fd48c
Merge pull request #15468 from strapi/audit-logs/default-sort
remidej Jan 17, 2023
c94d8b7
Move retention calculation to feature level
remidej Jan 17, 2023
4fab209
Merge branch 'feature/audit-logs' into audit-logs/retention
remidej Jan 17, 2023
c6ab483
Fix invisible content type
remidej Jan 17, 2023
6f2ced8
Merge pull request #15477 from strapi/audit-logs/invisible-fix
remidej Jan 17, 2023
2a18a3f
Merge branch 'main' into feature/audit-logs
petersg83 Jan 18, 2023
5222cef
Merge branch 'feature/audit-logs' into audit-logs/retention
remidej Jan 18, 2023
ccc6da1
Ignore upload plugin entry events
remidej Jan 18, 2023
fac5dfd
Fix useFetchClient import
remidej Jan 18, 2023
d725279
Add media folder events
remidej Jan 18, 2023
7d184b0
Merge pull request #15489 from strapi/audit-logs/duplicate-events
remidej Jan 19, 2023
f121875
Merge pull request #15475 from strapi/audit-logs/retention
remidej Jan 19, 2023
3fd3457
Change cache time on audit logs query
Feranchz Jan 23, 2023
6ff1ce5
Manage opened log in URL params
remidej Jan 23, 2023
9294e96
Merge pull request #15526 from strapi/audit-logs/cache-duration
Feranchz Jan 23, 2023
65654f5
Bump retention days to 90
remidej Jan 23, 2023
9b348b4
Merge pull request #15533 from strapi/audit-logs/extend-retention
remidej Jan 23, 2023
52af45b
Handle unknown audit log ID
remidej Jan 23, 2023
c0c548d
Merge branch 'feature/audit-logs' into audit-logs/log-url
remidej Jan 23, 2023
0875dc9
Fix audit logs route policy
remidej Jan 23, 2023
f593197
Merge pull request #15537 from strapi/audit-logs/route-policy
remidej Jan 24, 2023
9b65cc4
Merge pull request #15529 from strapi/audit-logs/log-url
remidej Jan 24, 2023
1935ec5
Fix entity service events tests
remidej Jan 24, 2023
803f99c
Merge pull request #15546 from strapi/audit-logs/tests-fix
remidej Jan 24, 2023
963f651
Merge branch 'main' of github.com:strapi/strapi into feature/audit-logs
markkaylor Jan 24, 2023
2f7de9a
WIP move audit logs frontend to ee
remidej Jan 25, 2023
c5c20a3
Fix EE settings menu
remidej Jan 25, 2023
1961ae6
Add check for audit-logs feature enabled
markkaylor Jan 25, 2023
b4f16ee
Merge pull request #15568 from strapi/audit-logs/ee-admin
remidej Jan 25, 2023
85916f4
Merge branch 'main' into feature/audit-logs
markkaylor Jan 25, 2023
37a6c05
Move useRealTimers to afterAll
markkaylor Jan 25, 2023
caaa149
Merge branch 'main' into feature/audit-logs
markkaylor Jan 25, 2023
9ef1bea
Fix api tests
remidej Jan 25, 2023
10274e4
Mock audit log provider in API tests
remidej Jan 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = {
beforeUpdate() {
const ctx = strapi.requestContext.get();

console.log('User info in service: ', ctx.state.user);
},
};
10 changes: 7 additions & 3 deletions packages/core/admin/admin/src/components/LeftMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useRef, useState } from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { NavLink as RouterNavLink, useLocation } from 'react-router-dom';
import { NavLink as RouterNavLink, useLocation, useHistory } from 'react-router-dom';
import { Divider } from '@strapi/design-system/Divider';
import {
MainNav,
Expand All @@ -21,7 +21,8 @@ import { Stack } from '@strapi/design-system/Stack';
import Write from '@strapi/icons/Write';
import Exit from '@strapi/icons/Exit';
import { auth, usePersistentState, useAppInfos, useTracking } from '@strapi/helper-plugin';
import useConfigurations from '../../hooks/useConfigurations';
import { useConfigurations } from '../../hooks';
import { axiosInstance } from '../../core/utils';

const LinkUserWrapper = styled(Box)`
width: ${150 / 16}rem;
Expand Down Expand Up @@ -62,6 +63,7 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {
const { formatMessage } = useIntl();
const { trackUsage } = useTracking();
const { pathname } = useLocation();
const history = useHistory();

const initials = userDisplayName
.split(' ')
Expand All @@ -71,9 +73,11 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {

const handleToggleUserLinks = () => setUserLinksVisible((prev) => !prev);

const handleLogout = () => {
const handleLogout = async () => {
await axiosInstance.post('/admin/logout');
auth.clearAppStorage();
handleToggleUserLinks();
history.push('/auth/login');
};

const handleBlur = (e) => {
Expand Down
20 changes: 2 additions & 18 deletions packages/core/admin/admin/src/hooks/useSettingsMenu/init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import omit from 'lodash/omit';
import sortLinks from './utils/sortLinks';
import adminPermissions from '../../permissions';
import formatLinks from './utils/formatLinks';
import adminLinks from './utils/adminLinks';
import globalLinks from './utils/globalLinks';

const init = (initialState, { settings, shouldUpdateStrapi }) => {
Expand All @@ -23,23 +23,7 @@ const init = (initialState, { settings, shouldUpdateStrapi }) => {
{
id: 'permissions',
intlLabel: { id: 'Settings.permissions', defaultMessage: 'Administration Panel' },
links: [
{
intlLabel: { id: 'global.roles', defaultMessage: 'Roles' },
to: '/settings/roles',
id: 'roles',
isDisplayed: false,
permissions: adminPermissions.settings.roles.main,
},
{
intlLabel: { id: 'global.users' },
// Init the search params directly
to: '/settings/users?pageSize=10&page=1&sort=firstname',
id: 'users',
isDisplayed: false,
permissions: adminPermissions.settings.users.main,
},
],
links: adminLinks,
},
...otherSections,
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import customAdminLinks from 'ee_else_ce/hooks/useSettingsMenu/utils/customAdminLinks';
import defaultAdminLinks from './defaultAdminLinks';

export default [...customAdminLinks, ...defaultAdminLinks];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default [];
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import adminPermissions from '../../../permissions';

const defaultAdminLinks = [
{
intlLabel: { id: 'global.roles', defaultMessage: 'Roles' },
to: '/settings/roles',
id: 'roles',
isDisplayed: false,
permissions: adminPermissions.settings.roles.main,
},
{
intlLabel: { id: 'global.users' },
// Init the search params directly
to: '/settings/users?pageSize=10&page=1&sort=firstname',
id: 'users',
isDisplayed: false,
permissions: adminPermissions.settings.users.main,
},
];

export default defaultAdminLinks;
1 change: 1 addition & 0 deletions packages/core/admin/admin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ window.strapi = {
telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED ?? false,
features: {
SSO: 'sso',
auditLogs: 'audit-logs',
},
projectType: 'Community',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const permissions = {
uninstall: [{ action: 'admin::marketplace.plugins.uninstall', subject: null }],
},
settings: {
auditLogs: {
main: [{ action: 'admin::audit-logs.read', subject: null }],
read: [{ action: 'admin::audit-logs.read', subject: null }],
},
roles: {
main: [
{ action: 'admin::roles.create', subject: null },
Expand Down
34 changes: 34 additions & 0 deletions packages/core/admin/admin/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,38 @@
"Settings.permissions.users.strapi-super-admin": "Super Admin",
"Settings.permissions.users.strapi-editor": "Editor",
"Settings.permissions.users.strapi-author": "Author",
"Settings.permissions.auditLogs.action": "Action",
"Settings.permissions.auditLogs.date": "Date",
"Settings.permissions.auditLogs.user": "User",
"Settings.permissions.auditLogs.userId": "User ID",
"Settings.permissions.auditLogs.details": "Log Details",
"Settings.permissions.auditLogs.payload": "Payload",
"Settings.permissions.auditLogs.listview.header.subtitle": "Logs of all the activities that happened in your environment",
"Settings.permissions.auditLogs.entry.create": "Create entry ({model})",
"Settings.permissions.auditLogs.entry.update": "Update entry ({model})",
"Settings.permissions.auditLogs.entry.delete": "Delete entry ({model})",
"Settings.permissions.auditLogs.entry.publish": "Publish entry ({model})",
"Settings.permissions.auditLogs.entry.unpublish": "Unpublish entry ({model})",
"Settings.permissions.auditLogs.media.create": "Create media",
"Settings.permissions.auditLogs.media.update": "Update media",
"Settings.permissions.auditLogs.media.delete": "Delete media",
"Settings.permissions.auditLogs.user.create": "Create user",
"Settings.permissions.auditLogs.user.update": "Update user",
"Settings.permissions.auditLogs.user.delete": "Delete user",
"Settings.permissions.auditLogs.admin.auth.success": "Admin login",
"Settings.permissions.auditLogs.admin.logout": "Admin logout",
"Settings.permissions.auditLogs.content-type.create": "Create content type",
"Settings.permissions.auditLogs.content-type.update": "Update content type",
"Settings.permissions.auditLogs.content-type.delete": "Delete content type",
"Settings.permissions.auditLogs.component.create": "Create component",
"Settings.permissions.auditLogs.component.update": "Update component",
"Settings.permissions.auditLogs.component.delete": "Delete component",
"Settings.permissions.auditLogs.role.create": "Create role",
"Settings.permissions.auditLogs.role.update": "Update role",
"Settings.permissions.auditLogs.role.delete": "Delete role",
"Settings.permissions.auditLogs.permission.create": "Create permission",
"Settings.permissions.auditLogs.permission.update": "Update permission",
"Settings.permissions.auditLogs.permission.delete": "Delete permission",
"Settings.profile.form.notify.data.loaded": "Your profile data has been loaded",
"Settings.profile.form.section.experience.clear.select": "Clear the interface language selected",
"Settings.profile.form.section.experience.here": "here",
Expand Down Expand Up @@ -306,6 +338,7 @@
"app.component.search.label": "Search for {target}",
"app.component.table.duplicate": "Duplicate {target}",
"app.component.table.edit": "Edit {target}",
"app.component.table.view": "{target} details",
"app.component.table.select.one-entry": "Select {target}",
"app.components.BlockLink.blog": "Blog",
"app.components.BlockLink.blog.content": "Read the latest news about Strapi and the ecosystem.",
Expand Down Expand Up @@ -792,6 +825,7 @@
"global.settings": "Settings",
"global.type": "Type",
"global.users": "Users",
"global.auditLogs": "Audit Logs",
"notification.contentType.relations.conflict": "Content type has conflicting relations",
"notification.default.title": "Information:",
"notification.error": "An error occurred",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import adminPermissions from '../../../../../admin/src/permissions';

const auditLogsRoutes = strapi.features.isEnabled(strapi.features.auditLogs)
? [
{
intlLabel: { id: 'global.auditLogs', defaultMessage: 'Audit Logs' },
to: '/settings/audit-logs?pageSize=50&page=1&sort=date:DESC',
id: 'auditLogs',
isDisplayed: false,
permissions: adminPermissions.settings.auditLogs.main,
},
]
: [];

const customAdminLinks = [...auditLogsRoutes];

export default customAdminLinks;
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { Loader } from '@strapi/design-system/Loader';
import { Grid } from '@strapi/design-system/Grid';
import { Box } from '@strapi/design-system/Box';
import { Flex } from '@strapi/design-system/Flex';
import { Typography } from '@strapi/design-system/Typography';
import { JSONInput } from '@strapi/design-system/JSONInput';
import { pxToRem } from '@strapi/helper-plugin';
import getDefaultMessage from '../utils/getActionTypesDefaultMessages';
import ActionItem from './ActionItem';

const ActionBody = ({ status, data, formattedDate }) => {
const { formatMessage } = useIntl();

if (status === 'loading') {
return (
<Flex padding={7} justifyContent="center" alignItems="center">
<Loader>Loading content...</Loader>
</Flex>
);
}

const { action, user, payload } = data;

return (
<>
<Box marginBottom={3}>
<Typography variant="delta" id="title">
{formatMessage({
id: 'Settings.permissions.auditLogs.details',
defaultMessage: 'Log Details',
})}
</Typography>
</Box>
<Grid
gap={4}
gridCols={2}
paddingTop={4}
paddingBottom={4}
paddingLeft={6}
paddingRight={6}
marginBottom={4}
background="neutral100"
hasRadius
>
<ActionItem
actionLabel={formatMessage({
id: 'Settings.permissions.auditLogs.action',
defaultMessage: 'Action',
})}
actionName={formatMessage(
{
id: `Settings.permissions.auditLogs.${action}`,
defaultMessage: getDefaultMessage(action),
},
{ model: payload?.model }
)}
/>
<ActionItem
actionLabel={formatMessage({
id: 'Settings.permissions.auditLogs.date',
defaultMessage: 'Date',
})}
actionName={formattedDate}
/>
<ActionItem
actionLabel={formatMessage({
id: 'Settings.permissions.auditLogs.user',
defaultMessage: 'User',
})}
actionName={user?.fullname || '-'}
/>
<ActionItem
actionLabel={formatMessage({
id: 'Settings.permissions.auditLogs.userId',
defaultMessage: 'User ID',
})}
actionName={user?.id.toString() || '-'}
/>
</Grid>
<JSONInput
value={JSON.stringify(payload, null, 2)}
disabled
height={pxToRem(150)}
label={formatMessage({
id: 'Settings.permissions.auditLogs.payload',
defaultMessage: 'Payload',
})}
/>
</>
);
};

ActionBody.defaultProps = {
data: {},
};

ActionBody.propTypes = {
status: PropTypes.oneOf(['idle', 'loading', 'error', 'success']).isRequired,
data: PropTypes.shape({
action: PropTypes.string,
date: PropTypes.string,
payload: PropTypes.object,
user: PropTypes.object,
}),
formattedDate: PropTypes.string.isRequired,
};

export default ActionBody;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Flex } from '@strapi/design-system/Flex';
import { Typography } from '@strapi/design-system/Typography';

const ActionItem = ({ actionLabel, actionName }) => {
return (
<Flex direction="column" alignItems="baseline" gap={1}>
<Typography textColor="neutral600" variant="sigma">
{actionLabel}
</Typography>
<Typography textColor="neutral600">{actionName}</Typography>
</Flex>
);
};

ActionItem.propTypes = {
actionLabel: PropTypes.string.isRequired,
actionName: PropTypes.string.isRequired,
};

export default ActionItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useQuery } from 'react-query';
import { ModalLayout, ModalHeader, ModalBody } from '@strapi/design-system/ModalLayout';
import { Breadcrumbs, Crumb } from '@strapi/design-system/Breadcrumbs';
import { useNotification, useFetchClient } from '@strapi/helper-plugin';
import useFormatTimeStamp from '../hooks/useFormatTimeStamp';
import ActionBody from './ActionBody';

const Modal = ({ handleClose, logId }) => {
const { get } = useFetchClient();
const toggleNotification = useNotification();

const fetchAuditLog = async (id) => {
const { data } = await get(`/admin/audit-logs/${id}`);

if (!data) {
throw new Error('Audit log not found');
}

return data;
};

const { data, status } = useQuery(['audit-log', logId], () => fetchAuditLog(logId), {
onError() {
toggleNotification({
type: 'warning',
message: { id: 'notification.error', defaultMessage: 'An error occured' },
});
handleClose();
},
});

const formatTimeStamp = useFormatTimeStamp();
const formattedDate = data ? formatTimeStamp(data.date) : '';

return (
<ModalLayout onClose={handleClose} labelledBy="title">
<ModalHeader>
<Breadcrumbs label={formattedDate} id="title">
<Crumb>{formattedDate}</Crumb>
</Breadcrumbs>
</ModalHeader>
<ModalBody>
<ActionBody status={status} data={data} formattedDate={formattedDate} />
</ModalBody>
</ModalLayout>
);
};

Modal.propTypes = {
handleClose: PropTypes.func.isRequired,
logId: PropTypes.string.isRequired,
};

export default Modal;