Merge branch 'master' into clostridium

* master:
  Clean up beforeModel(s)
  Remove unneeded user model hook
  404/Not Found
This commit is contained in:
Matthew Dillon 2015-10-14 13:12:48 -07:00
commit f6a175980a
14 changed files with 91 additions and 17 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

@ -0,0 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
redirect: function() {
let url = this.router.location.formatURL('/not-found');
if (window.location.pathname !== url) {
this.transitionTo('/not-found');
}
}
});

View file

@ -0,0 +1,3 @@
{{#x-application invalidateSession="invalidateSession"}}
<h1>404 Not Found</h1>
{{/x-application}}

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,12 +1,12 @@
import Ember from 'ember'; import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
import parseBase64 from '../../utils/parse-base64';
export default Ember.Route.extend(AuthenticatedRouteMixin, { export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() { actions: {
let token = this.get('session.secure.token'); error: function() {
let user = parseBase64(token); this.transitionTo('/not-found');
return this.store.find('user', user.sub); },
}, },
}); });

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);
}, },

View file

@ -16,6 +16,8 @@ Router.map(function() {
}); });
}); });
this.route('not-found', { path: '/*path' });
this.route('protected', { path: '/' }, function() { this.route('protected', { path: '/' }, function() {
this.route('about'); this.route('about');