2020-11-11 15:43:13 +01:00
|
|
|
import {tap} from 'rxjs/operators';
|
2021-03-02 16:52:09 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-02-26 14:57:04 +01:00
|
|
|
import {
|
|
|
|
ActivatedRouteSnapshot,
|
2021-03-02 16:52:09 +01:00
|
|
|
CanActivate,
|
|
|
|
CanActivateChild,
|
|
|
|
Router,
|
2019-02-26 14:57:04 +01:00
|
|
|
RouterStateSnapshot,
|
2021-03-02 16:52:09 +01:00
|
|
|
UrlTree
|
2019-02-26 14:57:04 +01:00
|
|
|
} from '@angular/router';
|
2020-07-17 01:08:10 +02:00
|
|
|
import {Observable, Subscription} from 'rxjs';
|
2018-03-27 10:22:55 +02:00
|
|
|
import {CommunityService} from '../community/community.service';
|
2022-06-23 18:46:53 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2018-03-27 10:22:55 +02:00
|
|
|
|
|
|
|
@Injectable()
|
2021-03-02 16:52:09 +01:00
|
|
|
export class ConnectRIGuard implements CanActivate, CanActivateChild {
|
2020-07-17 01:08:10 +02:00
|
|
|
sub: Subscription = null;
|
2021-03-02 16:52:09 +01:00
|
|
|
|
2019-02-26 16:25:52 +01:00
|
|
|
constructor(private router: Router,
|
2021-03-02 16:52:09 +01:00
|
|
|
private communityService: CommunityService) {
|
2019-02-26 16:25:52 +01:00
|
|
|
}
|
2021-03-02 16:52:09 +01:00
|
|
|
|
|
|
|
check(community: string, url: string): Observable<boolean> | boolean {
|
2021-02-19 18:50:34 +01:00
|
|
|
return this.communityService.isRIType(community).pipe(tap(authorized => {
|
2020-11-11 15:43:13 +01:00
|
|
|
if (!authorized) {
|
2022-06-23 18:46:53 +02:00
|
|
|
this.router.navigate([properties.errorLink], {queryParams: {'page': url}});
|
2020-11-11 15:43:13 +01:00
|
|
|
}
|
|
|
|
}));
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
2021-01-26 17:21:55 +01:00
|
|
|
|
2021-07-14 13:19:57 +02:00
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
2021-03-01 19:44:26 +01:00
|
|
|
let community = route.params['community'];
|
2021-03-02 16:52:09 +01:00
|
|
|
return community && this.check(community, state.url);
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
2021-03-01 19:44:26 +01:00
|
|
|
|
|
|
|
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
|
|
|
let community = childRoute.params['community'];
|
2021-03-02 16:52:09 +01:00
|
|
|
return community && this.check(community, state.url);
|
2020-07-17 01:08:10 +02:00
|
|
|
}
|
2018-03-27 10:22:55 +02:00
|
|
|
}
|