2019-02-27 11:39:13 +01:00
|
|
|
import {HttpParams} from '@angular/common/http';
|
2020-09-24 13:18:24 +02:00
|
|
|
import {properties} from "../../../environments/environment";
|
2021-05-17 17:32:06 +02:00
|
|
|
import {Session} from "../login/utils/helper.class";
|
2023-10-10 21:40:01 +02:00
|
|
|
import {CommunityInfo} from "./community/communityInfo";
|
2018-03-29 10:23:36 +02:00
|
|
|
|
2019-02-27 11:39:13 +01:00
|
|
|
export class ConnectHelper {
|
|
|
|
|
|
|
|
public static getCommunityFromDomain(domain: string): string{
|
2024-01-09 10:33:46 +01:00
|
|
|
if(properties.dashboard === 'irish') {
|
2023-11-13 14:00:05 +01:00
|
|
|
return properties.adminToolsCommunity;
|
|
|
|
}
|
2022-10-03 19:25:37 +02:00
|
|
|
if(properties.environment == "development" &&
|
|
|
|
(properties.adminToolsPortalType == "connect" || properties.adminToolsPortalType == "community"
|
|
|
|
|| properties.adminToolsPortalType == "aggregator" || properties.adminToolsPortalType == "eosc")) {
|
2024-07-17 12:25:44 +02:00
|
|
|
// domain = "covid-19.openaire.eu"; //for testing
|
2021-04-19 18:28:36 +02:00
|
|
|
}
|
2020-08-11 14:39:55 +02:00
|
|
|
domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
|
2024-09-11 20:04:03 +02:00
|
|
|
if (domain.indexOf('eosc-portal.eu') != -1 || domain.indexOf('eosc-beyond.eu') != -1) {
|
2022-02-18 15:57:25 +01:00
|
|
|
return "eosc";
|
|
|
|
}
|
2019-02-27 11:39:13 +01:00
|
|
|
if (domain.indexOf('openaire.eu') === -1) {
|
2018-03-29 10:23:36 +02:00
|
|
|
return null;
|
|
|
|
}
|
2019-02-27 11:39:13 +01:00
|
|
|
if ( domain.indexOf('beta') !== -1) {
|
|
|
|
domain = domain.substr(domain.indexOf('.') + 1, domain.length);
|
|
|
|
domain = domain.substr(0, domain.indexOf('.'));
|
2022-07-21 15:07:51 +02:00
|
|
|
} else if (domain.indexOf('test.') !== -1 && !(properties.adminToolsPortalType == "connect" || properties.adminToolsPortalType == "community")) {
|
2018-10-17 14:10:30 +02:00
|
|
|
return null;
|
2019-02-27 11:39:13 +01:00
|
|
|
} else {
|
2020-07-15 10:19:35 +02:00
|
|
|
domain = domain.substr(0, domain.indexOf('.'));
|
2018-03-29 10:23:36 +02:00
|
|
|
}
|
2019-07-05 14:11:04 +02:00
|
|
|
if (domain === 'connect' || domain === 'explore' || domain === 'monitor' || domain === 'admin'){
|
2018-03-29 10:23:36 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return domain;
|
|
|
|
}
|
2019-02-27 11:39:13 +01:00
|
|
|
|
|
|
|
public static getCommunityFromPath(path: string): string {
|
|
|
|
if (path.includes('?')) {
|
|
|
|
const httpParams = new HttpParams({ fromString: path.split('?')[1] });
|
|
|
|
return httpParams.get('communityId');
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 13:18:24 +02:00
|
|
|
|
|
|
|
public static setPortalTypeFromPid(pid: string): void {
|
|
|
|
if(pid == "openaire") {
|
|
|
|
properties.adminToolsPortalType = "explore";
|
|
|
|
} else if(pid == "connect") {
|
|
|
|
properties.adminToolsPortalType = "connect";
|
2021-03-01 18:27:45 +01:00
|
|
|
} else if(pid == "monitor") {
|
|
|
|
properties.adminToolsPortalType = "monitor";
|
2020-09-24 13:18:24 +02:00
|
|
|
} else {
|
|
|
|
properties.adminToolsPortalType = "community";
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 17:32:06 +02:00
|
|
|
|
|
|
|
|
2023-10-10 21:40:01 +02:00
|
|
|
public static isPrivate(community: CommunityInfo, user) {
|
|
|
|
return community && (community.isPrivate() || (community.isRestricted() && !(
|
|
|
|
Session.isPortalAdministrator(user) ||
|
|
|
|
Session.isCommunityCurator(user) ||
|
|
|
|
Session.isManager("community", community.communityId, user) ||
|
|
|
|
(!community.isOpen() && Session.isMember('community', community.communityId, user))
|
|
|
|
)))
|
2021-05-17 17:32:06 +02:00
|
|
|
}
|
2018-03-29 10:23:36 +02:00
|
|
|
}
|