Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
Pierre Noël 2020-06-10 15:42:32 +02:00 committed by Alexandre Bodin
parent 22fb227b96
commit 3aec039698
6 changed files with 24 additions and 41 deletions

View File

@ -14,7 +14,7 @@ const updatePermissionsSchema = yup
.object() .object()
.shape({ .shape({
action: yup.string().required(), action: yup.string().required(),
subject: yup.string(), subject: yup.string().nullable(),
fields: yup.array().of(yup.string()), fields: yup.array().of(yup.string()),
conditions: yup.array().of(yup.string()), conditions: yup.array().of(yup.string()),
}) })

View File

@ -9,9 +9,6 @@ Object {
"action": "plugins::content-manager.create", "action": "plugins::content-manager.create",
"displayName": "Create", "displayName": "Create",
"subjects": Array [ "subjects": Array [
"strapi::permission",
"strapi::role",
"strapi::user",
"plugins::users-permissions.user", "plugins::users-permissions.user",
], ],
}, },
@ -19,9 +16,6 @@ Object {
"action": "plugins::content-manager.read", "action": "plugins::content-manager.read",
"displayName": "Read", "displayName": "Read",
"subjects": Array [ "subjects": Array [
"strapi::permission",
"strapi::role",
"strapi::user",
"plugins::users-permissions.user", "plugins::users-permissions.user",
], ],
}, },
@ -29,9 +23,6 @@ Object {
"action": "plugins::content-manager.update", "action": "plugins::content-manager.update",
"displayName": "Update", "displayName": "Update",
"subjects": Array [ "subjects": Array [
"strapi::permission",
"strapi::role",
"strapi::user",
"plugins::users-permissions.user", "plugins::users-permissions.user",
], ],
}, },
@ -39,9 +30,6 @@ Object {
"action": "plugins::content-manager.delete", "action": "plugins::content-manager.delete",
"displayName": "Delete", "displayName": "Delete",
"subjects": Array [ "subjects": Array [
"strapi::permission",
"strapi::role",
"strapi::user",
"plugins::users-permissions.user", "plugins::users-permissions.user",
], ],
}, },

View File

@ -31,7 +31,7 @@ const registerProviderActionSchema = yup
is: 'contentTypes', is: 'contentTypes',
then: yup then: yup
.array() .array()
.of(validators.isAContentTypeId) .of(yup.string())
.required(), .required(),
otherwise: yup otherwise: yup
.mixed() .mixed()
@ -39,21 +39,28 @@ const registerProviderActionSchema = yup
}), }),
displayName: yup.string().required(), displayName: yup.string().required(),
category: yup.mixed().when('section', { category: yup.mixed().when('section', {
is: val => ['plugins', 'contentTypes'].includes(val), is: 'settings',
then: yup then: yup.string().required(),
otherwise: yup
.mixed() .mixed()
.oneOf([undefined], 'category should only be defined for the "settings" section'), .test(
otherwise: yup.string().required(), 'settingsCategory',
'category should only be defined for the "settings" section',
cat => cat === undefined
),
}), }),
subCategory: yup.mixed().when('section', { subCategory: yup.mixed().when('section', {
is: 'contentTypes', is: section => ['settings', 'plugins'].includes(section),
then: yup then: yup.string(),
otherwise: yup
.mixed() .mixed()
.oneOf( .test(
[undefined], 'settingsSubCategory',
'subCategory should only be defined for "plugins" and "settings" sections' 'subCategory should only be defined for "plugins" and "settings" sections',
subCat => {
return subCat === undefined;
}
), ),
otherwise: yup.string(),
}), }),
}) })
.noUnknown() .noUnknown()

View File

@ -30,20 +30,6 @@ const isAPluginName = yup
: this.createError({ path: this.path, message: `${this.path} is not an existing plugin` }); : 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 = { module.exports = {
email, email,
firstname, firstname,
@ -52,5 +38,4 @@ module.exports = {
password, password,
roles, roles,
isAPluginName, isAPluginName,
isAContentTypeId,
}; };

View File

@ -5,7 +5,7 @@ const { yup, formatYupErrors } = require('strapi-utils');
const handleReject = error => Promise.reject(formatYupErrors(error)); const handleReject = error => Promise.reject(formatYupErrors(error));
// --- validatedUpdatePermissionsInput // validatedUpdatePermissionsInput
const BONDED_ACTIONS = [ const BONDED_ACTIONS = [
'plugins::content-manager.read', 'plugins::content-manager.read',
@ -75,7 +75,7 @@ const validatedUpdatePermissionsInput = data => {
.catch(handleReject); .catch(handleReject);
}; };
// --- validatePermissionsExist // validatePermissionsExist
const checkPermissionsExist = function(permissions) { const checkPermissionsExist = function(permissions) {
const existingActions = strapi.admin.services.permission.provider.getAll(); const existingActions = strapi.admin.services.permission.provider.getAll();

View File

@ -27,6 +27,9 @@ const HIDDEN_CONTENT_TYPES = [
'plugins::upload.file', 'plugins::upload.file',
'plugins::users-permissions.permission', 'plugins::users-permissions.permission',
'plugins::users-permissions.role', 'plugins::users-permissions.role',
'strapi::permission',
'strapi::role',
'strapi::user',
]; ];
const getConfiguration = uid => { const getConfiguration = uid => {