Skip to content

Instantly share code, notes, and snippets.

@shopapps
Created August 13, 2015 11:46
Show Gist options
  • Save shopapps/1997693d7c6d0053de09 to your computer and use it in GitHub Desktop.
Save shopapps/1997693d7c6d0053de09 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import DS from 'ember-data';
import Session from 'simple-auth/session';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
/*
* Inject the session into abilities
*/
export function initialize(container, application) {
application.inject('ability', 'session', 'session:custom');
}
export default {
name: 'inject-session-into-abilities.js',
initialize: initialize,
after:['simple-auth']
};
/*
* if an id comes from the oauth response
* (or is already stored in memory)
* use it to collect the current authorised user
*/
export default Session.extend({
user: function() {
var userId = this.get('secure.userId');
if (!Ember.isEmpty(userId)) {
return DS.PromiseObject.create({
promise: this.container.lookup('store:main').findRecord('user', userId)
});
}
}.property('secure.userId', 'isAuthenticated')
});
import { Ability } from 'ember-can';
/*
* app/abilities/request.js
* ROLES:
* admin
* agent
* fdc
*/
export default Ability.extend({
session: Ember.inject.service(),
canEdit: Ember.computed('user.role', function() {
var role = this.session.get('user.role');
return (role === 'admin' || role === 'fdc');
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.4.7",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.6/ember.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.7/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.6/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment