RED-3800 - add get tenant function token.
This commit is contained in:
parent
fa574115aa
commit
986d552e49
@ -17,7 +17,6 @@ import { IqserPermissionsService } from './permissions.service';
|
||||
import { IqserRolesService } from './roles.service';
|
||||
import { isArray, isFunction, isRedirectWithParameters, isString, transformPermission } from '../utils';
|
||||
import { List } from '../../utils';
|
||||
import { TenantsService } from '../../tenants';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
|
||||
export interface IqserPermissionsData {
|
||||
@ -31,7 +30,6 @@ export interface IqserPermissionsData {
|
||||
export class IqserPermissionsGuard implements CanActivate, CanMatch, CanActivateChild {
|
||||
constructor(
|
||||
private readonly _permissionsService: IqserPermissionsService,
|
||||
private readonly _tenantsService: TenantsService,
|
||||
private readonly _rolesService: IqserRolesService,
|
||||
private readonly _router: Router,
|
||||
private readonly _logger: NGXLogger,
|
||||
@ -93,7 +91,7 @@ export class IqserPermissionsGuard implements CanActivate, CanMatch, CanActivate
|
||||
' with extras ',
|
||||
navigationExtras,
|
||||
);
|
||||
return this._router.navigate([this._tenantsService.activeTenantId, ...navigationCommands], navigationExtras);
|
||||
return this._router.navigate([...navigationCommands], navigationExtras);
|
||||
}
|
||||
|
||||
if (Array.isArray(_redirectTo)) {
|
||||
@ -105,7 +103,7 @@ export class IqserPermissionsGuard implements CanActivate, CanMatch, CanActivate
|
||||
'. Redirecting to ',
|
||||
_redirectTo,
|
||||
);
|
||||
return this._router.navigate([this._tenantsService.activeTenantId, ..._redirectTo]);
|
||||
return this._router.navigate([..._redirectTo]);
|
||||
}
|
||||
|
||||
this._logger.warn(
|
||||
@ -116,7 +114,7 @@ export class IqserPermissionsGuard implements CanActivate, CanMatch, CanActivate
|
||||
'. Redirecting to ',
|
||||
_redirectTo,
|
||||
);
|
||||
return this._router.navigate([`${this._tenantsService.activeTenantId}${_redirectTo}`]);
|
||||
return this._router.navigate([_redirectTo]);
|
||||
}
|
||||
|
||||
#checkRedirect(permissions: IqserPermissionsData, route: ActivatedRouteSnapshot | Route, state?: RouterStateSnapshot) {
|
||||
|
||||
@ -2,19 +2,18 @@ import { inject, Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { LoadingService } from '../../loading';
|
||||
import { IqserUserService } from '../services/iqser-user.service';
|
||||
import { TenantsService } from '../../tenants';
|
||||
|
||||
@Injectable()
|
||||
export class IqserRoleGuard implements CanActivate {
|
||||
protected readonly _router = inject(Router);
|
||||
protected readonly _tenantsService = inject(TenantsService);
|
||||
protected readonly _loadingService = inject(LoadingService);
|
||||
protected readonly _userService = inject(IqserUserService);
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async canActivate(route: ActivatedRouteSnapshot, _: RouterStateSnapshot) {
|
||||
const currentUser = this._userService.currentUser;
|
||||
if (!currentUser || !currentUser.hasAnyRole) {
|
||||
await this._router.navigate([`/${this._tenantsService.activeTenantId}/auth-error`]);
|
||||
await this._router.navigate(['/auth-error']);
|
||||
this._loadingService.stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -14,3 +14,16 @@ export const UI_ROOT_PATH_FN = new InjectionToken<(path: string) => string>('App
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export const GET_TENANT_FROM_PATH_FN = new InjectionToken<() => string>('Parse tenant from path considering UI root', {
|
||||
factory: () => {
|
||||
const root = inject(UI_ROOT);
|
||||
|
||||
return () => {
|
||||
const pathSegments = location.pathname.split('/').filter(Boolean);
|
||||
const rootPathIndex = pathSegments.indexOf(root.replace('/', ''));
|
||||
const tenant = pathSegments[rootPathIndex + 1];
|
||||
return tenant ?? '';
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user