forked from strapi/strapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request strapi#15536 from strapi/feature/audit-logs
- Loading branch information
Showing
66 changed files
with
2,839 additions
and
555 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
examples/getstarted/src/api/address/content-types/address/lifecycles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/core/admin/admin/src/hooks/useSettingsMenu/utils/adminLinks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
1 change: 1 addition & 0 deletions
1
packages/core/admin/admin/src/hooks/useSettingsMenu/utils/customAdminLinks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default []; |
21 changes: 21 additions & 0 deletions
21
packages/core/admin/admin/src/hooks/useSettingsMenu/utils/defaultAdminLinks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/core/admin/ee/admin/hooks/useSettingsMenu/utils/customAdminLinks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
111 changes: 111 additions & 0 deletions
111
packages/core/admin/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/Modal/ActionBody.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
22 changes: 22 additions & 0 deletions
22
packages/core/admin/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/Modal/ActionItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
56 changes: 56 additions & 0 deletions
56
packages/core/admin/ee/admin/pages/SettingsPage/pages/AuditLogs/ListView/Modal/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.