diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index 7f9c41c366..d41f314325 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -1754,6 +1754,8 @@ "nav.statistics.header": "Statistics", + "nav.stop-impersonating": "Stop impersonating EPerson", + "orgunit.listelement.badge": "Organizational Unit", diff --git a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts index f886514ded..f221042418 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts +++ b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts @@ -402,7 +402,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy { * Stop impersonating the EPerson */ stopImpersonating() { - this.authService.stopImpersonating(); + this.authService.stopImpersonatingAndRefresh(); this.isImpersonated = false; } diff --git a/src/app/core/auth/auth.effects.ts b/src/app/core/auth/auth.effects.ts index 35d5e7b043..717aaff01e 100644 --- a/src/app/core/auth/auth.effects.ts +++ b/src/app/core/auth/auth.effects.ts @@ -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))) diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 7d642e60d2..ce0fafe277 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -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(); } diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html index 58f7cb1ecf..5ce0cdb410 100644 --- a/src/app/header/header.component.html +++ b/src/app/header/header.component.html @@ -8,6 +8,7 @@ +
+ + diff --git a/src/app/shared/impersonate-navbar/impersonate-navbar.component.spec.ts b/src/app/shared/impersonate-navbar/impersonate-navbar.component.spec.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/impersonate-navbar/impersonate-navbar.component.ts b/src/app/shared/impersonate-navbar/impersonate-navbar.component.ts new file mode 100644 index 0000000000..19293566ef --- /dev/null +++ b/src/app/shared/impersonate-navbar/impersonate-navbar.component.ts @@ -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} + */ + isAuthenticated$: Observable; + + /** + * Is the user currently impersonating another user? + */ + isImpersonating: boolean; + + constructor(private store: Store, + 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(); + } +} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index a136b7826c..ccf4b6d223 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -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 = [