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";
|
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{
|
2021-04-19 18:28:36 +02:00
|
|
|
if(properties.environment == "development") {
|
2021-11-23 12:50:44 +01:00
|
|
|
domain = "aginfra.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
|
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('.'));
|
|
|
|
} else if (domain.indexOf('test.') !== -1) {
|
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
|
|
|
|
|
|
|
|
|
|
|
public static isPrivate(community, user) {
|
2021-11-23 12:50:44 +01:00
|
|
|
return community && (community.status == "hidden" || (community.status == "manager" && !(Session.isPortalAdministrator(user) || Session.isCommunityCurator(user) || Session.isManager("community", community.communityId, user))))
|
2021-05-17 17:32:06 +02:00
|
|
|
}
|
2018-03-29 10:23:36 +02:00
|
|
|
}
|