@codex-ts/core-lib 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,11 +5,10 @@ import { isPlatformBrowser, CommonModule, formatDate } from '@angular/common';
|
|
|
5
5
|
import Keycloak from 'keycloak-js';
|
|
6
6
|
import * as i1 from '@angular/common/http';
|
|
7
7
|
import { HTTP_INTERCEPTORS, HttpClientModule, HttpParams } from '@angular/common/http';
|
|
8
|
-
import { from, mergeMap, catchError, throwError,
|
|
8
|
+
import { from, mergeMap, catchError, throwError, Observable, BehaviorSubject, finalize, forkJoin, of, isObservable, Subject, take as take$1, tap as tap$1, map as map$1, takeUntil as takeUntil$1, ReplaySubject, distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs';
|
|
9
9
|
import * as i1$3 from '@angular/router';
|
|
10
10
|
import { Router } from '@angular/router';
|
|
11
|
-
import {
|
|
12
|
-
import { retry, timeout, catchError as catchError$1, take, map as map$1, finalize as finalize$1, switchMap, takeUntil, mergeMap as mergeMap$1, tap, debounceTime, distinctUntilChanged } from 'rxjs/operators';
|
|
11
|
+
import { retry, timeout, catchError as catchError$1, take, map, finalize as finalize$1, switchMap, takeUntil, mergeMap as mergeMap$1, tap, debounceTime, distinctUntilChanged } from 'rxjs/operators';
|
|
13
12
|
import * as i4 from 'primeng/api';
|
|
14
13
|
import * as i1$1 from '@angular/forms';
|
|
15
14
|
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
@@ -324,20 +323,25 @@ class KeycloakAuthGuard {
|
|
|
324
323
|
config = inject(KEYCLOAK_CONFIG);
|
|
325
324
|
router = inject(Router);
|
|
326
325
|
canActivate(route, state) {
|
|
327
|
-
return
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
326
|
+
return new Observable(subscriber => {
|
|
327
|
+
const authenticated = this.keycloakService.isAuthenticated$();
|
|
328
|
+
subscriber.next(this.processAuthentication(authenticated, route, state));
|
|
329
|
+
subscriber.complete();
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
processAuthentication(authenticated, route, state) {
|
|
333
|
+
if (!authenticated) {
|
|
334
|
+
this.keycloakService.login({ redirectUri: window.location.origin + state.url });
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
// Check for route-specific roles first, then fallback to default roles
|
|
338
|
+
const routeRoles = route.data['roles'];
|
|
339
|
+
const defaultRoles = this.config.options?.roles;
|
|
340
|
+
const requiredRoles = routeRoles || defaultRoles;
|
|
341
|
+
if (requiredRoles?.length && !this.hasRequiredRoles(requiredRoles)) {
|
|
342
|
+
return this.router.createUrlTree(['/unauthorized']);
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
341
345
|
}
|
|
342
346
|
hasRequiredRoles(roles) {
|
|
343
347
|
return roles.every(role => this.keycloakService.hasRole(role));
|
|
@@ -1102,7 +1106,7 @@ class FormService {
|
|
|
1102
1106
|
return of(void 0);
|
|
1103
1107
|
}
|
|
1104
1108
|
this.formState.loading = true;
|
|
1105
|
-
return this.entityService.getById(uuid).pipe(take(1), map
|
|
1109
|
+
return this.entityService.getById(uuid).pipe(take(1), map(data => {
|
|
1106
1110
|
this.updateFormState(data);
|
|
1107
1111
|
}), finalize$1(() => this.formState.loading = false));
|
|
1108
1112
|
}
|
|
@@ -1122,7 +1126,7 @@ class FormService {
|
|
|
1122
1126
|
}
|
|
1123
1127
|
this.formState.loading = true;
|
|
1124
1128
|
const operation$ = this.getSubmitOperation();
|
|
1125
|
-
return operation$.pipe(finalize$1(() => this.formState.loading = false), map
|
|
1129
|
+
return operation$.pipe(finalize$1(() => this.formState.loading = false), map(result => {
|
|
1126
1130
|
this.notificationService.showSuccess(`${this.entityName} ${AppMessages.FORM.SUCCESS.SAVE}`);
|
|
1127
1131
|
return result;
|
|
1128
1132
|
}));
|
|
@@ -1861,7 +1865,7 @@ class BaseFormComponent extends BasePageComponent {
|
|
|
1861
1865
|
});
|
|
1862
1866
|
}
|
|
1863
1867
|
initializeForm() {
|
|
1864
|
-
return this.route.queryParams.pipe(take(1), map
|
|
1868
|
+
return this.route.queryParams.pipe(take(1), map(params => {
|
|
1865
1869
|
this.initializeFormMode(params[AppConstants.FORM.MODE]);
|
|
1866
1870
|
this.setupFormState();
|
|
1867
1871
|
this.initializeFormSubscriptions();
|
|
@@ -1882,7 +1886,7 @@ class BaseFormComponent extends BasePageComponent {
|
|
|
1882
1886
|
throw new Error(`UUID is required for ${this.state.mode} mode`);
|
|
1883
1887
|
}
|
|
1884
1888
|
return this.getEntityOperations().getById(uuid)
|
|
1885
|
-
.pipe(tap(data => this.updateFormState(data)), map
|
|
1889
|
+
.pipe(tap(data => this.updateFormState(data)), map(() => void 0));
|
|
1886
1890
|
}));
|
|
1887
1891
|
}
|
|
1888
1892
|
getRouterState() {
|
|
@@ -2461,7 +2465,7 @@ class BaseTabbedFormComponent extends BasePageComponent {
|
|
|
2461
2465
|
activeTab: tabs[0]?.value || ''
|
|
2462
2466
|
};
|
|
2463
2467
|
// Then initialize form
|
|
2464
|
-
this.route.queryParams.pipe(take$1(1), tap$1(() => this.state = { ...this.state, loading: true }), tap$1(params => this.initializeForm(params)), map(() => void 0), catchError(error => {
|
|
2468
|
+
this.route.queryParams.pipe(take$1(1), tap$1(() => this.state = { ...this.state, loading: true }), tap$1(params => this.initializeForm(params)), map$1(() => void 0), catchError(error => {
|
|
2465
2469
|
console.error('Error initializing form:', error);
|
|
2466
2470
|
this.showError(AppMessages.FORM.ERROR.INIT);
|
|
2467
2471
|
return of(void 0);
|
|
@@ -2517,7 +2521,7 @@ class BaseTabbedFormComponent extends BasePageComponent {
|
|
|
2517
2521
|
}
|
|
2518
2522
|
}
|
|
2519
2523
|
loadFromUuid() {
|
|
2520
|
-
this.route.queryParams.pipe(take$1(1), map((params) => {
|
|
2524
|
+
this.route.queryParams.pipe(take$1(1), map$1((params) => {
|
|
2521
2525
|
const uuid = params[AppConstants.FORM.UUID];
|
|
2522
2526
|
if (!uuid) {
|
|
2523
2527
|
throw new Error(`UUID is required for ${this.state.mode} mode when no formData is provided`);
|
|
@@ -2905,7 +2909,7 @@ class BaseTaskDetailsComponent extends BasePageComponent {
|
|
|
2905
2909
|
this.formlyConfigService = formlyConfigService;
|
|
2906
2910
|
}
|
|
2907
2911
|
initializeServices() {
|
|
2908
|
-
return of(void 0).pipe(map
|
|
2912
|
+
return of(void 0).pipe(map(() => {
|
|
2909
2913
|
this.formService = new FormService(this.getEntityService(), this.formlyConfigService, this.notificationService, this.getEntityName(), this.getJsonFields(), this.getDropdownOptions());
|
|
2910
2914
|
this.state = this.formService.getState();
|
|
2911
2915
|
this.loading = this.state.loading;
|
|
@@ -2920,7 +2924,7 @@ class BaseTaskDetailsComponent extends BasePageComponent {
|
|
|
2920
2924
|
});
|
|
2921
2925
|
}
|
|
2922
2926
|
initializeFromRoute() {
|
|
2923
|
-
return this.route.queryParams.pipe(map
|
|
2927
|
+
return this.route.queryParams.pipe(map(params => {
|
|
2924
2928
|
const mode = params[AppConstants.FORM.MODE];
|
|
2925
2929
|
if (mode) {
|
|
2926
2930
|
this.formService.setMode(mode);
|