From b2fb610256c18b75fd8e4f7f9a3c892dfc539038 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 9 Dec 2020 16:49:15 -0500 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20auth=20reset=20?= =?UTF-8?q?bug=20in=20desktop=20due=20to=20init=20before=20origin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/services/storage.js | 1 + ui/desktop/app/initializers/origin.js | 31 +++++++++++++++++++ ui/desktop/app/routes/index.js | 4 +-- ui/desktop/app/services/origin.js | 6 ++-- ui/desktop/config/environment.js | 7 ++++- .../tests/acceptance/authentication-test.js | 6 ++-- ui/desktop/tests/acceptance/projects-test.js | 8 ++--- ui/desktop/tests/acceptance/targets-test.js | 8 ++--- 8 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 ui/desktop/app/initializers/origin.js diff --git a/addons/api/addon/services/storage.js b/addons/api/addon/services/storage.js index ea1b7138d..eeb1da684 100644 --- a/addons/api/addon/services/storage.js +++ b/addons/api/addon/services/storage.js @@ -80,6 +80,7 @@ export default class StorageService extends Service { .documentElement.parentNode.defaultView; // If memory storage enabled, return the memory storage instance, // otherwise return localStorage. + console.log(inMemory); return inMemory ? this.#memoryStorage : globalContext.localStorage; } diff --git a/ui/desktop/app/initializers/origin.js b/ui/desktop/app/initializers/origin.js new file mode 100644 index 000000000..d719bd911 --- /dev/null +++ b/ui/desktop/app/initializers/origin.js @@ -0,0 +1,31 @@ +import { getOwner } from '@ember/application'; + +export function initialize(registry) { + + // Lookup the application route + const ApplicationRoute = registry.resolveRegistration + ? registry.resolveRegistration('route:application') + : registry.resolve('route:application'); + + ApplicationRoute.reopen({ + init() { + this._super(...arguments); + const originalBeforeModel = this.beforeModel; + + // Override the beforeModel hook and initialize the origin + this.beforeModel = async function() { + const origin = getOwner(this).lookup('service:origin'); + console.log('updating origin...', await origin.rendererOrigin); + return origin.updateOrigin().then( + () => originalBeforeModel.apply(this, arguments), + () => originalBeforeModel.apply(this, arguments) + ); + }; + }, + }); +} + +export default { + after: 'ember-simple-auth', + initialize +}; diff --git a/ui/desktop/app/routes/index.js b/ui/desktop/app/routes/index.js index 18b3bd24f..200135491 100644 --- a/ui/desktop/app/routes/index.js +++ b/ui/desktop/app/routes/index.js @@ -4,7 +4,7 @@ import { inject as service } from '@ember/service'; export default class IndexRoute extends Route { // =services - @service session; + @service origin; // =methods @@ -12,7 +12,7 @@ export default class IndexRoute extends Route { * If no origin is specified yet, redirects to origin, otherwise scopes. */ redirect() { - const rendererOrigin = this.session.data.origin; + const rendererOrigin = this.origin.rendererOrigin; if (!rendererOrigin) { this.replaceWith('origin'); } else { diff --git a/ui/desktop/app/services/origin.js b/ui/desktop/app/services/origin.js index 5fe141900..3e397240d 100644 --- a/ui/desktop/app/services/origin.js +++ b/ui/desktop/app/services/origin.js @@ -8,7 +8,7 @@ export default class OriginService extends Service { @service ipc; @service store; - @service session; + @service storage; // =attributes @@ -23,14 +23,14 @@ export default class OriginService extends Service { * @type {?string} */ get rendererOrigin() { - return this.session.data.origin; + return this.storage.getItem('origin'); } /** * @param {?string} origin */ set rendererOrigin(origin) { - this.session.set('data.origin', origin); + this.storage.setItem('origin', origin); } /** diff --git a/ui/desktop/config/environment.js b/ui/desktop/config/environment.js index e4b94e3fc..3d7c0c1b6 100644 --- a/ui/desktop/config/environment.js +++ b/ui/desktop/config/environment.js @@ -2,7 +2,7 @@ const APP_NAME = process.env.APP_NAME || 'Boundary'; const API_HOST = process.env.API_HOST || ''; -const ENABLE_MIRAGE = process.env.API_HOST ? false : true; +const ENABLE_MIRAGE = process.env.ENABLE_MIRAGE ? false : true; module.exports = function (environment) { let ENV = { @@ -70,6 +70,11 @@ module.exports = function (environment) { // Notification timeout should be 0 for fast tests ENV.notifyTimeout = 0; + + // Use in-memory storage + ENV.storage = { + memory: true + }; } if (environment === 'production') { diff --git a/ui/desktop/tests/acceptance/authentication-test.js b/ui/desktop/tests/acceptance/authentication-test.js index 96c1258fc..703ca0ce9 100644 --- a/ui/desktop/tests/acceptance/authentication-test.js +++ b/ui/desktop/tests/acceptance/authentication-test.js @@ -62,9 +62,9 @@ module('Acceptance | authentication', function (hooks) { }; const setDefaultOrigin = (test) => { - const origin = window.location.origin; - const session = test.owner.lookup('service:session'); - session.set('data.origin', origin); + const windowOrigin = window.location.origin; + const origin = test.owner.lookup('service:origin'); + origin.rendererOrigin = windowOrigin; }; hooks.beforeEach(function () { diff --git a/ui/desktop/tests/acceptance/projects-test.js b/ui/desktop/tests/acceptance/projects-test.js index a973db904..b3298cca9 100644 --- a/ui/desktop/tests/acceptance/projects-test.js +++ b/ui/desktop/tests/acceptance/projects-test.js @@ -60,9 +60,9 @@ module('Acceptance | projects', function (hooks) { }; const setDefaultOrigin = (test) => { - const origin = window.location.origin; - const session = test.owner.lookup('service:session'); - session.set('data.origin', origin); + const windowOrigin = window.location.origin; + const origin = test.owner.lookup('service:origin'); + origin.rendererOrigin = windowOrigin; }; hooks.beforeEach(function () { @@ -102,7 +102,7 @@ module('Acceptance | projects', function (hooks) { urls.authenticate.global = `${urls.scopes.global}/authenticate`; urls.authenticate.methods.global = `${urls.authenticate.global}/${instances.authMethods.global.id}`; urls.projects = `${urls.scopes.org}/projects`; - + class MockIPC { origin = null; diff --git a/ui/desktop/tests/acceptance/targets-test.js b/ui/desktop/tests/acceptance/targets-test.js index 6f7cd30e4..968b677d1 100644 --- a/ui/desktop/tests/acceptance/targets-test.js +++ b/ui/desktop/tests/acceptance/targets-test.js @@ -61,9 +61,9 @@ module('Acceptance | targets', function (hooks) { }; const setDefaultOrigin = (test) => { - const origin = window.location.origin; - const session = test.owner.lookup('service:session'); - session.set('data.origin', origin); + const windowOrigin = window.location.origin; + const origin = test.owner.lookup('service:origin'); + origin.rendererOrigin = windowOrigin; }; hooks.beforeEach(function () { @@ -104,7 +104,7 @@ module('Acceptance | targets', function (hooks) { urls.authenticate.methods.global = `${urls.authenticate.global}/${instances.authMethods.global.id}`; urls.projects = `${urls.scopes.org}/projects`; urls.targets = `${urls.projects}/targets`; - + class MockIPC { origin = null; From c4149ae93e0ac64565af0a0b82991f8df03f11eb Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 9 Dec 2020 17:06:10 -0500 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20remove=20console.log?= =?UTF-8?q?=20statements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/services/storage.js | 1 - ui/desktop/app/initializers/origin.js | 1 - 2 files changed, 2 deletions(-) diff --git a/addons/api/addon/services/storage.js b/addons/api/addon/services/storage.js index eeb1da684..ea1b7138d 100644 --- a/addons/api/addon/services/storage.js +++ b/addons/api/addon/services/storage.js @@ -80,7 +80,6 @@ export default class StorageService extends Service { .documentElement.parentNode.defaultView; // If memory storage enabled, return the memory storage instance, // otherwise return localStorage. - console.log(inMemory); return inMemory ? this.#memoryStorage : globalContext.localStorage; } diff --git a/ui/desktop/app/initializers/origin.js b/ui/desktop/app/initializers/origin.js index d719bd911..0a3abfc39 100644 --- a/ui/desktop/app/initializers/origin.js +++ b/ui/desktop/app/initializers/origin.js @@ -15,7 +15,6 @@ export function initialize(registry) { // Override the beforeModel hook and initialize the origin this.beforeModel = async function() { const origin = getOwner(this).lookup('service:origin'); - console.log('updating origin...', await origin.rendererOrigin); return origin.updateOrigin().then( () => originalBeforeModel.apply(this, arguments), () => originalBeforeModel.apply(this, arguments)