[Desktop][Bug fix]: Stop target sessions before unauthenticating user session (#2891)
* add stopAll invocation to ipc handler * trigger modal on both signout btns * refactor invalidateSession fn * fix application controller tests * fix failing tests settings-card/user * add test to Acceptance | authentication * migrate electron dialog.showMessageBoxSync to Hds * rename channel and tracked prop, consolidate cancel fns * combine modals, add willDestroy, refactor * test signout and close sessions modal * address feedback * refactor window.electron in authentication-test * address feedback * refactor: 💡 Fix failing tests --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
1 parent
f776ba0617
commit
990e2d6b9d
20 files changed
+342
-84
No files matched your search
@@ -7,22 +7,63 @@ import Controller from '@ember/controller';
|
||||
import { service } from '@ember/service';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
|
||||
export default class ApplicationController extends Controller {
|
||||
// =services
|
||||
|
||||
@service ipc;
|
||||
@service session;
|
||||
@service clusterUrl;
|
||||
@service flashMessages;
|
||||
@service ipc;
|
||||
@service session;
|
||||
@service('browser/window') window;
|
||||
|
||||
@tracked isLoggingOut = false;
|
||||
@tracked isAppQuitting = false;
|
||||
|
||||
// =attributes
|
||||
removeOnAppQuitListener;
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
// Listen for when user attempts to quit app
|
||||
// Setup removeOnAppQuitListener to destroy the listener afterwards
|
||||
this.removeOnAppQuitListener = this.window.electron?.onAppQuit(() => {
|
||||
this.isAppQuitting = true;
|
||||
});
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Delegates invalidation to the session service.
|
||||
* Stop all active/pending target sessions
|
||||
* Logout or close app
|
||||
*/
|
||||
@action
|
||||
invalidateSession() {
|
||||
this.session.invalidate();
|
||||
async confirmCloseSessions() {
|
||||
await this.ipc.invoke('stopAll');
|
||||
if (this.isAppQuitting) {
|
||||
this.isAppQuitting = false;
|
||||
this.close();
|
||||
} else {
|
||||
// this.session.invalidate() comes from Ember Simple Auth BaseSessionService
|
||||
this.session.invalidate();
|
||||
}
|
||||
|
||||
this.isLoggingOut = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only renders the signout modal if target sessions are running
|
||||
*/
|
||||
@action
|
||||
async showModalOrLogout() {
|
||||
const hasRunningSessions = await this.ipc.invoke('hasRunningSessions');
|
||||
if (hasRunningSessions) {
|
||||
this.isLoggingOut = true;
|
||||
} else {
|
||||
this.session.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +73,7 @@ export default class ApplicationController extends Controller {
|
||||
@action
|
||||
disconnect() {
|
||||
this.clusterUrl.resetClusterUrl();
|
||||
this.invalidateSession();
|
||||
this.session.invalidate();
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -75,4 +116,15 @@ export default class ApplicationController extends Controller {
|
||||
rootEl.classList.remove('rose-theme-light');
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
cancel() {
|
||||
this.isLoggingOut = false;
|
||||
this.isAppQuitting = false;
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
super.willDestroy(...arguments);
|
||||
this.removeOnAppQuitListener?.();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user