70373: Stop impersonating button in navbar + clear cookie on logout

This commit is contained in:
Kristof De Langhe
2020-04-15 13:08:04 +02:00
parent e43aa15a70
commit c48bb2cbb0
9 changed files with 64 additions and 2 deletions

View File

@@ -1754,6 +1754,8 @@
"nav.statistics.header": "Statistics",
"nav.stop-impersonating": "Stop impersonating EPerson",
"orgunit.listelement.badge": "Organizational Unit",

View File

@@ -402,7 +402,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
* Stop impersonating the EPerson
*/
stopImpersonating() {
this.authService.stopImpersonating();
this.authService.stopImpersonatingAndRefresh();
this.isImpersonated = false;
}

View File

@@ -201,6 +201,7 @@ export class AuthEffects {
.pipe(
ofType(AuthActionTypes.LOG_OUT),
switchMap(() => {
this.authService.stopImpersonating();
return this.authService.logout().pipe(
map((value) => new LogOutSuccessAction()),
catchError((error) => observableOf(new LogOutErrorAction(error)))

View File

@@ -513,6 +513,13 @@ export class AuthService {
*/
stopImpersonating() {
this.storage.remove(IMPERSONATING_COOKIE);
}
/**
* Stop impersonating EPerson and refresh the store/ui
*/
stopImpersonatingAndRefresh() {
this.stopImpersonating();
this.refreshAfterLogout();
}

View File

@@ -8,6 +8,7 @@
<ds-search-navbar></ds-search-navbar>
<ds-lang-switch></ds-lang-switch>
<ds-auth-nav-menu></ds-auth-nav-menu>
<ds-impersonate-navbar></ds-impersonate-navbar>
<div class="pl-2">
<button class="navbar-toggler" type="button" (click)="toggleNavbar()"
aria-controls="collapsingNav"

View File

@@ -0,0 +1,7 @@
<ul class="navbar-nav" *ngIf="(isAuthenticated$ | async) && isImpersonating">
<li class="nav-item">
<button class="btn btn-sm btn-dark" ngbTooltip="{{'nav.stop-impersonating' | translate}}" (click)="stopImpersonating()">
<i class="fa fa-user-secret"></i>
</button>
</li>
</ul>

View File

@@ -0,0 +1,42 @@
import { Component, OnInit } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { AppState } from '../../app.reducer';
import { AuthService } from '../../core/auth/auth.service';
import { Observable } from 'rxjs/internal/Observable';
import { isAuthenticated } from '../../core/auth/selectors';
@Component({
selector: 'ds-impersonate-navbar',
templateUrl: 'impersonate-navbar.component.html'
})
/**
* Navbar component for actions to take concerning impersonating users
*/
export class ImpersonateNavbarComponent implements OnInit {
/**
* Whether or not the user is authenticated.
* @type {Observable<string>}
*/
isAuthenticated$: Observable<boolean>;
/**
* Is the user currently impersonating another user?
*/
isImpersonating: boolean;
constructor(private store: Store<AppState>,
private authService: AuthService) {
}
ngOnInit(): void {
this.isAuthenticated$ = this.store.pipe(select(isAuthenticated));
this.isImpersonating = this.authService.isImpersonating();
}
/**
* Stop impersonating the user
*/
stopImpersonating() {
this.authService.stopImpersonatingAndRefresh();
}
}

View File

@@ -191,6 +191,7 @@ import { ItemVersionsNoticeComponent } from './item/item-versions/notice/item-ve
import { ClaimedTaskActionsLoaderComponent } from './mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component';
import { ClaimedTaskActionsDirective } from './mydspace-actions/claimed-task/switcher/claimed-task-actions.directive';
import { ClaimedTaskActionsEditMetadataComponent } from './mydspace-actions/claimed-task/edit-metadata/claimed-task-actions-edit-metadata.component';
import { ImpersonateNavbarComponent } from './impersonate-navbar/impersonate-navbar.component';
const MODULES = [
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
@@ -367,7 +368,8 @@ const COMPONENTS = [
LogInContainerComponent,
ItemVersionsComponent,
PublicationSearchResultListElementComponent,
ItemVersionsNoticeComponent
ItemVersionsNoticeComponent,
ImpersonateNavbarComponent
];
const ENTRY_COMPONENTS = [