openaire-library/error/isRouteEnabled.guard.ts

99 lines
3.4 KiB
TypeScript
Raw Normal View History

[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 {of as observableOf, Observable, Subject, Subscription} from 'rxjs';
import {map, filter, mergeMap, tap} from 'rxjs/operators';
import { Injectable } from '@angular/core';
import {
Router,
CanActivate,
CanLoad,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Route, Data
} from '@angular/router';
import { ConfigurationService } from '../utils/configuration/configuration.service';
import { EnvironmentSpecificService} from '../utils/properties/environment-specific.service';
import {ConnectHelper} from '../connect/connectHelper';
import {properties} from "../../../environments/environment";
import {LoginErrorCodes} from "../login/utils/guardHelper.class";
import {of} from 'rxjs';
import {Page} from "../utils/entities/adminTool/page";
@Injectable()
export class IsRouteEnabled implements CanActivate {
[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 config: ConfigurationService,
private propertiesService: EnvironmentSpecificService) {}
// check(data: Data, community: string, path: string): Observable<boolean> | boolean {
// const customRedirect = data['redirect'];
//
// const redirect = customRedirect ? customRedirect : '/error';
// const obs = this.propertiesService.subscribeEnvironment().pipe(map(res => {
// let communityDomain = null;
// //if (!community) {
// communityDomain = ConnectHelper.getCommunityFromDomain(res.domain);
// //}
// if(communityDomain) {
// community = communityDomain;
// } else if (!community && data['community']) { // for openaire or connect
// community = data['community'];
// }
// return res;
// }),mergeMap(prop => {
// if (!community) {
// community = prop.adminToolsCommunity;
// }
// return this.config.isPageEnabled(prop, community, '/' + path);
// }),);
// console.log("check isRouteEnabled.guard : call isPageEnabled");
//
// obs.pipe(filter(enabled => !enabled))
// .subscribe(() => this.router.navigate([redirect], {queryParams: {'page': path}}));
// return obs;
// }
check(data: Data, community: string, path: string): Observable<boolean> | boolean {
const customRedirect = data['redirect'];
const redirect = customRedirect ? customRedirect : '/error';
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
if(communityDomain) {
community = communityDomain;
} else if (!community && data['community']) { // for openaire or connect
community = data['community'];
}
if (!community) {
community = properties.adminToolsCommunity;
}
const obs =
//this.config.isPageEnabled(properties, community, '/' + path);
this.config.isPageEnabledByState(properties, community, '/'+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
this.sub = obs
//.pipe(tap((enabled) => console.log("aaa: "+enabled)))
.pipe(filter(enabled => !enabled))
.subscribe(() => {
this.router.navigate([redirect], {queryParams: {'page': path}});
});
return obs;
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(route.data, route.queryParams['communityId'], state.url);
}
[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;
}
}