Skip to content

Instantly share code, notes, and snippets.

@Kilowhisky
Last active December 30, 2016 23:22
Show Gist options
  • Save Kilowhisky/1eba1236f9d5c78a30589eb4dfb0663c to your computer and use it in GitHub Desktop.
Save Kilowhisky/1eba1236f9d5c78a30589eb4dfb0663c to your computer and use it in GitHub Desktop.
Helper issue
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
/**
* This helper returns if the user has any of the supplied permission or not.
* If all=true is applied then all the supplied permissions have to be present.
*
* @example {{has-permission 'communicate' 'communicate.send' all=true }}
*/
export default Ember.Helper.extend({
compute: function(params, hash) {
//let permissions = this.get('sessionAccount.user.permissions');
return this.hasPermission(/*permissions*/['track'], params, hash.all);
},
// This function is usually in its own util file
hasPermission(userPermissions, permissions, allRequired) {
for (let i = 0; i < permissions.get('length'); i++) {
if (userPermissions.includes(permissions.objectAt(i))) {
return true;
}
}
return false;
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{#if (has-permission 'track')}}
SUCCESS
{{/if}}
<br>
<br>
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "canary",
"ember-data": "2.10.0",
"ember-template-compiler": "canary",
"ember-testing": "canary"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment