[Library | Trunk]: 1. Move mapType on Role class. 2. Fix isUpload on stakeholder.service.ts

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60360 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-02-04 13:36:29 +00:00
parent 35abee9027
commit fed345b244
4 changed files with 61 additions and 36 deletions

View File

@ -5,7 +5,7 @@ import {AlertModal} from "../../../utils/modal/alert";
import {UserRegistryService} from "../../../services/user-registry.service";
import {EnvProperties} from "../../../utils/properties/env-properties";
import {properties} from "../../../../../environments/environment";
import {Session, User} from "../../../login/utils/helper.class";
import {Role, Session, User} from "../../../login/utils/helper.class";
import {UserManagementService} from "../../../services/user-management.service";
import {Router} from "@angular/router";
import {StringUtils} from "../../../utils/string-utils.class";
@ -130,7 +130,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
this.createRoleModal.okButtonLeft = false;
this.createRoleModal.okButtonText = 'Create';
this.roleFb = this.fb.group({
name: this.fb.control(Session.mapType(this.type, (this.role === 'manager')) + '.' + this.id, Validators.required),
name: this.fb.control(Role.mapType(this.type, (this.role === 'manager')) + '.' + this.id, Validators.required),
description: this.fb.control('', Validators.required)
});
setTimeout(() => {

View File

@ -14,7 +14,7 @@ import {AlertModal} from "../../../utils/modal/alert";
import {UserRegistryService} from "../../../services/user-registry.service";
import {EnvProperties} from "../../../utils/properties/env-properties";
import {properties} from "../../../../../environments/environment";
import {Session, User} from "../../../login/utils/helper.class";
import {Role, Session, User} from "../../../login/utils/helper.class";
import {UserManagementService} from "../../../services/user-management.service";
import {Router} from "@angular/router";
import {SubscriberInviteComponent} from "../../../sharedComponents/subscriber-invite/subscriber-invite.component";
@ -129,7 +129,7 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges {
this.createRoleModal.okButtonLeft = false;
this.createRoleModal.okButtonText = 'create';
this.roleFb = this.fb.group({
name: this.fb.control(Session.mapType(this.type) + '.' + this.id, Validators.required),
name: this.fb.control(Role.mapType(this.type) + '.' + this.id, Validators.required),
description: this.fb.control('', Validators.required)
});
setTimeout(() => {

View File

@ -55,9 +55,7 @@ export class Session {
//Methods to check roles
public static isClaimsCurator(user: User): boolean {
return user &&
(user.role.indexOf('urn:geant:openaire.eu:group:Curator+-+Claim#aai.openaire.eu') !== -1 ||
user.role.indexOf('CURATOR_CLAIM') !== -1);
return user && user.role.indexOf(Role.CURATOR_CLAIM) !== -1;
}
public static isMonitorCurator(user: User): boolean {
@ -81,9 +79,7 @@ export class Session {
}
private static isTypeCurator(type: string, user: User): boolean {
return user &&
(user.role.indexOf('CURATOR_' + type.toUpperCase()) !== -1 ||
user.role.indexOf('urn:geant:openaire.eu:group:Curator+-+' + type + '#aai.openaire.eu') !== -1);
return user && user.role.indexOf(Role.curator(type)) !== -1;
}
public static isCurator(type: string, user: User): boolean {
@ -99,27 +95,23 @@ export class Session {
}
public static isPortalAdministrator(user: User): boolean {
return user &&
(user.role.indexOf('urn:geant:openaire.eu:group:Portal+Administrator#aai.openaire.eu') !== -1 ||
user.role.indexOf('PORTAL_ADMINISTRATOR') !== -1);
return user && user.role.indexOf(Role.PORTAL_ADMIN) !== -1;
}
public static isUserManager(user: User): boolean {
return user &&
(user.role.indexOf('urn:geant:openaire.eu:group:User+Manager#aai.openaire.eu') !== -1 ||
user.role.indexOf('USER_MANAGER') !== -1);
return user && user.role.indexOf(Role.USER_MANAGER) !== -1;
}
public static isSubscribedTo(type: string, id: string, user: User): boolean {
return user && user.role.indexOf(this.mapType(type).toUpperCase() + '_' + id.toUpperCase()) !== -1;
return user && user.role.indexOf(Role.member(type, id)) !== -1;
}
public static isMember(type: string, id: string, user: User): boolean {
return user && user.role.indexOf(this.mapType(type, false).toUpperCase() + '_' + id.toUpperCase()) !== -1;
return user && user.role.indexOf(Role.member(type, id)) !== -1;
}
public static isManager(type: string, id: string, user: User): boolean {
return user && user.role.indexOf(this.mapType(type).toUpperCase() + '_' + id.toUpperCase() + '_MANAGER') !== -1
return user && user.role.indexOf(Role.manager(type, id)) !== -1
}
public static isKindOfMonitorManager(user: User): boolean {
@ -145,18 +137,7 @@ export class Session {
}
public static isRegisteredUser(user: User): boolean {
return user &&
(user.role.indexOf('urn:geant:openaire.eu:group:Registered+User#aai.openaire.eu') !== -1 ||
user.role.indexOf('REGISTERED_USER') !== -1);
}
public static mapType(type: string, communityMap: boolean = true): string {
if (type == "ri" && communityMap) {
type = "community";
} else if (type == "organization") {
type = "institution";
}
return type;
return user && user.role.indexOf(Role.REGISTERED_USER) !== -1;
}
}
@ -202,3 +183,47 @@ export class COOKIE {
}
}
}
export class Role {
public static PORTAL_ADMIN = 'PORTAL_ADMINISTRATOR';
public static REGISTERED_USER = 'REGISTERED_USER';
public static ANONYMOUS_USER = 'ROLE_ANONYMOUS';
public static USER_MANAGER = 'USER_MANAGER';
public static CURATOR_CLAIM = 'CURATOR_CLAIM';
public static mapType(type: string, communityMap: boolean = true): string {
if (type == "ri" && communityMap) {
type = "community";
} else if (type == "organization") {
type = "institution";
}
return type;
}
/**
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
*
* */
public static curator(type: string): string {
return "CURATOR_" + this.mapType(type, true).toUpperCase();
}
/**
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
*
* Id = EE, EGI, etc
* */
public static manager(type: string, id: string) {
return this.mapType(type, true).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
}
/**
* Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT
*
* Id = EE, EGI, etc
* */
public static member(type: string, id: string) {
return this.mapType(type, false).toUpperCase() + "_" + id.toUpperCase();
}
}

View File

@ -70,8 +70,8 @@ export class StakeholderService {
}));
}
getStakeholders(url: string, type: string = null): Observable<(Stakeholder & StakeholderInfo)[]> {
return this.http.get<Stakeholder[]>(url + '/stakeholder' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => {
getStakeholders(url: string, type: string = null, defaultId: string = null): Observable<(Stakeholder & StakeholderInfo)[]> {
return this.http.get<Stakeholder[]>(url + '/stakeholder' + ((type) ? ('?type=' + type) : '') + ((!type && defaultId)? ('?defaultId=' + defaultId):''), CustomOptions.registryOptions()).pipe(map(stakeholders => {
return this.formalize(this.checkIsUpload(stakeholders));
}));
}
@ -105,7 +105,7 @@ export class StakeholderService {
if(path.length === 0) {
return this.formalize(this.checkIsUpload(element));
} else {
this.formalize(element);
return this.formalize(element);
}
}));
}
@ -145,10 +145,10 @@ export class StakeholderService {
private checkIsUpload(response: Stakeholder | Stakeholder[]): any | any[] {
if(Array.isArray(response)) {
response.forEach(value => {
value.isUpload = !StringUtils.isValidUrl(value.logoUrl);
value.isUpload = value.logoUrl && !StringUtils.isValidUrl(value.logoUrl);
});
} else {
response.isUpload = !StringUtils.isValidUrl(response.logoUrl);
response.isUpload = response.logoUrl && !StringUtils.isValidUrl(response.logoUrl);
}
return response;
}