Project

General

Profile

1
import {HttpParams} from '@angular/common/http';
2
import {properties} from "../../../environments/environment";
3
import {Session} from "../login/utils/helper.class";
4

    
5
export class ConnectHelper {
6

    
7
  public static  getCommunityFromDomain(domain: string): string{
8
    if(properties.environment == "development") {
9
      domain = "beta.connect.openaire.eu"; //for testing
10
    }
11
    domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
12
    if (domain.indexOf('openaire.eu') === -1) {
13
      return null;
14
    }
15
    if ( domain.indexOf('beta') !== -1) {
16
      domain = domain.substr(domain.indexOf('.') + 1, domain.length);
17
      domain = domain.substr(0, domain.indexOf('.'));
18
    } else if (domain.indexOf('test.') !== -1) {
19
      return null;
20
    } else {
21
      domain = domain.substr(0, domain.indexOf('.'));
22
    }
23
    if (domain === 'connect' || domain === 'explore' || domain === 'monitor' || domain === 'admin'){
24
      return null;
25
    }
26
    return domain;
27
  }
28

    
29
  public static getCommunityFromPath(path: string): string {
30
    if (path.includes('?')) {
31
      const httpParams = new HttpParams({ fromString: path.split('?')[1] });
32
      return httpParams.get('communityId');
33
    } else {
34
      return null;
35
    }
36
  }
37

    
38
  public static setPortalTypeFromPid(pid: string): void {
39
    if(pid == "openaire") {
40
      properties.adminToolsPortalType = "explore";
41
    } else if(pid == "connect") {
42
      properties.adminToolsPortalType = "connect";
43
    } else if(pid == "monitor") {
44
      properties.adminToolsPortalType = "monitor";
45
    } else {
46
      properties.adminToolsPortalType = "community";
47
    }
48
  }
49

    
50

    
51
  public static isPrivate(community, user) {
52
    return community && (community.status == "hidden" || (community.status == "manager" && !(Session.isCommunityCurator(user) || Session.isManager("community", community.communityId, user))))
53
  }
54
}
    (1-1/1)