mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
show creator fields only if user has admin read permissions
This commit is contained in:
parent
43f40db27f
commit
2319c6d15e
@ -5,6 +5,7 @@ import { useIntl } from 'react-intl';
|
||||
|
||||
const NOT_ALLOWED_FILTERS = ['json', 'component', 'media', 'richtext', 'dynamiczone', 'password'];
|
||||
const TIMESTAMPS = ['createdAt', 'updatedAt'];
|
||||
const CREATOR_ATTRIBUTES = ['createdBy', 'updatedBy'];
|
||||
|
||||
const useAllowedAttributes = (contentType, slug) => {
|
||||
const { allPermissions } = useRBACProvider();
|
||||
@ -21,6 +22,14 @@ const useAllowedAttributes = (contentType, slug) => {
|
||||
},
|
||||
]);
|
||||
|
||||
const canReadAdminUsers =
|
||||
findMatchingPermissions(allPermissions, [
|
||||
{
|
||||
action: 'admin::users.read',
|
||||
subject: null,
|
||||
},
|
||||
]).length > 0;
|
||||
|
||||
const readPermissionForAttr = get(readPermissionsForSlug, ['0', 'properties', 'fields'], []);
|
||||
const attributesArray = Object.keys(get(contentType, ['attributes']), {});
|
||||
const allowedAttributes = attributesArray
|
||||
@ -39,6 +48,10 @@ const useAllowedAttributes = (contentType, slug) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CREATOR_ATTRIBUTES.includes(attr) && !canReadAdminUsers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.sort((a, b) => formatter.compare(a, b));
|
||||
|
Loading…
x
Reference in New Issue
Block a user