Created
August 13, 2015 11:46
-
-
Save shopapps/1997693d7c6d0053de09 to your computer and use it in GitHub Desktop.
New Twiddle
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
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'); | |
}) | |
}); | |
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
{ | |
"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