Skip to content

Commit

Permalink
Turn off auto-logout if the user can not log off
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Nov 12, 2020
1 parent 0c2634a commit 7ec7339
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/frontend/packages/core/src/logged-in.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DOCUMENT } from '@angular/common';
import { Inject, Injectable, NgZone } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { fromEvent, interval, merge, Subscription } from 'rxjs';
import { combineLatest, fromEvent, interval, merge, Subscription } from 'rxjs';
import { tap, withLatestFrom } from 'rxjs/operators';

import { VerifySession } from '../../store/src/actions/auth.actions';
Expand All @@ -12,16 +12,18 @@ import { selectDashboardState } from '../../store/src/selectors/dashboard.select
import { DashboardState } from './../../store/src/reducers/dashboard-reducer';
import { LogOutDialogComponent } from './core/log-out-dialog/log-out-dialog.component';
import { PageVisible } from './core/page-visible';
import { CurrentUserPermissionsService } from './core/permissions/current-user-permissions.service';
import { StratosCurrentUserPermissions } from './core/permissions/stratos-user-permissions.checker';

@Injectable()
export class LoggedInService {
constructor(
@Inject(DOCUMENT) private document: Document,
private store: Store<AppState>,
private dialog: MatDialog,
private ngZone: NgZone
) {
}
private ngZone: NgZone,
private currentUserPermissionsService: CurrentUserPermissionsService,
) { }

private userInteractionChecker: Subscription;

Expand Down Expand Up @@ -53,24 +55,25 @@ export class LoggedInService {
return fromEvent(document, eventName);
});

this.sub = this.store.select(s => s.auth)
.subscribe((auth: AuthState) => {
if (auth.loggedIn && auth.sessionData && auth.sessionData.valid && !auth.error) {
if (!this.sessionChecker || this.sessionChecker.closed) {
this.openSessionCheckerPoll();
}
if (!this.userInteractionChecker) {
this.userInteractionChecker = merge(...eventStreams).subscribe(() => {
this.lastUserInteraction = Date.now();
});
}
} else {
this.closeSessionCheckerPoll();
if (this.userInteractionChecker) {
this.userInteractionChecker.unsubscribe();
}
const auth$ = this.store.select(s => s.auth);
const canNotLogout$ = this.currentUserPermissionsService.can(StratosCurrentUserPermissions.CAN_NOT_LOGOUT);
this.sub = combineLatest([auth$, canNotLogout$]).subscribe(([auth, canNotLogout]) => {
if (!canNotLogout && auth.loggedIn && auth.sessionData && auth.sessionData.valid && !auth.error) {
if (!this.sessionChecker || this.sessionChecker.closed) {
this.openSessionCheckerPoll();
}
if (!this.userInteractionChecker) {
this.userInteractionChecker = merge(...eventStreams).subscribe(() => {
this.lastUserInteraction = Date.now();
});
}
} else {
this.closeSessionCheckerPoll();
if (this.userInteractionChecker) {
this.userInteractionChecker.unsubscribe();
}
});
}
});
}

destroy() {
Expand Down

0 comments on commit 7ec7339

Please sign in to comment.