From 43bc7645f2d2db853063c57f464b7aba7ef0b1e8 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 10:07:29 -0700 Subject: [PATCH 01/12] Replace calls to store for metaData with user CP Fixes #25. --- app/models/user.js | 10 ++++++++++ app/pods/protected/characteristics/index/route.js | 4 +++- app/pods/protected/species/edit/route.js | 4 +++- app/pods/protected/species/index/route.js | 4 +++- app/pods/protected/strains/edit/route.js | 4 +++- app/pods/protected/strains/index/route.js | 4 +++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/models/user.js b/app/models/user.js index c6a5dac..198f451 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -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') }; + }), + }); diff --git a/app/pods/protected/characteristics/index/route.js b/app/pods/protected/characteristics/index/route.js index 83aa3ef..a68c605 100644 --- a/app/pods/protected/characteristics/index/route.js +++ b/app/pods/protected/characteristics/index/route.js @@ -7,7 +7,9 @@ export default Ember.Route.extend({ setupController: function(controller, model) { controller.set('model', model); - controller.set('metaData', this.store.metadataFor('characteristic')); + this.get('session.currentUser').then((user) => { + controller.set('metaData', user.get('metaData')); + }); }, }); diff --git a/app/pods/protected/species/edit/route.js b/app/pods/protected/species/edit/route.js index e9e9076..3da73d9 100644 --- a/app/pods/protected/species/edit/route.js +++ b/app/pods/protected/species/edit/route.js @@ -18,7 +18,9 @@ export default Ember.Route.extend({ setupController: function(controller, model) { controller.set('model', model); - controller.set('metaData', this.store.metadataFor('species')); + this.get('session.currentUser').then((user) => { + controller.set('metaData', user.get('metaData')); + }); }, }); diff --git a/app/pods/protected/species/index/route.js b/app/pods/protected/species/index/route.js index 755edff..fdb9293 100644 --- a/app/pods/protected/species/index/route.js +++ b/app/pods/protected/species/index/route.js @@ -7,7 +7,9 @@ export default Ember.Route.extend({ setupController: function(controller, model) { controller.set('model', model); - controller.set('metaData', this.store.metadataFor('species')); + this.get('session.currentUser').then((user) => { + controller.set('metaData', user.get('metaData')); + }); }, }); diff --git a/app/pods/protected/strains/edit/route.js b/app/pods/protected/strains/edit/route.js index 328d89d..90ae097 100644 --- a/app/pods/protected/strains/edit/route.js +++ b/app/pods/protected/strains/edit/route.js @@ -26,7 +26,9 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { setupController: function(controller, models) { controller.setProperties(models); - controller.set('metaData', this.store.metadataFor('strain')); + this.get('session.currentUser').then((user) => { + controller.set('metaData', user.get('metaData')); + }); }, }); diff --git a/app/pods/protected/strains/index/route.js b/app/pods/protected/strains/index/route.js index 14b7a5c..89b5e40 100644 --- a/app/pods/protected/strains/index/route.js +++ b/app/pods/protected/strains/index/route.js @@ -7,7 +7,9 @@ export default Ember.Route.extend({ setupController: function(controller, model) { controller.set('model', model); - controller.set('metaData', this.store.metadataFor('strain')); + this.get('session.currentUser').then((user) => { + controller.set('metaData', user.get('metaData')); + }); }, }); From 131c59daa268bb405c1c639a4184158a7a6b0121 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 10:24:58 -0700 Subject: [PATCH 02/12] Update package, drop esa-token --- bower.json | 1 - package.json | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 9efca06..abdb8ab 100644 --- a/bower.json +++ b/bower.json @@ -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", diff --git a/package.json b/package.json index 9bd4ccd..bec8b94 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,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", From e526167c62fbff016d7c407117bb2cf00a9569c6 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 10:28:28 -0700 Subject: [PATCH 03/12] Application boots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Can’t authenticate --- app/pods/application/route.js | 2 +- app/pods/login/route.js | 2 +- app/pods/protected/route.js | 2 +- app/pods/users/new/route.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/pods/application/route.js b/app/pods/application/route.js index 0754183..ca03050 100644 --- a/app/pods/application/route.js +++ b/app/pods/application/route.js @@ -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: { diff --git a/app/pods/login/route.js b/app/pods/login/route.js index 457fe0c..c38d19e 100644 --- a/app/pods/login/route.js +++ b/app/pods/login/route.js @@ -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, {}); diff --git a/app/pods/protected/route.js b/app/pods/protected/route.js index acb1442..b1cdc95 100644 --- a/app/pods/protected/route.js +++ b/app/pods/protected/route.js @@ -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: { diff --git a/app/pods/users/new/route.js b/app/pods/users/new/route.js index 8d7010b..c3e757a 100644 --- a/app/pods/users/new/route.js +++ b/app/pods/users/new/route.js @@ -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() { From 1aa8d8d88d14f26eb6c8e6e7a810200e09f8475b Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 10:40:23 -0700 Subject: [PATCH 04/12] Clear out old stuff --- app/initializers/custom-session.js | 9 --------- config/environment.js | 28 ---------------------------- package.json | 1 - 3 files changed, 38 deletions(-) delete mode 100644 app/initializers/custom-session.js diff --git a/app/initializers/custom-session.js b/app/initializers/custom-session.js deleted file mode 100644 index 011cd90..0000000 --- a/app/initializers/custom-session.js +++ /dev/null @@ -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 -}; diff --git a/config/environment.js b/config/environment.js index d03d0ff..2b1e044 100644 --- a/config/environment.js +++ b/config/environment.js @@ -15,30 +15,6 @@ module.exports = function(environment) { genus: 'hymenobacter', }, podModulePrefix: 'hymenobacterdotinfo/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', @@ -62,11 +38,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; }; diff --git a/package.json b/package.json index bec8b94..aa25acd 100644 --- a/package.json +++ b/package.json @@ -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", From c2e8299e672dd5c98e4db3b72fb64074300e6ec4 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 13:34:06 -0700 Subject: [PATCH 05/12] Can log in now --- app/authenticators/oauth2.js | 6 ++++++ app/pods/login/controller.js | 12 ++++++------ app/pods/users/lockoutauthenticate/route.js | 2 ++ config/environment.js | 3 +++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 app/authenticators/oauth2.js diff --git a/app/authenticators/oauth2.js b/app/authenticators/oauth2.js new file mode 100644 index 0000000..c5c9221 --- /dev/null +++ b/app/authenticators/oauth2.js @@ -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`, +}); diff --git a/app/pods/login/controller.js b/app/pods/login/controller.js index 42e761d..13eed49 100644 --- a/app/pods/login/controller.js +++ b/app/pods/login/controller.js @@ -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); } } diff --git a/app/pods/users/lockoutauthenticate/route.js b/app/pods/users/lockoutauthenticate/route.js index f77c5dc..9924157 100644 --- a/app/pods/users/lockoutauthenticate/route.js +++ b/app/pods/users/lockoutauthenticate/route.js @@ -1,6 +1,8 @@ import Ember from 'ember'; export default Ember.Route.extend({ + session: Ember.inject.service('session'), + beforeModel: function(transition) { this._super(transition); diff --git a/config/environment.js b/config/environment.js index 2b1e044..824739a 100644 --- a/config/environment.js +++ b/config/environment.js @@ -20,6 +20,9 @@ module.exports = function(environment) { type: 'error', types: ['error', 'warning', 'success', 'information', 'tip', 'message'], }, + 'ember-simple-auth': { + routeAfterAuthentication: 'protected.compare', + }, }; var apiURL; From 7051180e49c5a2782927a930cd83a1e7e64ee231 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 15:03:08 -0700 Subject: [PATCH 06/12] Remove extra mixin --- app/pods/protected/strains/show/route.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/pods/protected/strains/show/route.js b/app/pods/protected/strains/show/route.js index 4c9634b..0a17d8b 100644 --- a/app/pods/protected/strains/show/route.js +++ b/app/pods/protected/strains/show/route.js @@ -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 }); }, From 1f163737da3430b5f1a125d253783872f0382033 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 15:03:28 -0700 Subject: [PATCH 07/12] Remove dead route --- app/pods/users/index/route.js | 8 -------- app/pods/users/index/template.hbs | 3 --- 2 files changed, 11 deletions(-) delete mode 100644 app/pods/users/index/route.js delete mode 100644 app/pods/users/index/template.hbs diff --git a/app/pods/users/index/route.js b/app/pods/users/index/route.js deleted file mode 100644 index 2169a4f..0000000 --- a/app/pods/users/index/route.js +++ /dev/null @@ -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'); - } -}); diff --git a/app/pods/users/index/template.hbs b/app/pods/users/index/template.hbs deleted file mode 100644 index f3239cb..0000000 --- a/app/pods/users/index/template.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#each model as |user|}} - {{user.email}}
-{{/each}} From 30b1706868a6a5cc399612636c8dae69e0c3c9e5 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 15:03:39 -0700 Subject: [PATCH 08/12] Remove old session --- app/sessions/custom.js | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 app/sessions/custom.js diff --git a/app/sessions/custom.js b/app/sessions/custom.js deleted file mode 100644 index e5a8385..0000000 --- a/app/sessions/custom.js +++ /dev/null @@ -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') -}); From 52979ac9e25ccdeeccc466e9a7e438e7c6ecd1c9 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 15:04:14 -0700 Subject: [PATCH 09/12] Setup authorizer and custom session for account --- app/authorizers/application.js | 3 +++ app/pods/application/adapter.js | 5 ++++- app/services/session-account.js | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/authorizers/application.js create mode 100644 app/services/session-account.js diff --git a/app/authorizers/application.js b/app/authorizers/application.js new file mode 100644 index 0000000..68755e3 --- /dev/null +++ b/app/authorizers/application.js @@ -0,0 +1,3 @@ +import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer'; + +export default OAuth2Bearer.extend({}); diff --git a/app/pods/application/adapter.js b/app/pods/application/adapter.js index 11498d0..96daa1a 100644 --- a/app/pods/application/adapter.js +++ b/app/pods/application/adapter.js @@ -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(), diff --git a/app/services/session-account.js b/app/services/session-account.js new file mode 100644 index 0000000..1b34554 --- /dev/null +++ b/app/services/session-account.js @@ -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), + }); + } + }) +}); From bbcef5459e9661002b25b72d42143f40da4641ad Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 15:04:35 -0700 Subject: [PATCH 10/12] Update account service references --- app/pods/components/x-application/component.js | 3 +++ app/pods/components/x-application/template.hbs | 4 ++-- app/pods/protected/characteristics/edit/route.js | 7 ++++--- app/pods/protected/characteristics/index/route.js | 4 +++- app/pods/protected/characteristics/new/route.js | 4 +++- app/pods/protected/species/edit/route.js | 6 ++++-- app/pods/protected/species/index/route.js | 4 +++- app/pods/protected/species/new/route.js | 4 +++- app/pods/protected/strains/edit/route.js | 9 +++++---- app/pods/protected/strains/index/route.js | 4 +++- app/pods/protected/strains/new/route.js | 4 +++- app/pods/protected/users/changepassword/controller.js | 4 +++- app/pods/protected/users/changepassword/route.js | 4 +++- app/pods/protected/users/edit/route.js | 4 +++- app/pods/protected/users/edit/template.hbs | 2 +- app/pods/protected/users/index/route.js | 4 +++- app/pods/protected/users/show/controller.js | 6 ++++-- app/pods/protected/users/show/route.js | 4 +++- 18 files changed, 56 insertions(+), 25 deletions(-) diff --git a/app/pods/components/x-application/component.js b/app/pods/components/x-application/component.js index 27c8d25..967b497 100644 --- a/app/pods/components/x-application/component.js +++ b/app/pods/components/x-application/component.js @@ -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(); }, diff --git a/app/pods/components/x-application/template.hbs b/app/pods/components/x-application/template.hbs index e859890..49cc38e 100644 --- a/app/pods/components/x-application/template.hbs +++ b/app/pods/components/x-application/template.hbs @@ -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}}

- {{link-to session.currentUser.name 'protected.users.show' session.currentUser.id}}
+ {{link-to currentUser.account.name 'protected.users.show' currentUser.account.id}}
Logout

{{else}} diff --git a/app/pods/protected/characteristics/edit/route.js b/app/pods/protected/characteristics/edit/route.js index 1c04a5d..3f35133 100644 --- a/app/pods/protected/characteristics/edit/route.js +++ b/app/pods/protected/characteristics/edit/route.js @@ -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'); } diff --git a/app/pods/protected/characteristics/index/route.js b/app/pods/protected/characteristics/index/route.js index a68c605..3ee78f4 100644 --- a/app/pods/protected/characteristics/index/route.js +++ b/app/pods/protected/characteristics/index/route.js @@ -1,13 +1,15 @@ 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); - this.get('session.currentUser').then((user) => { + this.get('currentUser.account').then((user) => { controller.set('metaData', user.get('metaData')); }); }, diff --git a/app/pods/protected/characteristics/new/route.js b/app/pods/protected/characteristics/new/route.js index 677a5fc..2773092 100644 --- a/app/pods/protected/characteristics/new/route.js +++ b/app/pods/protected/characteristics/new/route.js @@ -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'); } diff --git a/app/pods/protected/species/edit/route.js b/app/pods/protected/species/edit/route.js index 3da73d9..1f5b616 100644 --- a/app/pods/protected/species/edit/route.js +++ b/app/pods/protected/species/edit/route.js @@ -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,7 @@ export default Ember.Route.extend({ setupController: function(controller, model) { controller.set('model', model); - this.get('session.currentUser').then((user) => { + this.get('currentUser.account').then((user) => { controller.set('metaData', user.get('metaData')); }); }, diff --git a/app/pods/protected/species/index/route.js b/app/pods/protected/species/index/route.js index fdb9293..89c832d 100644 --- a/app/pods/protected/species/index/route.js +++ b/app/pods/protected/species/index/route.js @@ -1,13 +1,15 @@ 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); - this.get('session.currentUser').then((user) => { + this.get('currentUser.account').then((user) => { controller.set('metaData', user.get('metaData')); }); }, diff --git a/app/pods/protected/species/new/route.js b/app/pods/protected/species/new/route.js index 3f813d2..d265f9e 100644 --- a/app/pods/protected/species/new/route.js +++ b/app/pods/protected/species/new/route.js @@ -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'); } diff --git a/app/pods/protected/strains/edit/route.js b/app/pods/protected/strains/edit/route.js index 90ae097..ee75d51 100644 --- a/app/pods/protected/strains/edit/route.js +++ b/app/pods/protected/strains/edit/route.js @@ -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,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { setupController: function(controller, models) { controller.setProperties(models); - this.get('session.currentUser').then((user) => { + this.get('currentUser.account').then((user) => { controller.set('metaData', user.get('metaData')); }); }, diff --git a/app/pods/protected/strains/index/route.js b/app/pods/protected/strains/index/route.js index 89b5e40..e5582d7 100644 --- a/app/pods/protected/strains/index/route.js +++ b/app/pods/protected/strains/index/route.js @@ -1,13 +1,15 @@ 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); - this.get('session.currentUser').then((user) => { + this.get('currentUser.account').then((user) => { controller.set('metaData', user.get('metaData')); }); }, diff --git a/app/pods/protected/strains/new/route.js b/app/pods/protected/strains/new/route.js index 45ca831..6def196 100644 --- a/app/pods/protected/strains/new/route.js +++ b/app/pods/protected/strains/new/route.js @@ -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'); } diff --git a/app/pods/protected/users/changepassword/controller.js b/app/pods/protected/users/changepassword/controller.js index 94ce219..512c539 100644 --- a/app/pods/protected/users/changepassword/controller.js +++ b/app/pods/protected/users/changepassword/controller.js @@ -2,6 +2,8 @@ import Ember from 'ember'; import ajaxRequest from '../../../../utils/ajax-request'; export default Ember.Controller.extend({ + currentUser: Ember.inject.service('session-account'), + passwordConfirm: null, actions: { @@ -16,7 +18,7 @@ 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'), }, }; diff --git a/app/pods/protected/users/changepassword/route.js b/app/pods/protected/users/changepassword/route.js index 2e3f295..ce869dd 100644 --- a/app/pods/protected/users/changepassword/route.js +++ b/app/pods/protected/users/changepassword/route.js @@ -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'); } diff --git a/app/pods/protected/users/edit/route.js b/app/pods/protected/users/edit/route.js index 3a943b8..b95bdb2 100644 --- a/app/pods/protected/users/edit/route.js +++ b/app/pods/protected/users/edit/route.js @@ -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'); } diff --git a/app/pods/protected/users/edit/template.hbs b/app/pods/protected/users/edit/template.hbs index 2f2f678..e53c6e8 100644 --- a/app/pods/protected/users/edit/template.hbs +++ b/app/pods/protected/users/edit/template.hbs @@ -1,7 +1,7 @@ {{ protected/users/user-form user=model - currentUser=session.currentUser + currentUser=currentUser.account save="save" cancel="cancel" }} diff --git a/app/pods/protected/users/index/route.js b/app/pods/protected/users/index/route.js index e8b6bc7..8429726 100644 --- a/app/pods/protected/users/index/route.js +++ b/app/pods/protected/users/index/route.js @@ -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'); } diff --git a/app/pods/protected/users/show/controller.js b/app/pods/protected/users/show/controller.js index 481b126..3c6c549 100644 --- a/app/pods/protected/users/show/controller.js +++ b/app/pods/protected/users/show/controller.js @@ -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'); }), }); diff --git a/app/pods/protected/users/show/route.js b/app/pods/protected/users/show/route.js index 33eeba7..a0c9fd9 100644 --- a/app/pods/protected/users/show/route.js +++ b/app/pods/protected/users/show/route.js @@ -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'); From f06fbd030552c3be53bc8c74f5f23d3cadb3c162 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 16:09:51 -0700 Subject: [PATCH 11/12] Inject session for vanilla ajax requests --- app/pods/protected/compare/results/route.js | 4 +++- app/pods/protected/users/changepassword/controller.js | 3 ++- app/pods/users/new/verify/route.js | 4 +++- app/pods/users/requestlockouthelp/controller.js | 4 +++- app/utils/ajax-request.js | 7 ++++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/pods/protected/compare/results/route.js b/app/pods/protected/compare/results/route.js index e37da66..981fa36 100644 --- a/app/pods/protected/compare/results/route.js +++ b/app/pods/protected/compare/results/route.js @@ -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) { diff --git a/app/pods/protected/users/changepassword/controller.js b/app/pods/protected/users/changepassword/controller.js index 512c539..3b54073 100644 --- a/app/pods/protected/users/changepassword/controller.js +++ b/app/pods/protected/users/changepassword/controller.js @@ -2,6 +2,7 @@ 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, @@ -22,7 +23,7 @@ export default Ember.Controller.extend({ 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.'); }, diff --git a/app/pods/users/new/verify/route.js b/app/pods/users/new/verify/route.js index 0593ba8..7c50823 100644 --- a/app/pods/users/new/verify/route.js +++ b/app/pods/users/new/verify/route.js @@ -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')); }, diff --git a/app/pods/users/requestlockouthelp/controller.js b/app/pods/users/requestlockouthelp/controller.js index 205f73c..d138cc6 100644 --- a/app/pods/users/requestlockouthelp/controller.js +++ b/app/pods/users/requestlockouthelp/controller.js @@ -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'); }, diff --git a/app/utils/ajax-request.js b/app/utils/ajax-request.js index 30eee5f..a4c8de9 100644 --- a/app/utils/ajax-request.js +++ b/app/utils/ajax-request.js @@ -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); }; From 227a85bb01e047f00e1772d819b3bd3673895b8c Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 20 Oct 2015 16:12:35 -0700 Subject: [PATCH 12/12] Clean up delete transitions --- app/pods/protected/characteristics/edit/controller.js | 5 +++-- app/pods/protected/characteristics/show/controller.js | 5 +++-- app/pods/protected/species/new/controller.js | 5 +++-- app/pods/protected/species/show/controller.js | 5 +++-- app/pods/protected/strains/edit/controller.js | 5 +++-- app/pods/protected/strains/show/controller.js | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/pods/protected/characteristics/edit/controller.js b/app/pods/protected/characteristics/edit/controller.js index c16ce3f..2acb5dd 100644 --- a/app/pods/protected/characteristics/edit/controller.js +++ b/app/pods/protected/characteristics/edit/controller.js @@ -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); + }); } }, diff --git a/app/pods/protected/characteristics/show/controller.js b/app/pods/protected/characteristics/show/controller.js index 2ed7872..044b783 100644 --- a/app/pods/protected/characteristics/show/controller.js +++ b/app/pods/protected/characteristics/show/controller.js @@ -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'); + }); }, }, diff --git a/app/pods/protected/species/new/controller.js b/app/pods/protected/species/new/controller.js index 094ea14..1d2cecf 100644 --- a/app/pods/protected/species/new/controller.js +++ b/app/pods/protected/species/new/controller.js @@ -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'); + }); } }, diff --git a/app/pods/protected/species/show/controller.js b/app/pods/protected/species/show/controller.js index cadc1f4..b44b6a7 100644 --- a/app/pods/protected/species/show/controller.js +++ b/app/pods/protected/species/show/controller.js @@ -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'); + }); }, }, diff --git a/app/pods/protected/strains/edit/controller.js b/app/pods/protected/strains/edit/controller.js index b455768..ae093b7 100644 --- a/app/pods/protected/strains/edit/controller.js +++ b/app/pods/protected/strains/edit/controller.js @@ -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); + }); } }, diff --git a/app/pods/protected/strains/show/controller.js b/app/pods/protected/strains/show/controller.js index ab4d552..7128b9a 100644 --- a/app/pods/protected/strains/show/controller.js +++ b/app/pods/protected/strains/show/controller.js @@ -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'); + }); }, },