mirror of
https://github.com/strapi/strapi.git
synced 2025-10-27 16:10:08 +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) {
|
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)) {
|
if ((cluster.isWorker && strapi.config.reload.workers > 0) || (cluster.isMaster && strapi.config.reload.workers < 1)) {
|
||||||
let route;
|
let route;
|
||||||
let controller;
|
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.
|
// Add the `dashboardPolicy` to the list of policies.
|
||||||
if (strapi.config.dashboard.enabled) {
|
if (strapi.config.dashboard.enabled) {
|
||||||
strapi.policies.dashboardToken = dashboardTokenPolicy;
|
strapi.policies.dashboardToken = dashboardTokenPolicy;
|
||||||
@ -89,7 +91,7 @@ module.exports = function (strapi) {
|
|||||||
policies = [];
|
policies = [];
|
||||||
|
|
||||||
// Add the `globalPolicy`.
|
// Add the `globalPolicy`.
|
||||||
policies.push(globalPolicy(endpoint, route));
|
policies.push(globalPolicy(endpoint, value, route));
|
||||||
|
|
||||||
if (_.isArray(value.policies) && !_.isEmpty(value.policies)) {
|
if (_.isArray(value.policies) && !_.isEmpty(value.policies)) {
|
||||||
_.forEach(value.policies, function (policy) {
|
_.forEach(value.policies, function (policy) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user