2023-08-01 13:29:27 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
|
2019-02-27 11:39:13 +01:00
|
|
|
import {ConnectHelper} from '../connectHelper';
|
2020-12-02 16:26:35 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2021-03-22 13:00:38 +01:00
|
|
|
import {CommunityService} from "../community/community.service";
|
|
|
|
import {map} from "rxjs/operators";
|
2018-03-15 10:53:07 +01:00
|
|
|
|
|
|
|
@Injectable()
|
2023-08-01 13:29:27 +02:00
|
|
|
export class IsCommunity {
|
2018-03-15 10:53:07 +01:00
|
|
|
|
2021-03-22 13:00:38 +01:00
|
|
|
constructor(private router: Router,
|
|
|
|
private communityService: CommunityService) {
|
2019-02-26 16:25:52 +01:00
|
|
|
}
|
2018-03-15 10:53:07 +01:00
|
|
|
|
2021-04-01 14:43:49 +02:00
|
|
|
check(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
2021-03-22 13:00:38 +01:00
|
|
|
let community;
|
|
|
|
if(properties.isDashboard) {
|
|
|
|
community = route.params['community'];
|
|
|
|
} else {
|
2021-04-01 16:24:54 +02:00
|
|
|
community = ConnectHelper.getCommunityFromDomain(properties.domain);
|
2021-03-22 13:00:38 +01:00
|
|
|
}
|
|
|
|
if (community) {
|
|
|
|
return this.communityService.getCommunity(community).pipe(map(community => {
|
|
|
|
if(community) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2022-05-11 11:55:14 +02:00
|
|
|
this.router.navigate([properties.errorLink], {queryParams: {page: state.url}});
|
2021-03-22 13:00:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}));
|
2019-02-26 16:25:52 +01:00
|
|
|
} else {
|
2022-05-11 11:55:14 +02:00
|
|
|
this.router.navigate([properties.errorLink], {queryParams: {page: state.url}});
|
2019-02-26 16:25:52 +01:00
|
|
|
return false;
|
2018-03-15 10:53:07 +01:00
|
|
|
}
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
|
|
|
|
2021-07-14 13:19:57 +02:00
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
2021-04-01 14:43:49 +02:00
|
|
|
return this.check(route, state);
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
2021-03-22 13:00:38 +01:00
|
|
|
|
|
|
|
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
2021-04-01 14:43:49 +02:00
|
|
|
return this.check(childRoute, state);
|
2018-03-15 10:53:07 +01:00
|
|
|
}
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|