openaire-library/connect/communityGuard/connectRIGuard.guard.ts

51 lines
1.6 KiB
TypeScript
Raw Normal View History

import {tap} from 'rxjs/operators';
import { Injectable } from '@angular/core';
import {
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
CanLoad,
Route, UrlSegment
} from '@angular/router';
[Trunk | Library]: 1. community.service.ts: a. Add BehaviorSubject for community. b. Method "isCommunityManager" replaced by "isCommunityManagerByState" (filtering applied in community stored in BehaviorSubject). c. Method "isRIType" replaced by "isRITypeByState" (filtering applied in community stored in BehaviorSubject). d. Method "isCommunityType" replaced by "isCommunityTypeByState" (filtering applied in community stored in BehaviorSubject). 2. connectAdminLoginGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityManagerByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 3. connectCommunityGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityTypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 4. connectRIGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isRITypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 5. isRouteEnabled.guard.ts: Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 6. curator.service.ts: [Undo change of r59073] Use "useCache" property, not "useLongCache" for curators. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59140 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-17 01:08:10 +02:00
import {Observable, Subscription} from 'rxjs';
import {CommunityService} from '../community/community.service';
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
import {ConnectHelper} from '../connectHelper';
[Trunk | Library]: 1. community.service.ts: a. Add BehaviorSubject for community. b. Method "isCommunityManager" replaced by "isCommunityManagerByState" (filtering applied in community stored in BehaviorSubject). c. Method "isRIType" replaced by "isRITypeByState" (filtering applied in community stored in BehaviorSubject). d. Method "isCommunityType" replaced by "isCommunityTypeByState" (filtering applied in community stored in BehaviorSubject). 2. connectAdminLoginGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityManagerByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 3. connectCommunityGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityTypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 4. connectRIGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isRITypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 5. isRouteEnabled.guard.ts: Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 6. curator.service.ts: [Undo change of r59073] Use "useCache" property, not "useLongCache" for curators. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59140 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-17 01:08:10 +02:00
import {properties} from "../../../../environments/environment";
@Injectable()
export class ConnectRIGuard implements CanActivate, CanLoad {
[Trunk | Library]: 1. community.service.ts: a. Add BehaviorSubject for community. b. Method "isCommunityManager" replaced by "isCommunityManagerByState" (filtering applied in community stored in BehaviorSubject). c. Method "isRIType" replaced by "isRITypeByState" (filtering applied in community stored in BehaviorSubject). d. Method "isCommunityType" replaced by "isCommunityTypeByState" (filtering applied in community stored in BehaviorSubject). 2. connectAdminLoginGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityManagerByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 3. connectCommunityGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityTypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 4. connectRIGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isRITypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 5. isRouteEnabled.guard.ts: Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 6. curator.service.ts: [Undo change of r59073] Use "useCache" property, not "useLongCache" for curators. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59140 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-17 01:08:10 +02:00
sub: Subscription = null;
constructor(private router: Router,
private communityService: CommunityService,
private propertiesService: EnvironmentSpecificService) {
}
check(community: string): Observable<boolean> | boolean {
return this.communityService.isRIType(community).pipe(tap(authorized => {
if (!authorized) {
this.router.navigate(['errorcommunity']);
}
}));
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
let community = route.params['community']?route.params['community']:route.queryParams['communityId'];
return community && this.check(community);
}
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
const path = '/' + route.path + document.location.search;
return this.check(ConnectHelper.getCommunityFromPath(path));
}
[Trunk | Library]: 1. community.service.ts: a. Add BehaviorSubject for community. b. Method "isCommunityManager" replaced by "isCommunityManagerByState" (filtering applied in community stored in BehaviorSubject). c. Method "isRIType" replaced by "isRITypeByState" (filtering applied in community stored in BehaviorSubject). d. Method "isCommunityType" replaced by "isCommunityTypeByState" (filtering applied in community stored in BehaviorSubject). 2. connectAdminLoginGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityManagerByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 3. connectCommunityGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isCommunityTypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 4. connectRIGuard.guard.ts: a. Get properties from environment (no service needed). b. Call method "isRITypeByState" of CommunityService. c. Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 5. isRouteEnabled.guard.ts: Add "canDeactivate" method to unsubscribe (TODO: call method from routing modules). 6. curator.service.ts: [Undo change of r59073] Use "useCache" property, not "useLongCache" for curators. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59140 d315682c-612b-4755-9ff5-7f18f6832af3
2020-07-17 01:08:10 +02:00
canDeactivate() {
if(this.sub) {
this.sub.unsubscribe();
}
return true;
}
}