Removed app state guard
This commit is contained in:
parent
d3d8b16f8e
commit
f6da0da6de
@ -16,7 +16,6 @@
|
||||
"@components/**",
|
||||
"@guards/**",
|
||||
"@i18n/**",
|
||||
"@state/**",
|
||||
"@utils/**",
|
||||
"@models/**",
|
||||
"@environments/**",
|
||||
|
||||
@ -6,7 +6,6 @@ import { BaseScreenComponent } from '@components/base-screen/base-screen.compone
|
||||
import { RouteReuseStrategy, RouterModule, Routes } from '@angular/router';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { DownloadsListScreenComponent } from '@components/downloads-list-screen/downloads-list-screen.component';
|
||||
import { AppStateGuard } from '@state/app-state.guard';
|
||||
import { DossiersGuard } from '@guards/dossiers.guard';
|
||||
import { DossierTemplatesGuard } from '@guards/dossier-templates.guard';
|
||||
|
||||
@ -37,7 +36,7 @@ const routes: Routes = [
|
||||
loadChildren: () => import('./modules/dossier/dossiers.module').then(m => m.DossiersModule),
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, DossierTemplatesGuard, AppStateGuard, DossiersGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard, DossierTemplatesGuard, DossiersGuard],
|
||||
requiredRoles: ['RED_USER', 'RED_MANAGER'],
|
||||
},
|
||||
},
|
||||
@ -52,7 +51,7 @@ const routes: Routes = [
|
||||
],
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@ -1,13 +1,22 @@
|
||||
import { Component, ViewContainerRef } from '@angular/core';
|
||||
import { Component, OnInit, ViewContainerRef } from '@angular/core';
|
||||
import { RouterHistoryService } from '@services/router-history.service';
|
||||
import { UserService } from '@services/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.scss'],
|
||||
})
|
||||
export class AppComponent {
|
||||
export class AppComponent implements OnInit {
|
||||
// ViewContainerRef needs to be injected for the color picker to work
|
||||
// RouterHistoryService needs to be injected for last dossiers screen to be updated on first app load
|
||||
constructor(public viewContainerRef: ViewContainerRef, private readonly _routerHistoryService: RouterHistoryService) {}
|
||||
constructor(
|
||||
public viewContainerRef: ViewContainerRef,
|
||||
private readonly _routerHistoryService: RouterHistoryService,
|
||||
private readonly _userService: UserService,
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this._userService.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
21
apps/red-ui/src/app/guards/dictionary-exists.guard.ts
Normal file
21
apps/red-ui/src/app/guards/dictionary-exists.guard.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { DICTIONARY_TYPE, DOSSIER_TEMPLATE_ID } from '@utils/constants';
|
||||
import { DictionariesMapService } from '../services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DictionaryExistsGuard implements CanActivate {
|
||||
constructor(private readonly _dictionariesMapService: DictionariesMapService, private readonly _router: Router) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot): Promise<boolean> {
|
||||
const dossierTemplateId: string = route.paramMap.get(DOSSIER_TEMPLATE_ID);
|
||||
const type: string = route.paramMap.get(DICTIONARY_TYPE);
|
||||
|
||||
if (!this._dictionariesMapService.get(dossierTemplateId, type)) {
|
||||
await this._router.navigate(['main', 'admin', 'dossier-templates', dossierTemplateId, 'dictionaries']);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
20
apps/red-ui/src/app/guards/dossier-template-exists.guard.ts
Normal file
20
apps/red-ui/src/app/guards/dossier-template-exists.guard.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { DOSSIER_TEMPLATE_ID } from '@utils/constants';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DossierTemplateExistsGuard implements CanActivate {
|
||||
constructor(private readonly _dossierTemplatesService: DossierTemplatesService, private readonly _router: Router) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot): Promise<boolean> {
|
||||
const dossierTemplateId: string = route.paramMap.get(DOSSIER_TEMPLATE_ID);
|
||||
|
||||
if (!this._dossierTemplatesService.find(dossierTemplateId)) {
|
||||
await this._router.navigate(['main', 'admin', 'dossier-templates']);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,6 @@ import { RouterModule } from '@angular/router';
|
||||
import { CompositeRouteGuard } from '@iqser/common-ui';
|
||||
import { AuthGuard } from '../auth/auth.guard';
|
||||
import { RedRoleGuard } from '../auth/red-role.guard';
|
||||
import { AppStateGuard } from '@state/app-state.guard';
|
||||
import { BaseAccountScreenComponent } from './base-account-screen/base-account-screen-component';
|
||||
|
||||
const routes = [
|
||||
@ -13,7 +12,7 @@ const routes = [
|
||||
component: BaseAccountScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
loadChildren: () => import('./screens/user-profile/user-profile.module').then(m => m.UserProfileModule),
|
||||
},
|
||||
@ -22,7 +21,7 @@ const routes = [
|
||||
component: BaseAccountScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
requiredRoles: ['RED_USER'],
|
||||
},
|
||||
loadChildren: () => import('./screens/notifications/notifications.module').then(m => m.NotificationsModule),
|
||||
|
||||
@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';
|
||||
import { AuthGuard } from '../auth/auth.guard';
|
||||
import { CompositeRouteGuard } from '@iqser/common-ui';
|
||||
import { RedRoleGuard } from '../auth/red-role.guard';
|
||||
import { AppStateGuard } from '@state/app-state.guard';
|
||||
import { DictionaryListingScreenComponent } from './screens/dictionary-listing/dictionary-listing-screen.component';
|
||||
import { DictionaryOverviewScreenComponent } from './screens/dictionary-overview/dictionary-overview-screen.component';
|
||||
import { PendingChangesGuard } from '@guards/can-deactivate.guard';
|
||||
@ -19,6 +18,9 @@ import { GeneralConfigScreenComponent } from './screens/general-config/general-c
|
||||
import { BaseAdminScreenComponent } from './base-admin-screen/base-admin-screen.component';
|
||||
import { BaseDossierTemplateScreenComponent } from './base-dossier-templates-screen/base-dossier-template-screen.component';
|
||||
import { DossierTemplatesGuard } from '../../guards/dossier-templates.guard';
|
||||
import { DICTIONARY_TYPE, DOSSIER_TEMPLATE_ID } from '@utils/constants';
|
||||
import { DossierTemplateExistsGuard } from '../../guards/dossier-template-exists.guard';
|
||||
import { DictionaryExistsGuard } from '../../guards/dictionary-exists.guard';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: '', redirectTo: 'dossier-templates', pathMatch: 'full' },
|
||||
@ -30,7 +32,7 @@ const routes: Routes = [
|
||||
component: BaseAdminScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
loadChildren: () =>
|
||||
import('./screens/dossier-templates-listing/dossier-templates-listing.module').then(
|
||||
@ -38,7 +40,7 @@ const routes: Routes = [
|
||||
),
|
||||
},
|
||||
{
|
||||
path: ':dossierTemplateId',
|
||||
path: `:${DOSSIER_TEMPLATE_ID}`,
|
||||
children: [
|
||||
{
|
||||
path: 'info',
|
||||
@ -54,16 +56,16 @@ const routes: Routes = [
|
||||
component: DictionaryListingScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':dictionary',
|
||||
path: `:${DICTIONARY_TYPE}`,
|
||||
component: DictionaryOverviewScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
canDeactivate: [PendingChangesGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard, DictionaryExistsGuard],
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -74,7 +76,7 @@ const routes: Routes = [
|
||||
canActivate: [CompositeRouteGuard],
|
||||
canDeactivate: [PendingChangesGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
loadChildren: () => import('./screens/rules/rules.module').then(m => m.RulesModule),
|
||||
},
|
||||
@ -83,7 +85,7 @@ const routes: Routes = [
|
||||
component: FileAttributesListingScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -91,7 +93,7 @@ const routes: Routes = [
|
||||
component: BaseDossierTemplateScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
loadChildren: () => import('./screens/watermark/watermark.module').then(m => m.WatermarkModule),
|
||||
},
|
||||
@ -100,7 +102,7 @@ const routes: Routes = [
|
||||
component: BaseDossierTemplateScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
loadChildren: () => import('./screens/reports/reports.module').then(m => m.ReportsModule),
|
||||
},
|
||||
@ -109,7 +111,7 @@ const routes: Routes = [
|
||||
component: DossierAttributesListingScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -117,7 +119,7 @@ const routes: Routes = [
|
||||
component: DefaultColorsScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -128,11 +130,13 @@ const routes: Routes = [
|
||||
},
|
||||
{ path: '', redirectTo: 'info', pathMatch: 'full' },
|
||||
],
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: { routeGuards: [DossierTemplateExistsGuard] },
|
||||
},
|
||||
],
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, DossierTemplatesGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard, DossierTemplatesGuard],
|
||||
requiredRoles: ['RED_MANAGER', 'RED_ADMIN'],
|
||||
},
|
||||
},
|
||||
@ -141,7 +145,7 @@ const routes: Routes = [
|
||||
component: UserListingScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
requiredRoles: ['RED_USER_ADMIN'],
|
||||
},
|
||||
},
|
||||
@ -150,7 +154,7 @@ const routes: Routes = [
|
||||
component: LicenseInformationScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
requiredRoles: ['RED_ADMIN'],
|
||||
},
|
||||
},
|
||||
@ -159,7 +163,7 @@ const routes: Routes = [
|
||||
component: DigitalSignatureScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
requiredRoles: ['RED_ADMIN'],
|
||||
},
|
||||
},
|
||||
@ -168,7 +172,7 @@ const routes: Routes = [
|
||||
component: AuditScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
requiredRoles: ['RED_ADMIN'],
|
||||
},
|
||||
},
|
||||
@ -178,7 +182,7 @@ const routes: Routes = [
|
||||
canActivate: [CompositeRouteGuard],
|
||||
canDeactivate: [PendingChangesGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
requiredRoles: ['RED_ADMIN'],
|
||||
},
|
||||
},
|
||||
@ -187,7 +191,7 @@ const routes: Routes = [
|
||||
component: TrashScreenComponent,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard],
|
||||
routeGuards: [AuthGuard, RedRoleGuard],
|
||||
requiredRoles: ['RED_MANAGER'],
|
||||
},
|
||||
},
|
||||
|
||||
@ -5,6 +5,7 @@ import { FilePreviewGuard } from '@guards/file-preview.guard';
|
||||
import { DossierFilesGuard } from '@guards/dossier-files-guard';
|
||||
import { CompositeRouteGuard } from '@iqser/common-ui';
|
||||
import { BreadcrumbTypes } from '@red/domain';
|
||||
import { DOSSIER_ID, FILE_ID } from '@utils/constants';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
@ -12,7 +13,7 @@ const routes: Routes = [
|
||||
component: SearchScreenComponent,
|
||||
},
|
||||
{
|
||||
path: ':dossierId',
|
||||
path: `:${DOSSIER_ID}`,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [DossierFilesGuard],
|
||||
@ -21,7 +22,7 @@ const routes: Routes = [
|
||||
loadChildren: () => import('./screens/dossier-overview/dossier-overview.module').then(m => m.DossierOverviewModule),
|
||||
},
|
||||
{
|
||||
path: ':dossierId/file/:fileId',
|
||||
path: `:${DOSSIER_ID}/file/:${FILE_ID}`,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [DossierFilesGuard, FilePreviewGuard],
|
||||
|
||||
@ -4,7 +4,7 @@ import jwt_decode from 'jwt-decode';
|
||||
import { ICreateUserRequest, IMyProfileUpdateRequest, IProfileUpdateRequest, IResetPasswordRequest, IUser, User } from '@red/domain';
|
||||
import { wipeCaches } from '@redaction/red-cache';
|
||||
import { BASE_HREF } from '../tokens';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { BehaviorSubject, firstValueFrom, Observable } from 'rxjs';
|
||||
import { EntitiesService, List, mapEach, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
|
||||
import { tap } from 'rxjs/operators';
|
||||
|
||||
@ -36,6 +36,12 @@ export class UserService extends EntitiesService<User, IUser> {
|
||||
return this.all.filter(user => user.isUser || user.isManager);
|
||||
}
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
if (this.currentUser.isUserAdmin || this.currentUser.isUser || this.currentUser.isAdmin) {
|
||||
await firstValueFrom(this.loadAll());
|
||||
}
|
||||
}
|
||||
|
||||
logout() {
|
||||
wipeCaches().then();
|
||||
this._keycloakService.logout(window.location.origin + this._baseHref).then();
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
import { DictionaryService } from '@shared/services/dictionary.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AppStateGuard implements CanActivate {
|
||||
constructor(
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _router: Router,
|
||||
) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot): Promise<boolean> {
|
||||
if (this._userService.currentUser.isUserAdmin) {
|
||||
await firstValueFrom(this._userService.loadAll());
|
||||
}
|
||||
|
||||
if (this._userService.currentUser.isUser || this._userService.currentUser.isAdmin) {
|
||||
await firstValueFrom(this._userService.loadAll());
|
||||
}
|
||||
|
||||
const { dossierTemplateId, type } = route.params;
|
||||
|
||||
if (dossierTemplateId && !this._dossierTemplatesService.find(dossierTemplateId as string)) {
|
||||
await this._router.navigate(['main', 'admin', 'dossier-templates']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type && !this._dictionariesMapService.get(dossierTemplateId, type)) {
|
||||
await this._router.navigate(['main', 'admin', 'dossier-templates', dossierTemplateId]);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -27,7 +27,6 @@
|
||||
"@redaction/red-cache": ["libs/red-cache/src/index.ts"],
|
||||
"@services/*": ["apps/red-ui/src/app/services/*"],
|
||||
"@shared/*": ["apps/red-ui/src/app/modules/shared/*"],
|
||||
"@state/*": ["apps/red-ui/src/app/state/*"],
|
||||
"@upload-download/*": ["apps/red-ui/src/app/modules/upload-download/*"],
|
||||
"@utils/*": ["apps/red-ui/src/app/utils/*"]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user