mirror of
https://github.com/strapi/strapi.git
synced 2025-10-26 23:51:10 +00:00
Merge pull request #26 from wistityhq/improvement/router
Improve router for user permissions
This commit is contained in:
commit
f57cd37512
@ -39,6 +39,22 @@ module.exports = function (strapi) {
|
||||
*/
|
||||
|
||||
initialize: function (cb) {
|
||||
|
||||
// Middleware used for every routes.
|
||||
// Expose the endpoint in `this`.
|
||||
function globalPolicy(endpoint, value, route) {
|
||||
return function * (next) {
|
||||
this.request.route = {
|
||||
endpoint: _.trim(endpoint),
|
||||
controller: _.trim(value.controller),
|
||||
action: _.trim(value.action),
|
||||
splittedEndpoint: _.trim(route.endpoint),
|
||||
verb: route.verb && _.trim(route.verb.toLowerCase())
|
||||
};
|
||||
yield next;
|
||||
};
|
||||
}
|
||||
|
||||
if ((cluster.isWorker && strapi.config.reload.workers > 0) || (cluster.isMaster && strapi.config.reload.workers < 1)) {
|
||||
let route;
|
||||
let controller;
|
||||
@ -52,20 +68,6 @@ module.exports = function (strapi) {
|
||||
});
|
||||
}
|
||||
|
||||
// Middleware used for every routes.
|
||||
// Expose the endpoint in `this`.
|
||||
function globalPolicy(endpoint, route) {
|
||||
return function * (next) {
|
||||
this.request.route = {
|
||||
endpoint: endpoint,
|
||||
controller: route.controller,
|
||||
firstWord: _.startsWith(route.endpoint, '/') ? route.endpoint.split('/')[1] : route.endpoint.split('/')[0],
|
||||
value: route
|
||||
};
|
||||
yield next;
|
||||
};
|
||||
}
|
||||
|
||||
// Add the `dashboardPolicy` to the list of policies.
|
||||
if (strapi.config.dashboard.enabled) {
|
||||
strapi.policies.dashboardToken = dashboardTokenPolicy;
|
||||
@ -89,7 +91,7 @@ module.exports = function (strapi) {
|
||||
policies = [];
|
||||
|
||||
// Add the `globalPolicy`.
|
||||
policies.push(globalPolicy(endpoint, route));
|
||||
policies.push(globalPolicy(endpoint, value, route));
|
||||
|
||||
if (_.isArray(value.policies) && !_.isEmpty(value.policies)) {
|
||||
_.forEach(value.policies, function (policy) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user