mirror of
https://github.com/strapi/strapi.git
synced 2025-11-15 01:28:07 +00:00
Fix RBAC upload permissions (#10484)
* Fix fetch of created_by.roles for the upload permissions' check * Remove console.log * Add default value for the set roles * Fetch the author (user) instead of their roles only * Only populate roles for the author
This commit is contained in:
parent
d66a49f23c
commit
c7c549aee6
@ -199,10 +199,11 @@ const findEntityAndCheckPermissions = async (ability, action, model, id) => {
|
|||||||
|
|
||||||
const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
|
const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
|
||||||
|
|
||||||
const roles = _.has(file, 'created_by.id')
|
const author = await strapi.admin.services.user.findOne({ id: file[CREATED_BY_ATTRIBUTE] }, [
|
||||||
? await strapi.query('role', 'admin').find({ 'users.id': file[CREATED_BY_ATTRIBUTE].id }, [])
|
'roles',
|
||||||
: [];
|
]);
|
||||||
const fileWithRoles = _.set(_.cloneDeep(file), 'created_by.roles', roles);
|
|
||||||
|
const fileWithRoles = _.set(_.cloneDeep(file), 'created_by', author);
|
||||||
|
|
||||||
if (pm.ability.cannot(pm.action, pm.toSubject(fileWithRoles))) {
|
if (pm.ability.cannot(pm.action, pm.toSubject(fileWithRoles))) {
|
||||||
throw strapi.errors.forbidden();
|
throw strapi.errors.forbidden();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user