35 lines
849 B
JavaScript
Raw Normal View History

2021-04-08 19:36:28 +02:00
'use strict';
const { isNil } = require('lodash/fp');
const { getService } = require('../utils');
const { AUTHOR_CODE, PUBLISH_ACTION } = require('./constants');
// TODO: move actionProvider here instead of in the permission service
/**
* Returns actions available for a role.
2021-04-09 16:20:53 +02:00
* @param {string|number} roleId
2021-04-08 19:36:28 +02:00
* @returns {object[]}
*/
2021-04-09 16:20:53 +02:00
const getAllowedActionsForRole = async roleId => {
2021-04-08 19:36:28 +02:00
const { actionProvider } = getService('permission');
if (!isNil(roleId)) {
const role = await getService('role').findOne({ id: roleId });
if (!role) {
throw new strapi.errors.notFound('role.notFound');
}
if (role.code === AUTHOR_CODE) {
2021-04-09 16:20:53 +02:00
return actionProvider.values().filter(({ actionId }) => actionId !== PUBLISH_ACTION);
2021-04-08 19:36:28 +02:00
}
}
return actionProvider.values();
};
module.exports = {
2021-04-09 16:20:53 +02:00
getAllowedActionsForRole,
2021-04-08 19:36:28 +02:00
};