mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
refacto
Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
parent
22fb227b96
commit
3aec039698
@ -14,7 +14,7 @@ const updatePermissionsSchema = yup
|
||||
.object()
|
||||
.shape({
|
||||
action: yup.string().required(),
|
||||
subject: yup.string(),
|
||||
subject: yup.string().nullable(),
|
||||
fields: yup.array().of(yup.string()),
|
||||
conditions: yup.array().of(yup.string()),
|
||||
})
|
||||
|
||||
@ -9,9 +9,6 @@ Object {
|
||||
"action": "plugins::content-manager.create",
|
||||
"displayName": "Create",
|
||||
"subjects": Array [
|
||||
"strapi::permission",
|
||||
"strapi::role",
|
||||
"strapi::user",
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
@ -19,9 +16,6 @@ Object {
|
||||
"action": "plugins::content-manager.read",
|
||||
"displayName": "Read",
|
||||
"subjects": Array [
|
||||
"strapi::permission",
|
||||
"strapi::role",
|
||||
"strapi::user",
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
@ -29,9 +23,6 @@ Object {
|
||||
"action": "plugins::content-manager.update",
|
||||
"displayName": "Update",
|
||||
"subjects": Array [
|
||||
"strapi::permission",
|
||||
"strapi::role",
|
||||
"strapi::user",
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
@ -39,9 +30,6 @@ Object {
|
||||
"action": "plugins::content-manager.delete",
|
||||
"displayName": "Delete",
|
||||
"subjects": Array [
|
||||
"strapi::permission",
|
||||
"strapi::role",
|
||||
"strapi::user",
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
|
||||
@ -31,7 +31,7 @@ const registerProviderActionSchema = yup
|
||||
is: 'contentTypes',
|
||||
then: yup
|
||||
.array()
|
||||
.of(validators.isAContentTypeId)
|
||||
.of(yup.string())
|
||||
.required(),
|
||||
otherwise: yup
|
||||
.mixed()
|
||||
@ -39,21 +39,28 @@ const registerProviderActionSchema = yup
|
||||
}),
|
||||
displayName: yup.string().required(),
|
||||
category: yup.mixed().when('section', {
|
||||
is: val => ['plugins', 'contentTypes'].includes(val),
|
||||
then: yup
|
||||
is: 'settings',
|
||||
then: yup.string().required(),
|
||||
otherwise: yup
|
||||
.mixed()
|
||||
.oneOf([undefined], 'category should only be defined for the "settings" section'),
|
||||
otherwise: yup.string().required(),
|
||||
.test(
|
||||
'settingsCategory',
|
||||
'category should only be defined for the "settings" section',
|
||||
cat => cat === undefined
|
||||
),
|
||||
}),
|
||||
subCategory: yup.mixed().when('section', {
|
||||
is: 'contentTypes',
|
||||
then: yup
|
||||
is: section => ['settings', 'plugins'].includes(section),
|
||||
then: yup.string(),
|
||||
otherwise: yup
|
||||
.mixed()
|
||||
.oneOf(
|
||||
[undefined],
|
||||
'subCategory should only be defined for "plugins" and "settings" sections'
|
||||
.test(
|
||||
'settingsSubCategory',
|
||||
'subCategory should only be defined for "plugins" and "settings" sections',
|
||||
subCat => {
|
||||
return subCat === undefined;
|
||||
}
|
||||
),
|
||||
otherwise: yup.string(),
|
||||
}),
|
||||
})
|
||||
.noUnknown()
|
||||
|
||||
@ -30,20 +30,6 @@ const isAPluginName = yup
|
||||
: this.createError({ path: this.path, message: `${this.path} is not an existing plugin` });
|
||||
});
|
||||
|
||||
const isAContentTypeId = yup
|
||||
.string()
|
||||
.test('is-a-contentType-id', 'is not a content-type id', function(value) {
|
||||
const contentTypesUids = strapi.plugins[
|
||||
'content-manager'
|
||||
].services.contenttypes.getDisplayedContentTypesUids();
|
||||
return contentTypesUids.includes(value)
|
||||
? true
|
||||
: this.createError({
|
||||
path: this.path,
|
||||
message: `${this.path} is not an existing content-type id`,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
email,
|
||||
firstname,
|
||||
@ -52,5 +38,4 @@ module.exports = {
|
||||
password,
|
||||
roles,
|
||||
isAPluginName,
|
||||
isAContentTypeId,
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@ const { yup, formatYupErrors } = require('strapi-utils');
|
||||
|
||||
const handleReject = error => Promise.reject(formatYupErrors(error));
|
||||
|
||||
// --- validatedUpdatePermissionsInput
|
||||
// validatedUpdatePermissionsInput
|
||||
|
||||
const BONDED_ACTIONS = [
|
||||
'plugins::content-manager.read',
|
||||
@ -75,7 +75,7 @@ const validatedUpdatePermissionsInput = data => {
|
||||
.catch(handleReject);
|
||||
};
|
||||
|
||||
// --- validatePermissionsExist
|
||||
// validatePermissionsExist
|
||||
|
||||
const checkPermissionsExist = function(permissions) {
|
||||
const existingActions = strapi.admin.services.permission.provider.getAll();
|
||||
|
||||
@ -27,6 +27,9 @@ const HIDDEN_CONTENT_TYPES = [
|
||||
'plugins::upload.file',
|
||||
'plugins::users-permissions.permission',
|
||||
'plugins::users-permissions.role',
|
||||
'strapi::permission',
|
||||
'strapi::role',
|
||||
'strapi::user',
|
||||
];
|
||||
|
||||
const getConfiguration = uid => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user