Clean up beforeModel(s)

Fixes #20
This commit is contained in:
Matthew Dillon 2015-10-14 13:12:06 -07:00
parent 0dbcd45c4e
commit bcd2bbb4c4
10 changed files with 70 additions and 12 deletions

View file

@ -13,6 +13,14 @@ export default DS.Model.extend({
return this.get('role') === 'A'; return this.get('role') === 'A';
}.property('role'), }.property('role'),
isWriter: function() {
return this.get('role') === 'W';
}.property('role'),
isReader: function() {
return this.get('role') === 'R';
}.property('role'),
fullRole: function() { fullRole: function() {
let role = this.get('role'); let role = this.get('role');
if (role === 'R') { if (role === 'R') {

View file

@ -2,6 +2,15 @@ import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, { export default Ember.Route.extend(AuthenticatedRouteMixin, {
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.characteristics.index');
}
});
},
model: function(params) { model: function(params) {
return this.store.findRecord('characteristic', params.characteristic_id, { reload: true }); return this.store.findRecord('characteristic', params.characteristic_id, { reload: true });
}, },

View file

@ -3,9 +3,11 @@ import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
beforeModel: function(transition) { beforeModel: function(transition) {
this._super(transition); this._super(transition);
if (this.get('session.currentUser.role') === 'R') { this.get('session.currentUser').then((user) => {
this.transitionTo('characteristics.index'); if (user.get('isReader')) {
} this.transitionTo('protected.characteristics.index');
}
});
}, },
model: function() { model: function() {

View file

@ -1,6 +1,15 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.species.index');
}
});
},
afterModel: function(species) { afterModel: function(species) {
if (!species.get('canEdit')) { if (!species.get('canEdit')) {
this.transitionTo('species.show', species.get('id')); this.transitionTo('species.show', species.get('id'));

View file

@ -3,9 +3,11 @@ import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
beforeModel: function(transition) { beforeModel: function(transition) {
this._super(transition); this._super(transition);
if (this.get('session.currentUser.role') === 'R') { this.get('session.currentUser').then((user) => {
this.transitionTo('species.index'); if (user.get('isReader')) {
} this.transitionTo('protected.species.index');
}
});
}, },
model: function() { model: function() {

View file

@ -2,6 +2,15 @@ import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, { export default Ember.Route.extend(AuthenticatedRouteMixin, {
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.strains.index');
}
});
},
model: function(params) { model: function(params) {
return Ember.RSVP.hash({ return Ember.RSVP.hash({
strain: this.store.find('strain', params.strain_id), strain: this.store.find('strain', params.strain_id),

View file

@ -3,9 +3,11 @@ import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
beforeModel: function(transition) { beforeModel: function(transition) {
this._super(transition); this._super(transition);
if (this.get('session.currentUser.role') === 'R') { this.get('session.currentUser').then((user) => {
this.transitionTo('strains.index'); if (user.get('isReader')) {
} this.transitionTo('protected.strains.index');
}
});
}, },
model: function() { model: function() {

View file

@ -5,8 +5,11 @@ export default Ember.Route.extend({
this._super(transition); this._super(transition);
let user_id = transition.params['protected.users.changepassword'].user_id; let user_id = transition.params['protected.users.changepassword'].user_id;
if (this.get('session.currentUser.id') !== user_id) {
this.transitionTo('protected.users.index'); this.get('session.currentUser').then((user) => {
} if (user.get('id') !== user_id) {
this.transitionTo('protected.users.index');
}
});
} }
}); });

View file

@ -1,6 +1,18 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
beforeModel: function(transition) {
this._super(transition);
let user_id = transition.params['protected.users.edit'].user_id;
this.get('session.currentUser').then((user) => {
if (user.get('id') !== user_id || user.get('isAdmin')) {
this.transitionTo('protected.users.index');
}
});
},
model: function(params) { model: function(params) {
return this.store.findRecord('user', params.user_id, { reload: true }); return this.store.findRecord('user', params.user_id, { reload: true });
}, },

View file

@ -2,6 +2,8 @@ import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
beforeModel: function(transition) { beforeModel: function(transition) {
this._super(transition);
let token = Ember.get(transition, 'queryParams.token'); let token = Ember.get(transition, 'queryParams.token');
this.get('session').authenticate('authenticator:jwt-resolved', token); this.get('session').authenticate('authenticator:jwt-resolved', token);
}, },