mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 01:09:49 +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 NOT_ALLOWED_FILTERS = ['json', 'component', 'media', 'richtext', 'dynamiczone', 'password'];
|
||||||
const TIMESTAMPS = ['createdAt', 'updatedAt'];
|
const TIMESTAMPS = ['createdAt', 'updatedAt'];
|
||||||
|
const CREATOR_ATTRIBUTES = ['createdBy', 'updatedBy'];
|
||||||
|
|
||||||
const useAllowedAttributes = (contentType, slug) => {
|
const useAllowedAttributes = (contentType, slug) => {
|
||||||
const { allPermissions } = useRBACProvider();
|
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 readPermissionForAttr = get(readPermissionsForSlug, ['0', 'properties', 'fields'], []);
|
||||||
const attributesArray = Object.keys(get(contentType, ['attributes']), {});
|
const attributesArray = Object.keys(get(contentType, ['attributes']), {});
|
||||||
const allowedAttributes = attributesArray
|
const allowedAttributes = attributesArray
|
||||||
@ -39,6 +48,10 @@ const useAllowedAttributes = (contentType, slug) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CREATOR_ATTRIBUTES.includes(attr) && !canReadAdminUsers) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.sort((a, b) => formatter.compare(a, b));
|
.sort((a, b) => formatter.compare(a, b));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user