2020-06-02 17:59:57 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { yup } = require('strapi-utils');
|
|
|
|
|
|
|
|
const registerProviderPermissionSchema = yup
|
|
|
|
.array()
|
|
|
|
.requiredAllowEmpty()
|
|
|
|
.required()
|
|
|
|
.of(
|
|
|
|
yup
|
|
|
|
.object()
|
|
|
|
.shape({
|
|
|
|
name: yup.string().required(),
|
|
|
|
section: yup
|
|
|
|
.string()
|
|
|
|
.oneOf(['contentTypes', 'plugins', 'settings'])
|
|
|
|
.required(),
|
2020-06-04 18:30:26 +02:00
|
|
|
pluginName: yup
|
|
|
|
.string()
|
|
|
|
.required()
|
|
|
|
.isAPluginName(),
|
|
|
|
subjects: yup.mixed().when('section', {
|
2020-06-02 17:59:57 +02:00
|
|
|
is: 'contentTypes',
|
2020-06-04 18:30:26 +02:00
|
|
|
then: yup
|
|
|
|
.array()
|
|
|
|
.of(yup.string().isAContentTypeId())
|
|
|
|
.required(),
|
|
|
|
otherwise: yup.mixed().oneOf([undefined]),
|
2020-06-02 17:59:57 +02:00
|
|
|
}),
|
|
|
|
displayName: yup.string().required(),
|
2020-06-04 18:30:26 +02:00
|
|
|
category: yup.mixed().when('section', {
|
|
|
|
is: val => ['plugins', 'contentTypes'].includes(val),
|
|
|
|
then: yup.mixed().oneOf([undefined]),
|
|
|
|
otherwise: yup.string().required(),
|
|
|
|
}),
|
|
|
|
subCategory: yup.mixed().when('section', {
|
|
|
|
is: 'contentTypes',
|
|
|
|
then: yup.mixed().oneOf([undefined]),
|
|
|
|
otherwise: yup.string(),
|
|
|
|
}),
|
2020-06-02 17:59:57 +02:00
|
|
|
conditions: yup.array().of(yup.string()),
|
|
|
|
})
|
|
|
|
.noUnknown()
|
|
|
|
);
|
|
|
|
|
|
|
|
const validateRegisterProviderPermission = data => {
|
|
|
|
try {
|
|
|
|
registerProviderPermissionSchema.validateSync(data, { strict: true, abortEarly: false });
|
|
|
|
} catch (e) {
|
2020-06-04 18:30:26 +02:00
|
|
|
if (e.errors.length > 0) {
|
|
|
|
throw new yup.ValidationError(e.errors.join(', '));
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
2020-06-02 17:59:57 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
validateRegisterProviderPermission,
|
|
|
|
};
|