Skip to content

Instantly share code, notes, and snippets.

@fantactuka
Last active December 22, 2015 04:58
Show Gist options
  • Save fantactuka/6420602 to your computer and use it in GitHub Desktop.
Save fantactuka/6420602 to your computer and use it in GitHub Desktop.
Backbone by-Role access concept
var can = Backbone.Role.can;
var EntitiesController = Backbone.Controller.extend({
before: {
index: function() {
return can('read', 'entities');
}
}
});
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
}
});
{{#can "read" "entities"}}
{{linkTo 'entities/index'}}Entities list{{/linkTo}}
{{/can}}
...
{{#each entities}}
{{name}}
{{#can "edit" "entities" this}}
{{linkTo 'entities/edit' id}}Edit{{/linkTo}}
{{/can}}
{{/each}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment