mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 09:14:49 +00:00
37 lines
822 B
JavaScript
37 lines
822 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const { yup, formatYupErrors } = require('strapi-utils');
|
||
|
|
||
|
const handleReject = error => Promise.reject(formatYupErrors(error));
|
||
|
|
||
|
const updatePermissionsSchema = yup
|
||
|
.object()
|
||
|
.shape({
|
||
|
permissions: yup
|
||
|
.array()
|
||
|
.of(
|
||
|
yup
|
||
|
.object()
|
||
|
.shape({
|
||
|
action: yup.string().required(),
|
||
|
subject: yup.string(),
|
||
|
fields: yup.array().of(yup.string()),
|
||
|
conditions: yup.array().of(yup.string()),
|
||
|
})
|
||
|
.noUnknown()
|
||
|
)
|
||
|
.requiredAllowEmpty(),
|
||
|
})
|
||
|
.required()
|
||
|
.noUnknown();
|
||
|
|
||
|
const validatedUpdatePermissionsInput = data => {
|
||
|
return updatePermissionsSchema
|
||
|
.validate(data, { strict: true, abortEarly: false })
|
||
|
.catch(handleReject);
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
validatedUpdatePermissionsInput,
|
||
|
};
|