mirror of
https://github.com/strapi/strapi.git
synced 2025-11-23 21:53:05 +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()
|
.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()),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -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",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@ -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()
|
||||||
|
|||||||
@ -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,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
@ -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 => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user