diff --git a/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.ts index ca482ad65..1c66e3089 100644 --- a/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.ts @@ -1,7 +1,7 @@ import { Component, ElementRef, ViewChild } from '@angular/core'; import { PermissionsService } from '../../../../services/permissions.service'; import { AceEditorComponent } from 'ng2-ace-editor'; -import { RulesControllerService, RuleSetModel } from '@redaction/red-ui-http'; +import { RulesControllerService } from '@redaction/red-ui-http'; import { NotificationService, NotificationType } from '../../../../services/notification.service'; import { TranslateService } from '@ngx-translate/core'; import { saveAs } from 'file-saver'; @@ -89,7 +89,10 @@ export class RulesScreenComponent extends ComponentHasChanges { public async save(): Promise { this.processing = true; this._rulesControllerService - .uploadRules({ rules: this.editorComponent.getEditor().getValue(), ruleSetId: this._appStateService.activeRuleSetId }) + .uploadRules({ + rules: this.editorComponent.getEditor().getValue(), + ruleSetId: this._appStateService.activeRuleSetId + }) .subscribe( () => { this._initialize(); diff --git a/apps/red-ui/src/app/modules/auth/red-role.guard.ts b/apps/red-ui/src/app/modules/auth/red-role.guard.ts index e000de15c..67c7482c2 100644 --- a/apps/red-ui/src/app/modules/auth/red-role.guard.ts +++ b/apps/red-ui/src/app/modules/auth/red-role.guard.ts @@ -19,6 +19,14 @@ export class RedRoleGuard implements CanActivate { obs.complete(); } else { // we have at least 1 RED Role -> if it's not user he must be admin + + if (this._userService.user.isUserAdmin && !this._userService.user.isAdmin && !state.url.startsWith('/main/admin/users')) { + this._router.navigate(['/main/admin/users']); + obs.next(false); + obs.complete(); + return; + } + if (!this._userService.isUser() && state.url.startsWith('/main/projects')) { this._router.navigate(['/main/admin']); obs.next(false); diff --git a/apps/red-ui/src/app/services/user.service.ts b/apps/red-ui/src/app/services/user.service.ts index cf36830c8..026e78f18 100644 --- a/apps/red-ui/src/app/services/user.service.ts +++ b/apps/red-ui/src/app/services/user.service.ts @@ -31,6 +31,10 @@ export class UserWrapper { return this.roles.indexOf('RED_MANAGER') >= 0; } + get isUserAdmin() { + return this.roles.indexOf('RED_USER_ADMIN') >= 0; + } + get isUser() { return this.roles.indexOf('RED_USER') >= 0; } @@ -39,12 +43,8 @@ export class UserWrapper { return this.roles.indexOf('RED_ADMIN') >= 0; } - get isUserAdmin() { - return this.roles.indexOf('RED_USER_ADMIN') >= 0; - } - get hasAnyREDRoles() { - return this.isUser || this.isManager || this.isAdmin; + return this.isUser || this.isManager || this.isAdmin || this.isUserAdmin; } } @@ -153,7 +153,12 @@ export class UserService { } private _hasAnyRedRole(u: User) { - return u.roles.indexOf('RED_USER') >= 0 || u.roles.indexOf('RED_MANAGER') >= 0 || u.roles.indexOf('RED_ADMIN') >= 0; + return ( + u.roles.indexOf('RED_USER') >= 0 || + u.roles.indexOf('RED_MANAGER') >= 0 || + u.roles.indexOf('RED_ADMIN') >= 0 || + u.roles.indexOf('RED_USER_ADMIN') >= 0 + ); } hasAnyRole(requiredRoles: string[], user?: User) { diff --git a/apps/red-ui/src/app/state/app-state.guard.ts b/apps/red-ui/src/app/state/app-state.guard.ts index 04ee71894..3c59af301 100644 --- a/apps/red-ui/src/app/state/app-state.guard.ts +++ b/apps/red-ui/src/app/state/app-state.guard.ts @@ -10,10 +10,16 @@ export class AppStateGuard implements CanActivate { constructor(private readonly _appStateService: AppStateService, private readonly _userService: UserService, private readonly _router: Router) {} async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { - await this._userService.loadAllUsersIfNecessary(); - await this._appStateService.loadRuleSetsIfNecessary(); - await this._appStateService.loadDictionaryDataIfNecessary(); - await this._appStateService.updateDictionaryVersion(); + if (this._userService.user.isUserAdmin) { + await this._userService.loadAllUsersIfNecessary(); + } + + if (this._userService.user.isUser || this._userService.user.isAdmin) { + await this._userService.loadAllUsersIfNecessary(); + await this._appStateService.loadRuleSetsIfNecessary(); + await this._appStateService.loadDictionaryDataIfNecessary(); + await this._appStateService.updateDictionaryVersion(); + } if (this._userService.isUser()) { await this._appStateService.loadAllProjectsIfNecessary(); @@ -40,6 +46,7 @@ export class AppStateGuard implements CanActivate { await this._router.navigate(['main', 'admin', 'project-templates', ruleSetId]); return false; } + return true; } }