Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { run } from '@ember/runloop';

export default class FormAuthenticateDetailsComponent extends Component {
// =properties
Expand Down Expand Up @@ -36,7 +35,7 @@ export default class FormAuthenticateDetailsComponent extends Component {
*/
@action
submit(fn, creds) {
run(() => this.resetPassword());
run(() => fn(creds));
this.resetPassword();
fn(creds);
}
}
4 changes: 2 additions & 2 deletions addons/core/addon/components/loading-button/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Hds::Button
@text={{t 'actions.refresh'}}
@color='secondary'
@icon={{if this.isLoading 'loading' 'reload'}}
@icon={{if this.toggleRefresh.isRunning 'loading' 'reload'}}
@disabled={{this.isLoading}}
{{on 'click' this.toggleRefresh}}
{{on 'click' this.toggleRefresh.perform}}
/>
21 changes: 6 additions & 15 deletions addons/core/addon/components/loading-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@
*/

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { later } from '@ember/runloop';
import { dropTask, timeout } from 'ember-concurrency';

export default class LoadingButton extends Component {
// =actions
@tracked isLoading = false;
// =attributes

@action
async toggleRefresh() {
this.isLoading = true;
try {
await this.args.onClick();
} catch (e) {
console.error('Error while loading data', e);
}
later(() => (this.isLoading = false), 1000);
}
toggleRefresh = dropTask(async () => {
await this.args.onClick();
await timeout(1000);
});
}
4 changes: 2 additions & 2 deletions addons/core/addon/helpers/time-remaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export default class extends Helper {
// Parse the expiration time
const expirationTime = new Date(expiration_time);

// Get the curent time
// Get the current time
const currentTime = this.clockTick.now;

// Calculate the difference in milleseconds
// Calculate the difference in milliseconds
const difference = expirationTime - currentTime;

// Calculate the difference in seconds if the difference is positive
Expand Down
41 changes: 11 additions & 30 deletions addons/core/addon/services/clock-tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { getOwner } from '@ember/application';
import { next } from '@ember/runloop';
import { task, timeout } from 'ember-concurrency';

export default class ClockTickService extends Service {
// =attributes
Expand All @@ -25,9 +25,15 @@ export default class ClockTickService extends Service {
frequency = 1000;

/**
* The timer interval ID
* Updates the value of `now` every `frequency` milliseconds.
*/
#timer;
_tick = task(async () => {
// eslint-disable-next-line no-constant-condition
while (true) {
await timeout(this.frequency);
this.now = Date.now();
}
});

/**
* This service is enabled only in non-test environments.
Expand All @@ -45,39 +51,14 @@ export default class ClockTickService extends Service {
*/
constructor() {
super(...arguments);
if (this.enabled) this._start();
if (this.enabled) this._tick.perform();
}

/**
* Stops the timer.
*/
willDestroy() {
super.willDestroy(...arguments);
this._stop();
}

/**
* Sets up the timer interval, calling `_tick()` every
* `frequency` milliseconds.
*/
_start() {
const self = this;
this.#timer = setInterval(function () {
self._tick();
}, this.frequency);
}

/**
* Clears the timer interval.
*/
_stop() {
clearInterval(this.#timer);
}

/**
* Updates the value of `now` within the next runloop.
*/
_tick() {
next(() => (this.now = Date.now()));
this._tick.cancelAll();
}
}
5 changes: 5 additions & 0 deletions addons/core/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ module.exports = function (defaults) {
'ember-simple-auth': {
useSessionSetupMethod: true,
},
babel: {
plugins: [
require.resolve('ember-concurrency/async-arrow-task-transform'),
],
},
});

/*
Expand Down
8 changes: 8 additions & 0 deletions addons/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ var path = require('path');
module.exports = {
name: require('./package').name,

options: {
babel: {
plugins: [
require.resolve('ember-concurrency/async-arrow-task-transform'),
],
},
},

included(app) {
this._super.included.apply(this, arguments);
this.includePublic(app);
Expand Down
1 change: 1 addition & 0 deletions addons/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.2.0",
"ember-cli-sass": "^11.0.1",
"ember-concurrency": "^4.0.3",
"ember-feature-flags": "^6.0.0",
"ember-intl": "^7.0.7",
"ember-loading": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,23 +23,21 @@ export default class FormAccountPasswordChangePasswordIndexComponent extends Com
/**
* @type {boolean}
*/
@computed('currentPassword', 'newPassword')
get canSave() {
return this.currentPassword && this.newPassword;
}

/**
* @type {boolean}
*/
@computed('canSave')
get cannotSave() {
return !this.canSave;
}

// =methods

/**
* Unsets the password fields.
* Un-sets the password fields.
*/
resetPasswords() {
this.currentPassword = null;
Expand All @@ -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);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions ui/admin/app/components/form/account/password/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +19,6 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon
/**
* @type {boolean}
*/
@computed('password')
get cannotSave() {
return !this.password;
}
Expand All @@ -45,7 +42,7 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon
*/
@action
submit(fn, password) {
run(() => this.resetPassword());
run(() => fn(password));
this.resetPassword();
fn(password);
}
}
20 changes: 16 additions & 4 deletions ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand All @@ -43,16 +52,19 @@ 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();
}

/**
* When this route is deactivated (exited), stop polling for changes and close
* any windows opened via the window manager service.
*/
deactivate() {
this.poller.cancelAll();
this.windowManager.closeAll();
}

Expand Down
3 changes: 2 additions & 1 deletion ui/admin/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module.exports = function (environment) {
appName: APP_NAME,
companyName: 'HashiCorp',

sessionPollingTimeoutSeconds: 300,
oidcPollingTimeoutSeconds: 1,

documentation: {
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion ui/admin/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = function (defaults) {
},
babel: {
sourceMaps: 'inline',
plugins: [
require.resolve('ember-concurrency/async-arrow-task-transform'),
],
},
sourcemaps: {
enabled: true,
Expand All @@ -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',
},
Expand Down
2 changes: 1 addition & 1 deletion ui/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions ui/admin/tests/acceptance/authentication-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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
Expand Down
Loading