Closed rishab-yumist closed 8 years ago
hey @rishab-yumist if your project structure looks like this:
then to apply a policy or policy factory to the EventController
, you need to prefix the relative path of the controller to the controller name, like so
// in /config/policies.js
module.exports.policies = {
// ..
'v1/EventController': {
'*': must().be.a.member()
}
// ..
}
Hello @cludden ,
I tried using this. It throws an error.
can you give some additional info? node version? sails version? also, you're policyFactory file if that's cool?
Sure @cludden , here are the details : Sails version 0.11.3 Node version 4.2.3
api/policies/member.js
config/policies.js ![Uploading Screen Shot 2016-01-19 at 8.22.35 pm.png…]()
Oh I think I see the issue, I don't believe you can put policyFactories in the /policies
folder, as this folder is reserved by sails for traditional policies. Try moving it to /api/policyFactories/member.js
and change your require statement to reflect the move:
// in /config/policies
var must = require('sails-must')({
helpers: ['to', 'of', 'at', 'a'],
response: function(err, errors, req, res, next) {
// ...
}
})
Hard luck, still getting the same error.
Folder structure
hmm, do you sails-hook-must
installed and have you disabled the default policy hook?
Hey @cludden , I found what the issue was, my .sailsrc file was missing. I added it and it works like a wonder. Thanks for your help :)
Awesome!
Hello,
If I have my controllers in api/controllers/v1/, when I try to write policies, it doesn't apply on them.
Here's my config/policies.js code
Could you help me with the same?
Thanks in advance. @cludden