mirror of
https://github.com/strapi/strapi.git
synced 2025-08-02 13:58:18 +00:00
Allows global and namespaced policies
This commit is contained in:
parent
7b09d9f539
commit
5a9ca376db
@ -210,7 +210,7 @@ module.exports = strapi => {
|
|||||||
// Retrieve the API's name where the controller is located
|
// Retrieve the API's name where the controller is located
|
||||||
// to access to the right validators
|
// to access to the right validators
|
||||||
const api = finder(strapi.api, controller);
|
const api = finder(strapi.api, controller);
|
||||||
const validator = _.get(strapi.api, api + '.config.validators.' + value.config.validate);
|
const validator = _.get(strapi.api, api + '.validators.' + value.config.validate);
|
||||||
|
|
||||||
_.merge(validate, _.mapValues(validator, value => {
|
_.merge(validate, _.mapValues(validator, value => {
|
||||||
return builder.build(value);
|
return builder.build(value);
|
||||||
|
@ -79,15 +79,24 @@ module.exports = strapi => {
|
|||||||
}, cb);
|
}, cb);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Load API policies from `./api/*/policies/*.js`.
|
// Load API policies from `./api/*/config/policies/*.js`.
|
||||||
'policies/*': cb => {
|
'policies/*': cb => {
|
||||||
dictionary.aggregate({
|
dictionary.optional({
|
||||||
dirname: path.resolve(strapi.config.appPath, strapi.config.paths.api, api, strapi.config.paths.policies),
|
dirname: path.resolve(strapi.config.appPath, strapi.config.paths.api, api, strapi.config.paths.config, strapi.config.paths.policies),
|
||||||
filter: /(.+)\.(js)$/,
|
filter: /(.+)\.(js)$/,
|
||||||
depth: 1
|
depth: 1
|
||||||
}, cb);
|
}, cb);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Load API validators from `./api/*/config/validators/*.js`.
|
||||||
|
'validators/*': cb => {
|
||||||
|
dictionary.optional({
|
||||||
|
dirname: path.resolve(strapi.config.appPath, strapi.config.paths.api, api, strapi.config.paths.config, strapi.config.paths.validators),
|
||||||
|
filter: /(.+)\.(json|js)$/,
|
||||||
|
depth: 1
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
|
||||||
// Load API config from `./api/*/config/*.js|json` and `./api/*/config/environments/**/*.js|json`.
|
// Load API config from `./api/*/config/*.js|json` and `./api/*/config/environments/**/*.js|json`.
|
||||||
'config/**': cb => {
|
'config/**': cb => {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@ -99,13 +108,6 @@ module.exports = strapi => {
|
|||||||
depth: 2
|
depth: 2
|
||||||
}, cb);
|
}, cb);
|
||||||
},
|
},
|
||||||
validators: cb => {
|
|
||||||
dictionary.aggregate({
|
|
||||||
dirname: path.resolve(strapi.config.appPath, strapi.config.paths.api, api, strapi.config.paths.config, 'validators'),
|
|
||||||
filter: /(.+)\.(js|json)$/,
|
|
||||||
depth: 2
|
|
||||||
}, cb);
|
|
||||||
},
|
|
||||||
specific: cb => {
|
specific: cb => {
|
||||||
dictionary.aggregate({
|
dictionary.aggregate({
|
||||||
dirname: path.resolve(strapi.config.appPath, strapi.config.paths.api, api, strapi.config.paths.config, 'environments', strapi.config.environment),
|
dirname: path.resolve(strapi.config.appPath, strapi.config.paths.api, api, strapi.config.paths.config, 'environments', strapi.config.environment),
|
||||||
@ -118,7 +120,7 @@ module.exports = strapi => {
|
|||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cb(null, _.merge(config.common, config.specific, {validators: config.validators}));
|
return cb(null, _.merge(config.common, config.specific));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -137,6 +139,7 @@ module.exports = strapi => {
|
|||||||
models: api['models/*'],
|
models: api['models/*'],
|
||||||
services: api['services/*'],
|
services: api['services/*'],
|
||||||
policies: api['policies/*'],
|
policies: api['policies/*'],
|
||||||
|
validators: api['validators/*'],
|
||||||
config: api['config/**']
|
config: api['config/**']
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -158,9 +161,6 @@ module.exports = strapi => {
|
|||||||
// Merge API models with the main ones.
|
// Merge API models with the main ones.
|
||||||
strapi.models = _.merge({}, strapi.models, _.get(strapi.api, api.name + '.models'));
|
strapi.models = _.merge({}, strapi.models, _.get(strapi.api, api.name + '.models'));
|
||||||
|
|
||||||
// Merge API policies with the main ones.
|
|
||||||
strapi.policies = _.merge({}, strapi.policies, _.get(strapi.api, api.name + '.policies'));
|
|
||||||
|
|
||||||
// Merge API routes with the main ones.
|
// Merge API routes with the main ones.
|
||||||
strapi.config.routes = _.union([], strapi.config.routes, _.get(strapi.api, api.name + '.config.routes'));
|
strapi.config.routes = _.union([], strapi.config.routes, _.get(strapi.api, api.name + '.config.routes'));
|
||||||
});
|
});
|
||||||
|
@ -78,6 +78,15 @@ module.exports = strapi => {
|
|||||||
}, cb);
|
}, cb);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Load global policies from `./config/policies/*.js`..
|
||||||
|
'config/policies/*': cb => {
|
||||||
|
dictionary.optional({
|
||||||
|
dirname: path.resolve(strapi.config.appPath, strapi.config.paths.config, 'policies'),
|
||||||
|
filter: /(.+)\.(js)$/,
|
||||||
|
depth: 1
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
|
||||||
// Load APIs from `./api/**/*.js|json`.
|
// Load APIs from `./api/**/*.js|json`.
|
||||||
'api/**': cb => {
|
'api/**': cb => {
|
||||||
dictionary.optional({
|
dictionary.optional({
|
||||||
@ -126,6 +135,9 @@ module.exports = strapi => {
|
|||||||
// Merge default config and user loaded config together inside `strapi.config`.
|
// Merge default config and user loaded config together inside `strapi.config`.
|
||||||
strapi.config = _.merge(strapi.config, mergedConfig, packageJSON);
|
strapi.config = _.merge(strapi.config, mergedConfig, packageJSON);
|
||||||
|
|
||||||
|
// Exposer global policies
|
||||||
|
strapi.policies = _.merge({}, config['config/policies/*']);
|
||||||
|
|
||||||
// Expose user APIs.
|
// Expose user APIs.
|
||||||
strapi.api = config['api/**'];
|
strapi.api = config['api/**'];
|
||||||
|
|
||||||
@ -150,7 +162,6 @@ module.exports = strapi => {
|
|||||||
// Initialize empty API objects.
|
// Initialize empty API objects.
|
||||||
strapi.controllers = {};
|
strapi.controllers = {};
|
||||||
strapi.models = {};
|
strapi.models = {};
|
||||||
strapi.policies = {};
|
|
||||||
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
@ -63,7 +63,8 @@ module.exports = class Configuration {
|
|||||||
services: 'services',
|
services: 'services',
|
||||||
policies: 'policies',
|
policies: 'policies',
|
||||||
models: 'models',
|
models: 'models',
|
||||||
plugins: 'plugins'
|
plugins: 'plugins',
|
||||||
|
validators: 'validators'
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start off needed empty objects and strings.
|
// Start off needed empty objects and strings.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user