diff --git a/connect/community/community.service.ts b/connect/community/community.service.ts index 4283785c..366ed81c 100644 --- a/connect/community/community.service.ts +++ b/connect/community/community.service.ts @@ -3,7 +3,7 @@ import {HttpClient, HttpHeaders} from "@angular/common/http"; import {CommunityInfo} from './communityInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; import {map} from "rxjs/operators"; -import {BehaviorSubject, from, Subscriber} from "rxjs"; +import {BehaviorSubject, from, Observable, Subscriber} from "rxjs"; import {properties} from "../../../../environments/environment"; import {HelperFunctions} from "../../utils/HelperFunctions.class"; import {Stakeholder} from "../../monitor/entities/stakeholder"; @@ -30,30 +30,6 @@ export class CommunityService { } } - // TODO Remove these functions - getCommunityByService(properties: EnvProperties, url: string) { - this.promise = new Promise(resolve => { - this.sub = this.getCommunity(properties, url).subscribe(res => { - this.community.next(res); - resolve(); - }, - error => { - this.community.error(error); - resolve(); - }) - }); - } - - async getCommunityByStateAsync(properties: EnvProperties, url: string) { - if (!this.promise) { - this.getCommunityByService(properties, url); - } - - await this.promise; - this.clearSubscriptions(); - return this.community.getValue(); - } - public getCommunityAsObservable() { return this.community.asObservable(); } @@ -62,15 +38,6 @@ export class CommunityService { this.community.next(community); } - getCommunityByState(properties: EnvProperties, url: string) { - return from(this.getCommunityByStateAsync(properties, url)); - } - - getCommunity(properties: EnvProperties, url: string) { - return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => this.parseCommunity(res))); - } - // TODO remove NEW from function names getCommunityNew(communityId: string, refresh = false) { if(!this.community.value || this.community.value.communityId !== communityId || refresh) { @@ -124,88 +91,6 @@ export class CommunityService { /*.map(res => res.json())*/ } - async isCommunityManagerByStateAsync(properties: EnvProperties, url: string, manager: string) { - if (!this.promise) { - this.getCommunityByService(properties, url); - } - - await this.promise; - let community: CommunityInfo = this.community.getValue(); - return (community.managers.indexOf(manager) !== -1); - } - - isCommunityManagerByState(properties: EnvProperties, url: string, manager: string) { - return from(this.isCommunityManagerByStateAsync(properties, url, manager)); - } - - /** - * @deprecated - */ - isCommunityManager(properties: EnvProperties, url: string, manager: string) { - return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - //.map(res => res.json()) - .pipe(map(res => this.parseCommunity(res))) - .pipe(map(community => community.managers.indexOf(manager) !== -1)); - } - - async isTypeByStateAsync(properties: EnvProperties, url: string, type: string) { - if (!this.promise) { - this.getCommunityByService(properties, url); - } - - await this.promise; - let community: CommunityInfo = this.community.getValue(); - return (community && community.type && community.type === type); - } - - isRITypeByState(properties: EnvProperties, url: string) { - return from(this.isTypeByStateAsync(properties, url, "ri")); - } - - isCommunityTypeByState(properties: EnvProperties, url: string) { - return from(this.isTypeByStateAsync(properties, url, "community")); - } - - /** - * @deprecated - */ - isRIType(properties: EnvProperties, url: string) { - return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - //.map(res => res.json()) - .pipe(map(res => this.parseCommunity(res))) - .pipe(map(community => (community && community.type && community.type === 'ri'))); - } - - /** - * @deprecated - */ - isCommunityType(properties: EnvProperties, url: string) { - return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - //.map(res => res.json()) - .pipe(map(res => this.parseCommunity(res))) - .pipe(map(community => (community && community.type && community.type === 'community'))); - } - - /** - * @deprecated - */ - isSubscribedToCommunity(pid: string, email: string, url: string) { - return this.http.get(url + '/' + properties.adminToolsPortalType + '/' + pid + '/subscribers') - //.map(res => ((res === '') ? {} : res.json())) - .pipe(map(res => { - if (res['subscribers'] && res['subscribers'] != null) { - - for (let i = 0; i < res['subscribers'].length; i++) { - if (res['subscribers'][i] != null && res['subscribers'][i].email === email) { - return true; - } - } - } - return false; - - })); - } - private parseCommunity(data: any): CommunityInfo { const resData = Array.isArray(data) ? data[0] : data; @@ -261,4 +146,11 @@ export class CommunityService { return this.checkIsUpload(community); } + isRIType(community: string): Observable { + return this.getCommunityNew(community).pipe(map(community => community.type === 'ri')); + } + + isCommunityType(community: string): Observable { + return this.getCommunityNew(community).pipe(map(community => community.type === 'community')); + } } diff --git a/connect/communityGuard/connectAdminLoginGuard.guard.ts b/connect/communityGuard/connectAdminLoginGuard.guard.ts index 3ec2ceba..9fc8d071 100644 --- a/connect/communityGuard/connectAdminLoginGuard.guard.ts +++ b/connect/communityGuard/connectAdminLoginGuard.guard.ts @@ -18,58 +18,37 @@ import {UserManagementService} from "../../services/user-management.service"; import {properties} from "../../../../environments/environment"; @Injectable() -export class ConnectAdminLoginGuard implements CanActivate, CanLoad { - sub: Subscription = null; - +export class ConnectAdminLoginGuard implements CanActivate { + constructor(private router: Router, - private communityService: CommunityService, private propertiesService: EnvironmentSpecificService, private userManagementService: UserManagementService) { } - + check(community: string, path: string): Observable | boolean { let errorCode = LoginErrorCodes.NOT_LOGIN; - let email = null; - const authorized = this.userManagementService.getUserInfo(false).pipe(take(1),map(user => { - if (user) { - email = user.email; - if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user) || Session.isManager('community', community, user)) { - return of(true); - } else { - errorCode = LoginErrorCodes.NOT_ADMIN; - return this.communityService.isCommunityManagerByState(properties, properties['communityAPI'] + community, - email).pipe(take(1)); - } - } else { - return of(false); + const authorized = this.userManagementService.getUserInfo(false).pipe(take(1), map(user => { + if (user) { + if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user) || Session.isManager('community', community, user)) { + return of(true); } - }), mergeMap( authorized => { - return authorized; - })); - //})); - this.sub = authorized.pipe(filter(authorized => !authorized)).subscribe(() => { + } + return of(false); + }), mergeMap(authorized => { + return authorized; + })); + authorized.pipe(filter(authorized => !authorized)).subscribe(() => { this.router.navigate(['/user-info'], { queryParams: { 'errorCode': errorCode, 'redirectUrl': path } - })}); + }) + }); return authorized; } - + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { return this.check(route.queryParams['communityId'], state.url); } - - canLoad(route: Route, segments: UrlSegment[]): Observable | Promise | boolean { - const path = StringUtils.URLSegmentsToPath(segments) + document.location.search; - return this.check(ConnectHelper.getCommunityFromPath(path), path); - } - - canDeactivate() { - if(this.sub) { - this.sub.unsubscribe(); - } - return true; - } } diff --git a/connect/communityGuard/connectCommunityGuard.guard.ts b/connect/communityGuard/connectCommunityGuard.guard.ts index 6cb4a638..3d50614a 100644 --- a/connect/communityGuard/connectCommunityGuard.guard.ts +++ b/connect/communityGuard/connectCommunityGuard.guard.ts @@ -20,7 +20,7 @@ export class ConnectCommunityGuard implements CanActivate { } check(community: string): Observable | boolean { - return this.communityService.isCommunityTypeByState(properties, properties['communityAPI'] + community).pipe(take(1), tap(isCommunity => { + return this.communityService.isCommunityType(community).pipe(take(1), tap(isCommunity => { if (!isCommunity) { this.router.navigate(['errorcommunity']); } diff --git a/connect/communityGuard/connectRIGuard.guard.ts b/connect/communityGuard/connectRIGuard.guard.ts index 39ed42d1..afede15e 100644 --- a/connect/communityGuard/connectRIGuard.guard.ts +++ b/connect/communityGuard/connectRIGuard.guard.ts @@ -24,7 +24,7 @@ export class ConnectRIGuard implements CanActivate, CanLoad { } check(community: string): Observable | boolean { - return this.communityService.isRITypeByState(properties, properties['communityAPI'] + community).pipe(tap(authorized => { + return this.communityService.isRIType(community).pipe(tap(authorized => { if (!authorized) { this.router.navigate(['errorcommunity']); } diff --git a/connect/communityGuard/connectSubscriber.guard.ts b/connect/communityGuard/connectSubscriber.guard.ts index e043b341..7b5ed6a5 100644 --- a/connect/communityGuard/connectSubscriber.guard.ts +++ b/connect/communityGuard/connectSubscriber.guard.ts @@ -1,34 +1,45 @@ -import {take, tap} from 'rxjs/operators'; +import {filter, map, mergeMap, take} from 'rxjs/operators'; import {Injectable} from '@angular/core'; -import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; -import {Observable} from 'rxjs'; +import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router'; +import {Observable, of} from 'rxjs'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; -import {SubscribeService} from "../../utils/subscribe/subscribe.service"; import {properties} from "../../../../environments/environment"; import {ConnectHelper} from "../connectHelper"; +import {Session} from "../../login/utils/helper.class"; +import {UserManagementService} from "../../services/user-management.service"; @Injectable() export class ConnectSubscriberGuard implements CanActivate { + constructor(private router: Router, - private subscribeService: SubscribeService) { + private userManagementService: UserManagementService) { } - + check(community: string, path: string): Observable { let errorCode = LoginErrorCodes.NOT_SUBSCRIBER; let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain); if (communityDomain) { community = communityDomain; } - return this.subscribeService.isSubscribedToCommunity(properties, community).pipe(take(1), tap(subscribed =>{ - if(!subscribed){ - this.router.navigate(['/user-info'], { - queryParams: { - 'errorCode': errorCode, - 'redirectUrl': path - } - }); + const authorized = this.userManagementService.getUserInfo(false).pipe(take(1), map(user => { + if (user) { + if (Session.isSubscribedTo('community', community, user)) { + return of(true); + } } + return of(false); + }), mergeMap(authorized => { + return authorized; })); + authorized.pipe(filter(authorized => !authorized)).subscribe(() => { + this.router.navigate(['/user-info'], { + queryParams: { + 'errorCode': errorCode, + 'redirectUrl': path + } + }) + }); + return authorized; } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { diff --git a/deposit/searchDataprovidersToDeposit.component.ts b/deposit/searchDataprovidersToDeposit.component.ts index e8bb0d2c..1ddc74b4 100644 --- a/deposit/searchDataprovidersToDeposit.component.ts +++ b/deposit/searchDataprovidersToDeposit.component.ts @@ -86,7 +86,7 @@ export class SearchDataprovidersToDepositComponent { public oldTotalResults: number = 0; pagingLimit = 0; - properties:EnvProperties; + properties:EnvProperties = properties; // @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; @@ -106,9 +106,6 @@ export class SearchDataprovidersToDepositComponent { } public ngOnInit() { - - - this.properties = properties; this.depositLearnHowPage = this.properties.depositLearnHowPage; this.baseUrl = this.properties.depositSearchPage; this.pagingLimit = this.properties.pagingLimit; diff --git a/login/verification.guard.ts b/login/verification.guard.ts deleted file mode 100644 index abcc817b..00000000 --- a/login/verification.guard.ts +++ /dev/null @@ -1,67 +0,0 @@ -import {Injectable} from '@angular/core'; -import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; -import {Session} from './utils/helper.class'; -import {LoginErrorCodes} from './utils/guardHelper.class'; -import {catchError, filter, map, mergeMap} from "rxjs/operators"; -import {UserManagementService} from "../services/user-management.service"; -import {UserRegistryService} from "../services/user-registry.service"; -import {of} from "rxjs"; -import {properties} from "../../../environments/environment"; -import {ConnectHelper} from "../connect/connectHelper"; - -@Injectable() -export class VerificationGuard implements CanActivate { - - constructor(private router: Router, - private userRegistryService: UserRegistryService, - private userManagementService: UserManagementService) { - } - - check(path: string, id: string, type: string, entity: string): Observable | boolean { - if (Session.isLoggedIn()) { - return this.userManagementService.getUserInfo(false).pipe(map(user => { - if(user) { - if(id) { - return this.userRegistryService.getInvitation(id).pipe(map(invitation => { - if(invitation.type !== type || invitation.entity !== entity) { - this.router.navigate(['/error'], {queryParams: {'page': path}}); - return false; - } else { - return true; - } - }), catchError(error => { - if(error.status === 404) { - this.router.navigate(['/error'], {queryParams: {'page': path}}); - } else { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_AUTHORIZED, 'redirectUrl': path}}); - } - return of(false); - })); - } else { - this.router.navigate(['/error'], {queryParams: {'page': path}}); - return of(false); - } - } else { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, 'redirectUrl': path}}); - return of(false); - } - }), mergeMap(authorized => { - return authorized; - })); - } else { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN,'redirectUrl': path}}); - return false; - } - } - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { - if(properties.dashboard === "connect" && properties.environment === 'development') { - let communityId = ConnectHelper.getCommunityFromDomain(properties.domain); - communityId = (communityId)?communityId:route.queryParams['communityId']; - return this.check(state.url, route.params.id, 'community', communityId); - } else { - return false; - } - } -} diff --git a/role-verification/role-verification.component.ts b/role-verification/role-verification.component.ts index 9e3cf379..f0d46ab2 100644 --- a/role-verification/role-verification.component.ts +++ b/role-verification/role-verification.component.ts @@ -7,13 +7,14 @@ import {LoginErrorCodes} from "../login/utils/guardHelper.class"; import {Subscriber} from "rxjs"; import {FormBuilder, FormControl, Validators} from "@angular/forms"; import {AlertModal} from "../utils/modal/alert"; +import {properties} from "../../../environments/environment"; @Component({ selector: 'role-verification', template: `
- You have been invited to join {{name}} Monitor Dashboard as a manager. + You have been invited to join {{name}} {{(service === 'monitor'?'Monitor':'Research Community')}} Dashboard as a manager. Fill in the verification code, sent to your email, to accept the invitation request.
@@ -22,7 +23,7 @@ import {AlertModal} from "../utils/modal/alert";
{{error}}
-
+
@@ -34,7 +35,7 @@ import {AlertModal} from "../utils/modal/alert";
- +
You have been invited to join {{name}} Monitor Dashboard as a member. @@ -86,6 +87,8 @@ export class RoleVerificationComponent implements OnInit, OnDestroy { public type: string; @Input() public name: string; + @Input() + public service: "connect" | "monitor" = "monitor"; public user: User; public verification: any; public code: FormControl; @@ -116,8 +119,10 @@ export class RoleVerificationComponent implements OnInit, OnDestroy { if (this.user.email === this.verification.email && this.id === this.verification.entity && this.type === this.verification.type) { if (this.verification.verificationType === 'manager') { this.openManagerModal(); - } else if (this.verification.verificationType === 'member') { + } else if (this.verification.verificationType === 'member' && this.service === "monitor") { this.openMemberModal(); + } else { + this.openErrorModal(); } } else { this.openErrorModal(); @@ -177,7 +182,11 @@ export class RoleVerificationComponent implements OnInit, OnDestroy { this.managerModal.cancel(); this.error = null; this.userManagementService.updateUserInfo(() => { - this.router.navigate(['/admin/' + this.verification.entity]); + if(this.service === "monitor") { + this.router.navigate(['/admin/' + this.verification.entity]); + } else { + window.location.href = 'https://' + (properties.environment !== 'production'?'beta.':'') + 'admin.connect.openaire.eu/' + this.verification.entity; + } }); }, error => { this.loading = false; diff --git a/services/user-registry.service.ts b/services/user-registry.service.ts index 6cff6d8b..016c2ed8 100644 --- a/services/user-registry.service.ts +++ b/services/user-registry.service.ts @@ -18,8 +18,8 @@ export class UserRegistryService { CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); } - public getSubscribersCount(type: string, id: string): Observable { - return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/count'); + public getMembersCount(type: string, id: string): Observable { + return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/count'); } public subscribeTo(type: string, id: string): Observable { diff --git a/utils/loading/loading.component.ts b/utils/loading/loading.component.ts index 8f943bc2..2552415e 100644 --- a/utils/loading/loading.component.ts +++ b/utils/loading/loading.component.ts @@ -1,4 +1,4 @@ -import {Component, Input} from "@angular/core"; +import {Component, Input, OnInit} from "@angular/core"; @Component({ selector: 'loading', @@ -11,21 +11,33 @@ import {Component, Input} from "@angular/core";
-
- +
+
` }) -export class LoadingComponent { - /** - * Possible values '': blue, 'success': green, 'warning': orange and 'danger': red - */ - @Input() color: 'success' | 'warning' | 'danger' = null; +export class LoadingComponent implements OnInit{ + @Input() color: string = 'portal-color'; @Input() full: boolean = false; @Input() top_margin: boolean = true; + @Input() size: "small" | "medium" | "large" = "large"; + public style; constructor() { } + + ngOnInit() { + let size = 1; + if(this.size === 'medium') { + size = 2; + } else if(this.size === "large") { + size = 3; + } + this.style = { + width: size*20 + 'px', + height: size*20 + 'px' + }; + } } diff --git a/utils/subscribe/subscribe.service.ts b/utils/subscribe/subscribe.service.ts index cb03e066..271abf70 100644 --- a/utils/subscribe/subscribe.service.ts +++ b/utils/subscribe/subscribe.service.ts @@ -1,90 +1,24 @@ -import {Injectable} from '@angular/core'; -import {HttpClient} from '@angular/common/http'; -import {map, tap} from "rxjs/operators"; -import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; -import {EnvProperties} from "../properties/env-properties"; -import {BehaviorSubject, Observable, Subscriber} from "rxjs"; +import {BehaviorSubject, Observable} from "rxjs"; -@Injectable() export class SubscribeService { - private isSubscribedSubject: BehaviorSubject = new BehaviorSubject(false); - - constructor(private http: HttpClient) {} - sub; - ngOnDestroy() { - this.clearSubscriptions(); + + private loading: BehaviorSubject = new BehaviorSubject(false); + private members: BehaviorSubject = new BehaviorSubject(0); + + public setLoading(loading: boolean) { + this.loading.next(loading); } - clearSubscriptions(){ - if (this.sub instanceof Subscriber) { - this.sub.unsubscribe(); - } + + public setMembers(members: number) { + this.members.next(members); } - public initIsSubscribedToCommunity(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/"; - this.sub = this.http.get(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => { - this.isSubscribedSubject.next(isSubscribed); - }, error => { - this.isSubscribedSubject.error(error); - }); + + public getLoading(): Observable { + return this.loading.asObservable(); } - - public get isSubscribed(): Observable { - return this.isSubscribedSubject.asObservable(); - } - - getCommunitySubscribers(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + pid + "/subscribers"; - return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); - } - - getNumberOfCommunitySubscribers(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType +"/" + pid + "/subscribers/count"; - return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); - } - - isSubscribedToCommunity(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/"; - return this.http.get(url, CustomOptions.getAuthOptionsWithBody()) - .pipe(map(res => { - // if (res['status'] && res['status'] != 200) { - // return null; - // } - // if (res['subscribers'] && res['subscribers'] != null) { - // - // for (var i = 0; i < res['subscribers'].length; i++) { - // if (res['subscribers'][i] != null && res['subscribers'][i].email == email) { - // return true; - // } - // } - // } - // return false; - return res; - })); - } - - subscribeToCommunity(properties: EnvProperties, pid: string) { - return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType +"/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody()) - .pipe(tap(isSubscribed => { - this.isSubscribedSubject.next(isSubscribed);})); - } - - unSubscribeToCommunity(properties: EnvProperties, pid: string) { - return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType+"/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody()) - .pipe(tap(unSubscribed => { - this.isSubscribedSubject.next(!unSubscribed);})); - } - - subscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) { - let subscriber = {"email": email}; - return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType+"/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody()); - } - - unSubscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) { - return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType+"/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody()); - } - - getCommunitiesSubscribedTo(properties: EnvProperties/*, email: string*/) { - let url = properties.adminToolsAPIURL + "/subscriber/communities";//?email=" + email; - return this.http.get(url, CustomOptions.getAuthOptionsWithBody()); + + public getMembers(): Observable { + return this.members.asObservable(); } + }