refactor: 💡 remove usage of ember/runloop & ember-pollster (#2705)
* refactor: 💡 remove usage of ember/runloop & ember-pollster --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
1 parent
e29a83ec25
commit
29bde998ed
23 files changed
+225
-197
No files matched your search
@@ -5,9 +5,7 @@
|
||||
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { computed } from '@ember/object';
|
||||
import { action } from '@ember/object';
|
||||
import { run } from '@ember/runloop';
|
||||
|
||||
export default class FormAccountPasswordChangePasswordIndexComponent extends Component {
|
||||
// =properties
|
||||
@@ -25,7 +23,6 @@ export default class FormAccountPasswordChangePasswordIndexComponent extends Com
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
@computed('currentPassword', 'newPassword')
|
||||
get canSave() {
|
||||
return this.currentPassword && this.newPassword;
|
||||
}
|
||||
@@ -33,7 +30,6 @@ export default class FormAccountPasswordChangePasswordIndexComponent extends Com
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
@computed('canSave')
|
||||
get cannotSave() {
|
||||
return !this.canSave;
|
||||
}
|
||||
@@ -41,7 +37,7 @@ export default class FormAccountPasswordChangePasswordIndexComponent extends Com
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Unsets the password fields.
|
||||
* Un-sets the password fields.
|
||||
*/
|
||||
resetPasswords() {
|
||||
this.currentPassword = null;
|
||||
@@ -52,15 +48,15 @@ export default class FormAccountPasswordChangePasswordIndexComponent extends Com
|
||||
|
||||
/**
|
||||
* Call passed submit function with passwords.
|
||||
* Unset passwords before callack.
|
||||
* Unset passwords before callback.
|
||||
* @param {function} fn
|
||||
* @param {string} currentPassword
|
||||
* @param {string} newPassword
|
||||
*/
|
||||
@action
|
||||
submit(fn, currentPassword, newPassword) {
|
||||
run(() => this.resetPasswords());
|
||||
run(() => fn(currentPassword, newPassword));
|
||||
this.resetPasswords();
|
||||
fn(currentPassword, newPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { next } from '@ember/runloop';
|
||||
|
||||
export default class FormAccountPasswordIndexComponent extends Component {
|
||||
// =properties
|
||||
@@ -36,7 +35,7 @@ export default class FormAccountPasswordIndexComponent extends Component {
|
||||
@action
|
||||
submit(fn) {
|
||||
const password = this.password;
|
||||
next(() => this.resetPassword());
|
||||
this.resetPassword();
|
||||
return this.args.model.isNew ? fn(password) : fn();
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,7 @@
|
||||
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { computed } from '@ember/object';
|
||||
import { action } from '@ember/object';
|
||||
import { run } from '@ember/runloop';
|
||||
|
||||
export default class FormAccountPasswordSetPasswordIndexComponent extends Component {
|
||||
// =properties
|
||||
@@ -21,7 +19,6 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
@computed('password')
|
||||
get cannotSave() {
|
||||
return !this.password;
|
||||
}
|
||||
@@ -45,7 +42,7 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon
|
||||
*/
|
||||
@action
|
||||
submit(fn, password) {
|
||||
run(() => this.resetPassword());
|
||||
run(() => fn(password));
|
||||
this.resetPassword();
|
||||
fn(password);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import Route from '@ember/routing/route';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import runEvery from 'ember-pollster/decorators/route/run-every';
|
||||
import { task, timeout } from 'ember-concurrency';
|
||||
import { notifyError } from 'core/decorators/notify';
|
||||
import config from '../../../../../config/environment';
|
||||
|
||||
@@ -20,6 +20,15 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
@service windowManager;
|
||||
@service router;
|
||||
|
||||
// =attributes
|
||||
|
||||
poller = task(async () => {
|
||||
while (!this.session.isAuthenticated) {
|
||||
await timeout(POLL_TIMEOUT_SECONDS * 1000);
|
||||
this.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
// =methods
|
||||
|
||||
beforeModel;
|
||||
@@ -43,9 +52,11 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
controller.authMethod = authMethod;
|
||||
}
|
||||
|
||||
@runEvery(POLL_TIMEOUT_SECONDS * 1000)
|
||||
poller() {
|
||||
this.refresh();
|
||||
/**
|
||||
* When this route is activated (entered), start polling for authentication.
|
||||
*/
|
||||
activate() {
|
||||
this.poller.perform();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,6 +64,7 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
* any windows opened via the window manager service.
|
||||
*/
|
||||
deactivate() {
|
||||
this.poller.cancelAll();
|
||||
this.windowManager.closeAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@ module.exports = function (environment) {
|
||||
appName: APP_NAME,
|
||||
companyName: 'HashiCorp',
|
||||
|
||||
sessionPollingTimeoutSeconds: 300,
|
||||
oidcPollingTimeoutSeconds: 1,
|
||||
|
||||
documentation: {
|
||||
@@ -195,6 +194,8 @@ module.exports = function (environment) {
|
||||
|
||||
// Notification timeout should be 0 for fast tests
|
||||
ENV.flashMessageDefaults.timeout = 0;
|
||||
// OIDC Authentication timeout should be 0 for fast tests
|
||||
ENV.oidcPollingTimeoutSeconds = 0;
|
||||
|
||||
ENV.enableConfirmService = false;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ module.exports = function (defaults) {
|
||||
},
|
||||
babel: {
|
||||
sourceMaps: 'inline',
|
||||
plugins: [
|
||||
require.resolve('ember-concurrency/async-arrow-task-transform'),
|
||||
],
|
||||
},
|
||||
sourcemaps: {
|
||||
enabled: true,
|
||||
@@ -34,7 +37,7 @@ module.exports = function (defaults) {
|
||||
},
|
||||
},
|
||||
// TODO: Update to 4.12 when deprecations are resolved
|
||||
// as multiple things break when forcing compatability on > 4.6
|
||||
// as multiple things break when forcing compatibility on > 4.6
|
||||
emberData: {
|
||||
compatWith: '4.6',
|
||||
},
|
||||
|
||||
@@ -71,12 +71,12 @@
|
||||
"ember-cli-sass": "^11.0.1",
|
||||
"ember-cli-sri": "^2.1.1",
|
||||
"ember-cli-terser": "^4.0.2",
|
||||
"ember-concurrency": "^4.0.3",
|
||||
"ember-exam": "^8.0.0",
|
||||
"ember-inline-svg": "^1.0.1",
|
||||
"ember-load-initializers": "^2.1.2",
|
||||
"ember-modifier": "^4.1.0",
|
||||
"ember-page-title": "^7.0.0",
|
||||
"ember-pollster": "https://github.com/hashicorp/ember-pollster.git#605d82e986d829b098667e4a5e221877a4ee4ac8",
|
||||
"ember-qunit": "^8.1.0",
|
||||
"ember-resolver": "^10.0.0",
|
||||
"ember-source": "~4.12.0",
|
||||
|
||||
@@ -16,7 +16,6 @@ import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { Response } from 'miragejs';
|
||||
import { runAllJobs } from 'ember-pollster/test-support';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import {
|
||||
currentSession,
|
||||
@@ -86,7 +85,7 @@ module('Acceptance | authentication', function (hooks) {
|
||||
},
|
||||
'withChildren',
|
||||
);
|
||||
// create an emtpy org with no auth methods
|
||||
// create an empty org with no auth methods
|
||||
this.server.create(
|
||||
'scope',
|
||||
{
|
||||
@@ -391,9 +390,6 @@ module('Acceptance | authentication', function (hooks) {
|
||||
);
|
||||
await visit(authMethodOIDCAuthenticateURL);
|
||||
await click('form [type="submit"]');
|
||||
// explicitly poll multiple times to trigger mock OIDC auth
|
||||
await runAllJobs();
|
||||
await runAllJobs();
|
||||
});
|
||||
|
||||
// TODO: test OIDC retry and cancel
|
||||
|
||||
Reference in new issue
Block a user