ElevatedAccess Mixin
This commit is contained in:
parent
58cbf4027d
commit
76942a10d0
4 changed files with 44 additions and 22 deletions
22
app/mixins/elevated-access.js
Normal file
22
app/mixins/elevated-access.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
const { Mixin , inject: { service } } = Ember;
|
||||
|
||||
export default Mixin.create({
|
||||
currentUser: service('session-account'),
|
||||
|
||||
beforeModel: function(transition) {
|
||||
this._super(transition);
|
||||
this.get('currentUser.account').then((user) => {
|
||||
if (user.get('isReader')) {
|
||||
this.transitionTo(this.get('fallbackRouteBefore'));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
afterModel: function(model) {
|
||||
if (!model.get('canEdit')) {
|
||||
this.transitionTo(this.get('fallbackRouteAfter'), model.get('id'));
|
||||
}
|
||||
},
|
||||
});
|
|
@ -1,7 +1,9 @@
|
|||
import Ember from 'ember';
|
||||
import ajaxError from '../utils/ajax-error';
|
||||
|
||||
export default Ember.Mixin.create({
|
||||
const { Mixin } = Ember;
|
||||
|
||||
export default Mixin.create({
|
||||
actions: {
|
||||
save: function() {
|
||||
const model = this.get('model');
|
||||
|
@ -20,12 +22,11 @@ export default Ember.Mixin.create({
|
|||
|
||||
cancel: function() {
|
||||
const model = this.get('model');
|
||||
const fallbackRoute = this.get('fallbackRoute');
|
||||
|
||||
model.get('errors').clear();
|
||||
model.rollbackAttributes();
|
||||
|
||||
this.transitionToRoute(fallbackRoute, model);
|
||||
this.transitionToRoute(this.get('fallbackRoute'), model);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
Reference in a new issue