Merge branch 'master' into clostridium
* master: Clean up beforeModel(s) Remove unneeded user model hook 404/Not Found
This commit is contained in:
commit
f6a175980a
14 changed files with 91 additions and 17 deletions
|
@ -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') {
|
||||||
|
|
11
app/pods/not-found/route.js
Normal file
11
app/pods/not-found/route.js
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
3
app/pods/not-found/template.hbs
Normal file
3
app/pods/not-found/template.hbs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{{#x-application invalidateSession="invalidateSession"}}
|
||||||
|
<h1>404 Not Found</h1>
|
||||||
|
{{/x-application}}
|
|
@ -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 });
|
||||||
},
|
},
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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);
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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'));
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 });
|
||||||
},
|
},
|
||||||
|
|
|
@ -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);
|
||||||
},
|
},
|
||||||
|
|
|
@ -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');
|
||||||
|
|
||||||
|
|
Reference in a new issue