RED-3158: Fixed disabled accounts, again

This commit is contained in:
Adina Țeudan 2022-01-10 21:21:27 +02:00
parent fc849196e3
commit f9359d509a
4 changed files with 17 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import { UserPreferenceService } from '@services/user-preference.service';
export class LanguageService {
constructor(private readonly _translateService: TranslateService, private readonly _userPreferenceService: UserPreferenceService) {
_translateService.addLangs(['en', 'de']);
_translateService.setDefaultLang('en');
}
get currentLanguage() {

View File

@ -3,6 +3,7 @@
:host {
@extend .user-button;
min-width: fit-content;
button {
padding: 0 10px 0 5px;

View File

@ -1,17 +1,17 @@
import { Injectable, Injector } from '@angular/core';
import { GenericService, RequiredParam, Validate } from '@iqser/common-ui';
import { IGeneralConfiguration } from '@red/domain';
import { UserService } from '@services/user.service';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class GeneralSettingsService extends GenericService<IGeneralConfiguration> {
constructor(protected readonly _injector: Injector, private readonly _userService: UserService) {
constructor(protected readonly _injector: Injector) {
super(_injector, 'configuration');
}
getGeneralConfigurations() {
getGeneralConfigurations(): Observable<IGeneralConfiguration> {
return this._getOne(['general']);
}

View File

@ -1,11 +1,11 @@
import { catchError, filter, mergeMap, switchMap, take, tap } from 'rxjs/operators';
import { catchError, filter, mapTo, switchMap, take, tap } from 'rxjs/operators';
import { ConfigService } from '@services/config.service';
import { Title } from '@angular/platform-browser';
import { from, of, throwError } from 'rxjs';
import { KeycloakEventType, KeycloakService } from 'keycloak-angular';
import { GeneralSettingsService } from '@services/general-settings.service';
import { LanguageService } from '@i18n/language.service';
import { UserPreferenceService } from '@services/user-preference.service';
import { from, iif, of, throwError } from 'rxjs';
export function configurationInitializer(
keycloakService: KeycloakService,
@ -15,16 +15,22 @@ export function configurationInitializer(
languageService: LanguageService,
userPreferenceService: UserPreferenceService,
) {
const userConfig$ = generalSettingsService.getGeneralConfigurations().pipe(
switchMap(config => from(userPreferenceService.reload()).pipe(mapTo(config))),
tap(() => languageService.chooseAndSetInitialLanguage()),
);
return () =>
keycloakService.keycloakEvents$
.pipe(
filter(event => event.type === KeycloakEventType.OnReady),
switchMap(() => from(keycloakService.isLoggedIn())),
switchMap(loggedIn => (!loggedIn ? throwError('Not Logged In') : of({}))),
mergeMap(() => generalSettingsService.getGeneralConfigurations()),
switchMap(loggedIn => {
const hasAnyRedRoles = !!keycloakService.getUserRoles().find(role => role.startsWith('RED_'));
return !loggedIn ? throwError('Not Logged In') : of(hasAnyRedRoles);
}),
switchMap(hasRoles => iif(() => !!hasRoles, userConfig$, of({ displayName: 'RedactManager' }))),
tap(configuration => configService.updateDisplayName(configuration.displayName)),
switchMap(() => userPreferenceService.reload()),
tap(() => languageService.chooseAndSetInitialLanguage()),
catchError(() => {
title.setTitle('RedactManager');
return of({});