Fixes #9 include all attributes when no roles are specified to get#11
Fixes #9 include all attributes when no roles are specified to get#11hendrul wants to merge 5 commits into
Conversation
|
io.js failing, go ahead and remove it from .travis.yml |
| // If no roles defined in attribute or set to true | ||
| || attr.roles === undefined || attr.roles === true | ||
| // If role is given but not defined in attribute apply default if any | ||
| || options.role && (typeof attr.roles === 'object' && attr.roles[options.role] === undefined && (attr.roles.default||{}).get !== false) |
There was a problem hiding this comment.
I think this case should rather throw, i don't like silently failing.
There was a problem hiding this comment.
What do you mean by silently failing?. Not returning boolean but rising an error instead?
There was a problem hiding this comment.
@i don't think that applying the default role for a "bad" role is a good default.
There was a problem hiding this comment.
Do you mean that if I try to save some attribute defaulted to set: false, I'll get an error?. In my particular case the client could send all attributes and I need just omit those protected ones. I think throwing is obtrusive (at least in my case) I would be forced to enclose every operation in try-catch block when I just need to be careful when assigning roles. Maybe this should be configurable don't you think?
There was a problem hiding this comment.
We should avoid configuration on call-site at all costs in favour of reasonable convention.
What i mean is that if you call get('attr', {role: 'roleThatDoesNotExist'}) it should throw, not default to using the default role.
|
I agree, the original default is almost unworkable and hard to implement unless you do so from the beginning. |
|
Maybe its a good idea to make this behavior configurable. I mean, being able to toggle it from blacklist to whitelist as needed. For backward compatibility. |
|
Although it's cool to have "default" roles, sometimes we may also want to bypass them and just get/set everything, This could be like: What if from get/set we don't apply default roles if the caller is Instance.build. Is that a horrible idea? |
|
@hendrul I prefer this behaviour so fine with a major bump. Sequelize uses |
|
For this common use case the problem I see with an omnipotent role is that now using blacklisting you should not forget to add that role for every attribute you have, while using just null as role means you want to disable roles |
|
@hendrul I see your point, |
What has changed?
Why this change?
I think the metaphor of roles in this plugin is taken too literally, as a security mecanism but this is not the real use case, what we want is to explicitly pick the attributes to "filter" depending on the situation or data destination (send to client? or use internally?), and not a super strong role base access mecanism, that prevent us from get/set sensible data by mistake. We choose!.
This way this plugin would cover the following use cases: