fixing config

This commit is contained in:
Matthew Ryan Dillon 2015-10-20 16:46:11 -07:00
commit 38daf6ea5b
47 changed files with 163 additions and 120 deletions

View file

@ -0,0 +1,6 @@
import OAuth2PasswordGrant from 'ember-simple-auth/authenticators/oauth2-password-grant';
import config from '../config/environment';
export default OAuth2PasswordGrant.extend({
serverTokenEndpoint: `${config.apiURL}/api/authenticate`,
});

View file

@ -0,0 +1,3 @@
import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';
export default OAuth2Bearer.extend({});

View file

@ -1,9 +0,0 @@
export function initialize(container, application) {
application.inject('session:custom', '_store', 'service:store');
}
export default {
name: 'custom-session',
after: 'ember-data',
initialize: initialize
};

View file

@ -1,3 +1,4 @@
import Ember from 'ember';
import DS from 'ember-data';
export default DS.Model.extend({
@ -33,4 +34,13 @@ export default DS.Model.extend({
return 'Error';
}
}.property('role'),
canWrite: Ember.computed('role', function() {
return this.get('role') !== 'R';
}),
metaData: Ember.computed('canWrite', function() {
return { 'canAdd': this.get('canWrite') };
}),
});

View file

@ -1,6 +1,9 @@
import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
export default DS.RESTAdapter.extend(DataAdapterMixin, {
authorizer: 'authorizer:application',
export default DS.RESTAdapter.extend({
namespace: function() {
return 'api/' + this.get('globals.genus');
}.property(),

View file

@ -1,5 +1,5 @@
import Ember from 'ember';
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {

View file

@ -3,6 +3,9 @@ import Ember from 'ember';
export default Ember.Component.extend({
classNames: ["flakes-frame"],
session: Ember.inject.service('session'),
currentUser: Ember.inject.service('session-account'),
didInsertElement: function() {
FlakesFrame.init();
},

View file

@ -14,7 +14,7 @@
{{#link-to 'protected.characteristics' tagName='li' href=false}}
{{link-to 'Characteristics' 'protected.characteristics'}}
{{/link-to}}
{{#if session.currentUser.isAdmin}}
{{#if currentUser.account.isAdmin}}
{{#link-to 'protected.users' tagName='li' href=false}}
{{link-to 'Users' 'protected.users'}}
{{/link-to}}
@ -24,7 +24,7 @@
{{/link-to}}
</ul>
<p class="foot">
{{link-to session.currentUser.name 'protected.users.show' session.currentUser.id}}<br>
{{link-to currentUser.account.name 'protected.users.show' currentUser.account.id}}<br>
<a {{action 'invalidateSession'}}>Logout</a>
</p>
{{else}}

View file

@ -1,21 +1,21 @@
import Ember from 'ember';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
loading: false,
actions: {
authenticate: function() {
let credentials = this.getProperties('identification', 'password');
let session = this.get('session');
let authenticator = 'simple-auth-authenticator:jwt';
// Manually clean up because there might not be a transition
this.get('flashMessages').clearMessages();
this.set('loading', true).then(session.authenticate(authenticator, credentials).catch((error) => {
let { identification, password } = this.getProperties('identification', 'password');
this.set('loading', true)
this.get('session').authenticate('authenticator:oauth2', identification, password).catch((error) => {
this.transitionToRoute('login');
this.set('loading', false);
this.get('flashMessages').error(error.error);
}));
});
this.set('loading', false);
}
}

View file

@ -1,4 +1,4 @@
import Ember from 'ember';
import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';
export default Ember.Route.extend(UnauthenticatedRouteMixin, {});

View file

@ -13,8 +13,9 @@ export default Ember.Controller.extend({
ajaxError(characteristic.get('errors'), this.get('flashMessages'));
});
} else {
characteristic.deleteRecord();
this.transitionToRoute('protected.characteristics.show', characteristic);
characteristic.deleteRecord().then(() => {
this.transitionToRoute('protected.characteristics.show', characteristic);
});
}
},

View file

@ -1,10 +1,11 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.characteristics.index');
}

View file

@ -1,13 +1,17 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
model: function() {
return this.store.findAll('characteristic');
},
setupController: function(controller, model) {
controller.set('model', model);
controller.set('metaData', this.store.metadataFor('characteristic'));
this.get('currentUser.account').then((user) => {
controller.set('metaData', user.get('metaData'));
});
},
});

View file

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

View file

@ -3,8 +3,9 @@ import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
delete: function() {
this.get('model').destroyRecord();
this.transitionToRoute('protected.characteristics.index');
this.get('model').destroyRecord().then(() => {
this.transitionToRoute('protected.characteristics.index');
});
},
},

View file

@ -2,6 +2,8 @@ import Ember from 'ember';
import ajaxRequest from '../../../../utils/ajax-request';
export default Ember.Route.extend({
session: Ember.inject.service('session'),
queryParams: {
strain_ids: {
refreshModel: true,
@ -33,7 +35,7 @@ export default Ember.Route.extend({
method: 'GET',
data: params,
};
return ajaxRequest(url, options);
return ajaxRequest(url, options, this.get('session'));
},
setupController: function(controller, model) {

View file

@ -1,5 +1,5 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
actions: {

View file

@ -1,9 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.species.index');
}
@ -18,7 +20,9 @@ export default Ember.Route.extend({
setupController: function(controller, model) {
controller.set('model', model);
controller.set('metaData', this.store.metadataFor('species'));
this.get('currentUser.account').then((user) => {
controller.set('metaData', user.get('metaData'));
});
},
});

View file

@ -1,13 +1,17 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
model: function() {
return this.store.findAll('species');
},
setupController: function(controller, model) {
controller.set('model', model);
controller.set('metaData', this.store.metadataFor('species'));
this.get('currentUser.account').then((user) => {
controller.set('metaData', user.get('metaData'));
});
},
});

View file

@ -13,8 +13,9 @@ export default Ember.Controller.extend({
ajaxError(species.get('errors'), this.get('flashMessages'));
});
} else {
species.deleteRecord();
this.transitionToRoute('protected.species.index');
species.deleteRecord().then(() => {
this.transitionToRoute('protected.species.index');
});
}
},

View file

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

View file

@ -3,8 +3,9 @@ import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
delete: function() {
this.get('model').destroyRecord();
this.transitionToRoute('protected.species.index');
this.get('model').destroyRecord().then(() => {
this.transitionToRoute('protected.species.index');
});
},
},

View file

@ -13,8 +13,9 @@ export default Ember.Controller.extend({
ajaxError(strain.get('errors'), this.get('flashMessages'));
});
} else {
strain.deleteRecord();
this.transitionToRoute('protected.strains.show', strain);
strain.deleteRecord().then(() => {
this.transitionToRoute('protected.strains.show', strain);
});
}
},

View file

@ -1,10 +1,11 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
this.get('currentUser.account').then((user) => {
if (user.get('isReader')) {
this.transitionTo('protected.strains.index');
}
@ -26,7 +27,9 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
setupController: function(controller, models) {
controller.setProperties(models);
controller.set('metaData', this.store.metadataFor('strain'));
this.get('currentUser.account').then((user) => {
controller.set('metaData', user.get('metaData'));
});
},
});

View file

@ -1,13 +1,17 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
model: function() {
return this.store.findAll('strain');
},
setupController: function(controller, model) {
controller.set('model', model);
controller.set('metaData', this.store.metadataFor('strain'));
this.get('currentUser.account').then((user) => {
controller.set('metaData', user.get('metaData'));
});
},
});

View file

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

View file

@ -3,8 +3,9 @@ import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
delete: function() {
this.get('model').destroyRecord();
this.transitionToRoute('protected.strains.index');
this.get('model').destroyRecord().then(() => {
this.transitionToRoute('protected.strains.index');
});
},
},

View file

@ -1,7 +1,6 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
export default Ember.Route.extend({
model: function(params) {
return this.store.findRecord('strain', params.strain_id, { reload: true });
},

View file

@ -2,6 +2,9 @@ import Ember from 'ember';
import ajaxRequest from '../../../../utils/ajax-request';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
currentUser: Ember.inject.service('session-account'),
passwordConfirm: null,
actions: {
@ -16,11 +19,11 @@ export default Ember.Controller.extend({
let options = {
method: 'POST',
data: {
id: this.get('session.currentUser.id'),
id: this.get('currentUser.account.id'),
password: this.get('password'),
},
};
ajaxRequest(url, options);
ajaxRequest(url, options, this.get('session'));
this.transitionTo('protected.users.index');
this.get('flashMessages').information('Your password has been changed.');
},

View file

@ -1,12 +1,14 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
beforeModel: function(transition) {
this._super(transition);
let user_id = transition.params['protected.users.changepassword'].user_id;
this.get('session.currentUser').then((user) => {
this.get('currentUser.account').then((user) => {
if (user.get('id') !== user_id) {
this.transitionTo('protected.users.index');
}

View file

@ -1,12 +1,14 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
beforeModel: function(transition) {
this._super(transition);
let user_id = transition.params['protected.users.edit'].user_id;
this.get('session.currentUser').then((user) => {
this.get('currentUser.account').then((user) => {
if (user.get('id') !== user_id && !user.get('isAdmin')) {
this.transitionTo('protected.users.index');
}

View file

@ -1,7 +1,7 @@
{{
protected/users/user-form
user=model
currentUser=session.currentUser
currentUser=currentUser.account
save="save"
cancel="cancel"
}}

View file

@ -1,9 +1,11 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
this.get('currentUser.account').then((user) => {
if (!user.get('isAdmin')) {
this.transitionTo('protected.index');
}

View file

@ -1,7 +1,9 @@
import Ember from 'ember';
export default Ember.Controller.extend({
isUser: Ember.computed('model.id', 'session.currentUser.id', function() {
return this.get('model.id') === this.get('session.currentUser.id');
currentUser: Ember.inject.service('session-account'),
isUser: Ember.computed('model.id', 'currentUser.account.id', function() {
return this.get('model.id') === this.get('currentUser.account.id');
}),
});

View file

@ -1,10 +1,12 @@
import Ember from 'ember';
export default Ember.Route.extend({
currentUser: Ember.inject.service('session-account'),
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((currentUser) => {
this.get('currentUser.account').then((currentUser) => {
let user_id = transition.params['protected.users.show'].user_id;
if (!currentUser.get('isAdmin') && currentUser.get('id') !== user_id) {
this.transitionTo('protected.users.index');

View file

@ -1,8 +0,0 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() {
return this.store.findAll('user');
}
});

View file

@ -1,3 +0,0 @@
{{#each model as |user|}}
{{user.email}}<br>
{{/each}}

View file

@ -1,6 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
session: Ember.inject.service('session'),
beforeModel: function(transition) {
this._super(transition);

View file

@ -1,5 +1,5 @@
import Ember from 'ember';
import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';
export default Ember.Route.extend(UnauthenticatedRouteMixin, {
model: function() {

View file

@ -2,6 +2,8 @@ import Ember from 'ember';
import ajaxRequest from '../../../../utils/ajax-request';
export default Ember.Route.extend({
session: Ember.inject.service('session'),
apiURL: function() {
return this.get('globals.apiURL');
}.property(),
@ -12,7 +14,7 @@ export default Ember.Route.extend({
model: function(params) {
let url = `${this.get('apiURL')}/api/${this.get('genus')}/users/verify/${params.nonce}`;
return ajaxRequest(url);
return ajaxRequest(url, {}, this.get('session'));
},

View file

@ -2,6 +2,8 @@ import Ember from 'ember';
import ajaxRequest from '../../../utils/ajax-request';
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
save: function() {
let url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/lockout`;
@ -9,7 +11,7 @@ export default Ember.Controller.extend({
method: 'POST',
data: { email: this.get('email') },
};
ajaxRequest(url, options);
ajaxRequest(url, options, this.get('session'));
this.transitionTo('login');
this.get('flashMessages').information('Please check your email');
},

View file

@ -0,0 +1,22 @@
import Ember from 'ember';
import DS from 'ember-data';
import parseBase64 from '../utils/parse-base64';
const { service } = Ember.inject;
export default Ember.Service.extend({
session: service('session'),
store: service(),
account: Ember.computed('session.data.authenticated.access_token', function() {
const token = this.get('session.data.authenticated.access_token');
const claims = parseBase64(token);
const id = claims['sub'];
if (!Ember.isEmpty(id)) {
return DS.PromiseObject.create({
promise: this.get('store').findRecord('user', id),
});
}
})
});

View file

@ -1,12 +0,0 @@
import Session from 'simple-auth/session';
import parseBase64 from '../utils/parse-base64';
export default Session.extend({
currentUser: function() {
let token = this.get('secure.token');
if (token && this.get('isAuthenticated')) {
let t = parseBase64(token);
return this._store.findRecord('user', t['sub']);
}
}.property('secure.token', 'isAuthenticated')
});

View file

@ -1,9 +1,14 @@
import Ember from 'ember';
export default function ajaxRequest(url, options) {
export default function ajaxRequest(url, options, session) {
return new Ember.RSVP.Promise(function(resolve, reject) {
options = options || {};
options.url = url;
session.authorize('authorizer:application', (headerName, headerValue) => {
let authHeader = {};
authHeader[headerName] = headerValue;
options.headers = authHeader;
});
options.success = function(data) {
resolve(data);
};

View file

@ -13,7 +13,6 @@
"loader.js": "ember-cli/loader.js#3.2.1",
"qunit": "~1.18.0",
"flakes": "~1.0.0",
"ember-simple-auth": "~0.8.0",
"moment": "~2.10.6",
"select2": "3.5.2",
"antiscroll": "git://github.com/azirbel/antiscroll.git#90391fb371c7be769bc32e7287c5271981428356",

View file

@ -14,36 +14,14 @@ module.exports = function(environment) {
APP: {
genus: 'clostridium',
},
podModulePrefix: 'clostridiumdotinfo/pods',
'simple-auth': {
session: 'session:custom',
authorizer: 'simple-auth-authorizer:token',
store: 'simple-auth-session-store:local-storage',
routeAfterAuthentication: 'protected.index',
},
'simple-auth-token': {
identificationField: 'email',
passwordField: 'password',
tokenPropertyName: 'token',
authorizationPrefix: 'Bearer ',
authorizationHeaderName: 'Authorization',
refreshAccessTokens: true,
timeFactor: 1000, // 1000 ms/s; JWT returned in unix time seconds
refreshLeeway: 1800, // (60 s/min) * (30 min) = 1800 s
},
contentSecurityPolicy: {
'default-src': "'none'",
'script-src': "'self'",
'font-src': "'self'",
'img-src': "'self' data:",
'style-src': "'self' 'unsafe-inline'",
'media-src': "'self'"
},
flashMessageDefaults: {
sticky: true,
type: 'error',
types: ['error', 'warning', 'success', 'information', 'tip', 'message'],
},
'ember-simple-auth': {
routeAfterAuthentication: 'protected.compare',
},
};
var apiURL;
@ -62,11 +40,7 @@ module.exports = function(environment) {
apiURL = 'https://bactdb.herokuapp.com';
}
ENV['simple-auth']['crossOriginWhitelist'] = [apiURL];
ENV['simple-auth-token']['serverTokenEndpoint'] = apiURL + '/api/authenticate';
ENV['simple-auth-token']['serverTokenRefreshEndpoint'] = apiURL + '/api/refresh';
ENV.apiURL = apiURL;
ENV.contentSecurityPolicy['connect-src'] = "'self' " + apiURL;
return ENV;
};

View file

@ -23,7 +23,6 @@
"ember-cli": "1.13.8",
"ember-cli-app-version": "0.5.0",
"ember-cli-babel": "^5.1.3",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.0.1",
"ember-cli-divshot": "^0.1.7",
"ember-cli-flash": "1.3.3",
@ -32,8 +31,7 @@
"ember-cli-ic-ajax": "0.2.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-qunit": "^1.0.0",
"ember-cli-simple-auth": "^0.8.0",
"ember-cli-simple-auth-token": "^0.7.2",
"ember-simple-auth": "1.0.0",
"ember-cli-release": "0.2.3",
"ember-cli-sri": "^1.0.3",
"ember-cli-uglify": "^1.2.0",