cludden / sails-must

MIT License
8 stars 1 forks source link

Issue with config/policies.js #6

Closed rishab-yumist closed 8 years ago

rishab-yumist commented 8 years ago

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

screen shot 2016-01-19 at 6 48 39 pm screen shot 2016-01-19 at 6 48 43 pm

Could you help me with the same?

Thanks in advance. @cludden

cludden commented 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()
    }
    // ..
}
rishab-yumist commented 8 years ago

Hello @cludden ,

I tried using this. It throws an error.

screen shot 2016-01-19 at 8 11 33 pm

cludden commented 8 years ago

can you give some additional info? node version? sails version? also, you're policyFactory file if that's cool?

rishab-yumist commented 8 years ago

Sure @cludden , here are the details : Sails version 0.11.3 Node version 4.2.3

screen shot 2016-01-19 at 8 20 49 pm

api/policies/member.js screen shot 2016-01-19 at 8 21 08 pm

config/policies.js ![Uploading Screen Shot 2016-01-19 at 8.22.35 pm.png…]()

cludden commented 8 years ago

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) {
        // ...
    }
})
rishab-yumist commented 8 years ago

Hard luck, still getting the same error.

screen shot 2016-01-19 at 8 28 30 pm

Folder structure

screen shot 2016-01-19 at 8 29 28 pm

cludden commented 8 years ago

hmm, do you sails-hook-must installed and have you disabled the default policy hook?

rishab-yumist commented 8 years ago

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 :)

cludden commented 8 years ago

Awesome!