2017-11-27 10:59:24 +01:00
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
2017-11-24 15:15:02 +01:00
|
|
|
|
module.exports = strapi => {
|
|
|
|
|
return {
|
2017-11-28 10:02:30 +01:00
|
|
|
|
beforeInitialize: function() {
|
|
|
|
|
strapi.config.middleware.load.before.unshift('users-permissions');
|
|
|
|
|
},
|
|
|
|
|
|
2017-11-24 15:15:02 +01:00
|
|
|
|
initialize: function(cb) {
|
2017-11-27 10:59:24 +01:00
|
|
|
|
_.forEach(strapi.config.routes, value => {
|
2017-12-08 11:21:51 +01:00
|
|
|
|
if (_.get(value.config, 'policies')) {
|
|
|
|
|
value.config.policies.unshift('plugins.users-permissions.permissions');
|
|
|
|
|
}
|
2017-11-24 15:15:02 +01:00
|
|
|
|
});
|
|
|
|
|
|
2017-11-27 10:59:24 +01:00
|
|
|
|
if (strapi.plugins) {
|
|
|
|
|
_.forEach(strapi.plugins, (plugin, name) => {
|
|
|
|
|
_.forEach(plugin.config.routes, value => {
|
2017-12-08 11:21:51 +01:00
|
|
|
|
if (_.get(value.config, 'policies')) {
|
|
|
|
|
value.config.policies.unshift('plugins.users-permissions.permissions');
|
|
|
|
|
}
|
2017-11-27 10:59:24 +01:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-24 15:15:02 +01:00
|
|
|
|
cb();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|