2020-05-19 16:11:19 +02:00
|
|
|
'use strict';
|
|
|
|
|
2021-11-03 19:31:57 +01:00
|
|
|
const { yup, validateYupSchema } = require('@strapi/utils');
|
2020-05-19 16:11:19 +02:00
|
|
|
|
2023-03-06 21:46:45 +01:00
|
|
|
const roleCreateSchema = yup
|
|
|
|
.object()
|
|
|
|
.shape({
|
|
|
|
name: yup.string().min(1).required(),
|
|
|
|
description: yup.string().nullable(),
|
|
|
|
})
|
|
|
|
.noUnknown();
|
|
|
|
|
|
|
|
const rolesDeleteSchema = yup
|
|
|
|
.object()
|
|
|
|
.shape({
|
|
|
|
ids: yup
|
|
|
|
.array()
|
|
|
|
.of(yup.strapiID())
|
|
|
|
.min(1)
|
|
|
|
.required()
|
|
|
|
.test('roles-deletion-checks', 'Roles deletion checks have failed', async function (ids) {
|
|
|
|
try {
|
|
|
|
await strapi.admin.services.role.checkRolesIdForDeletion(ids);
|
|
|
|
} catch (e) {
|
|
|
|
return this.createError({ path: 'ids', message: e.message });
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.noUnknown();
|
|
|
|
|
|
|
|
const roleDeleteSchema = yup
|
|
|
|
.strapiID()
|
|
|
|
.required()
|
|
|
|
.test('no-admin-single-delete', 'Role deletion checks have failed', async function (id) {
|
|
|
|
try {
|
|
|
|
await strapi.admin.services.role.checkRolesIdForDeletion([id]);
|
|
|
|
} catch (e) {
|
|
|
|
return this.createError({ path: 'id', message: e.message });
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2020-05-19 16:11:19 +02:00
|
|
|
const roleUpdateSchema = yup
|
|
|
|
.object()
|
|
|
|
.shape({
|
2020-07-17 10:48:51 +02:00
|
|
|
name: yup.string().min(1),
|
2020-06-04 10:25:02 +02:00
|
|
|
description: yup.string().nullable(),
|
2020-05-19 16:11:19 +02:00
|
|
|
})
|
|
|
|
.noUnknown();
|
|
|
|
|
|
|
|
module.exports = {
|
2021-11-03 19:31:57 +01:00
|
|
|
validateRoleUpdateInput: validateYupSchema(roleUpdateSchema),
|
2023-03-06 21:46:45 +01:00
|
|
|
validateRoleCreateInput: validateYupSchema(roleCreateSchema),
|
|
|
|
validateRolesDeleteInput: validateYupSchema(rolesDeleteSchema),
|
|
|
|
validateRoleDeleteInput: validateYupSchema(roleDeleteSchema),
|
2020-05-19 16:11:19 +02:00
|
|
|
};
|