Last active
December 22, 2015 04:58
-
-
Save fantactuka/6420602 to your computer and use it in GitHub Desktop.
Backbone by-Role access concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var can = Backbone.Role.can; | |
| var EntitiesController = Backbone.Controller.extend({ | |
| before: { | |
| index: function() { | |
| return can('read', 'entities'); | |
| } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var User = new Backbone.Role('user', { | |
| dashboard: { | |
| read: true | |
| }, | |
| entity: { | |
| read: true, | |
| create: true, | |
| update: function(entity) { | |
| return !!entity.get('internalContacts').findWhere({ id: CurrentUser.get('id') }); | |
| } | |
| } | |
| }); | |
| // Extend performs 2-level deep merging | |
| var Admin = User.extend({ | |
| entity: { | |
| update: true | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment