balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.83k stars 1.95k forks source link

Policies don't work for actions created from blueprint #1050

Closed shilov closed 10 years ago

shilov commented 10 years ago

Setting a policy seems to have no effect for actions being automatically generated from the controller blueprint.

I encountered this when I tried to enable the provided isAuthenticated policy for the index action on my controller.

Is this by design or unintentional?

reecelewellen commented 10 years ago

I do not think "index" exists actually. Try "find" and/or "findAll" - If anything, be redundant and use all 3.

On Fri, Nov 1, 2013 at 2:57 PM, Stanley notifications@github.com wrote:

Setting a policy seems to have no effect for actions being automatically generated from the controller blueprint.

I encountered this when I tried to enable the provided isAuthenticatedpolicy for the index action on my controller.

Is this by design or unintentional?

— Reply to this email directly or view it on GitHubhttps://github.com/balderdashy/sails/issues/1050 .

reecelewellen commented 10 years ago

Side note - I know find/findAll work. That is what I use personally*

On Fri, Nov 1, 2013 at 3:05 PM, Reece Lewellen reece.lewellen@gmail.comwrote:

I do not think "index" exists actually. Try "find" and/or "findAll" - If anything, be redundant and use all 3.

On Fri, Nov 1, 2013 at 2:57 PM, Stanley notifications@github.com wrote:

Setting a policy seems to have no effect for actions being automatically generated from the controller blueprint.

I encountered this when I tried to enable the provided isAuthenticatedpolicy for the index action on my controller.

Is this by design or unintentional?

— Reply to this email directly or view it on GitHubhttps://github.com/balderdashy/sails/issues/1050 .

rowanu commented 10 years ago

I ran in to this problem too. The index action does exist (in the REST blueprint), but I could not get the policies to be applied to it until I overrode the default/blueprint index() controller action manually.

I'm guessing this is not intentional (it's probably just to do with the order that policies and blueprint actions are applied ie. the policies are applied before the blueprints are generated). I'll send a PR once I'm more familiar with Sails.

mikermcneil commented 10 years ago

find should do the trick- the blueprint (aka "shadow") CRUD routes connect to the implicit find, create, update, and destroy methods on controllers.

mikermcneil commented 10 years ago

@shilov there's some more in-depth documentation of the blueprint CRUD actions here: https://github.com/balderdashy/sails-docs/blob/0.9/reference/Blueprints.md

and thanks- good question!