mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Fix pr comments
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
parent
a559047e77
commit
a5df905e00
@ -1,11 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const { map, filter } = require('lodash/fp');
|
||||
const { generateTimestampCode, stringIncludes } = require('strapi-utils');
|
||||
const { SUPER_ADMIN_CODE } = require('./constants');
|
||||
const { createPermission } = require('../domain/permission');
|
||||
|
||||
const ACTIONS = {
|
||||
publish: 'plugins::content-manager.explorer.publish',
|
||||
};
|
||||
|
||||
const sanitizeRole = role => {
|
||||
return _.omit(role, ['users', 'permissions']);
|
||||
};
|
||||
@ -221,15 +224,9 @@ const createRolesIfNoneExist = async ({ createPermissionsForAdmin = false } = {}
|
||||
}
|
||||
);
|
||||
|
||||
const addIsCreatorCondition = map(p => _.merge({}, p, { conditions: ['admin::is-creator'] }));
|
||||
const removeRestrictedActions = filter(
|
||||
p => !['plugins::content-manager.explorer.publish'].includes(p.action)
|
||||
);
|
||||
|
||||
const authorPermissions = _.flow(
|
||||
removeRestrictedActions,
|
||||
addIsCreatorCondition
|
||||
)(editorPermissions);
|
||||
const authorPermissions = editorPermissions
|
||||
.filter(({ action }) => action !== ACTIONS.publish)
|
||||
.map(p => _.merge({}, p, { conditions: ['admin::is-creator'] }));
|
||||
|
||||
editorPermissions.push(...getDefaultPluginPermissions());
|
||||
authorPermissions.push(...getDefaultPluginPermissions({ isAuthor: true }));
|
||||
|
||||
@ -55,6 +55,18 @@ const checkNoDuplicatedPermissions = permissions =>
|
||||
permissions.slice(i + 1).every(permB => !permissionsAreEquals(permA, permB))
|
||||
);
|
||||
|
||||
const checkNilFields = function(fields) {
|
||||
// If the parent has no action field, then we ignore this test
|
||||
if (_.isNil(this.parent.action)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { actionProvider } = strapi.admin.services.permission;
|
||||
const action = actionProvider.getByActionId(this.parent.action);
|
||||
|
||||
return actionDomain.hasFieldsRestriction(action) || _.isNil(fields);
|
||||
};
|
||||
|
||||
const updatePermissions = yup
|
||||
.object()
|
||||
.shape({
|
||||
@ -84,24 +96,14 @@ const updatePermissions = yup
|
||||
.test(
|
||||
'fields-restriction',
|
||||
'The permission at ${path} must have fields set to null or undefined',
|
||||
function(fields) {
|
||||
// If the parent has no action field, then we ignore this test
|
||||
if (_.isNil(this.parent.action)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { actionProvider } = strapi.admin.services.permission;
|
||||
const action = actionProvider.getByActionId(this.parent.action);
|
||||
|
||||
return actionDomain.hasFieldsRestriction(action) || _.isNil(fields);
|
||||
}
|
||||
checkNilFields
|
||||
),
|
||||
conditions: yup.array().of(yup.string()),
|
||||
})
|
||||
.noUnknown()
|
||||
)
|
||||
.test(
|
||||
'delete-fields-are-null',
|
||||
'duplicated-permissions',
|
||||
'Some permissions are duplicated (same action and subject)',
|
||||
checkNoDuplicatedPermissions
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user