2017-11-06 11:14:43 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-11-16 17:59:41 +01:00
|
|
|
const fakeData = require('../config/fakeData.json');
|
|
|
|
const _ = require('lodash');
|
2017-11-06 11:14:43 +01:00
|
|
|
/**
|
|
|
|
* UsersPermissions.js service
|
|
|
|
*
|
|
|
|
* @description: A set of functions similar to controller's actions to avoid code duplication.
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = {
|
2017-11-16 17:59:41 +01:00
|
|
|
getActions: () => {
|
2017-11-17 12:14:12 +01:00
|
|
|
|
|
|
|
// TODO
|
2017-11-16 17:59:41 +01:00
|
|
|
const appControllers = Object.keys(strapi.api).reduce((acc, key) => {
|
|
|
|
const actions = Object.keys(strapi.api[key].controllers[key]).reduce((obj, k) => {
|
|
|
|
obj[k] = { enabled: false, policy: 'test' };
|
2017-11-06 11:14:43 +01:00
|
|
|
|
2017-11-16 17:59:41 +01:00
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
acc.controllers[key] = actions;
|
|
|
|
|
|
|
|
return acc;
|
2017-11-17 12:14:12 +01:00
|
|
|
}, { controllers: {} });
|
|
|
|
|
|
|
|
const pluginsPermissions = Object.keys(strapi.plugins).reduce((acc, key) => {
|
|
|
|
const pluginControllers = Object.keys(strapi.plugins[key].controllers).reduce((obj, k) => {
|
|
|
|
const actions = Object.keys(strapi.plugins[key].controllers[k]).reduce((obj, k) => {
|
|
|
|
obj[k] = { enabled: false, policy: 'test' };
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
obj.icon = strapi.plugins[key].package.strapi.icon;
|
|
|
|
obj.controllers[k] = actions;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
}, { icon: '', controllers: {} });
|
|
|
|
|
|
|
|
acc[key] = pluginControllers;
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2017-11-16 17:59:41 +01:00
|
|
|
|
|
|
|
const permissions = {
|
|
|
|
application: {
|
|
|
|
icon: '',
|
|
|
|
controllers: appControllers.controllers,
|
2017-11-17 12:14:12 +01:00
|
|
|
},
|
2017-11-16 17:59:41 +01:00
|
|
|
};
|
|
|
|
|
2017-11-17 12:14:12 +01:00
|
|
|
const allPermissions = _.merge(permissions, pluginsPermissions);
|
|
|
|
|
|
|
|
return allPermissions;
|
|
|
|
}
|
2017-11-06 11:14:43 +01:00
|
|
|
};
|