From 889bd1db172956dbc634845ee88b46c7b4378992 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 3 Nov 2020 18:25:03 +0000 Subject: [PATCH] [Library | Trunk]: Merge members managers. Add create group for portal admins git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59757 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../users/dashboard-users.component.html | 17 +- dashboard/users/dashboard-users.component.ts | 16 +- dashboard/users/dashboard-users.module.ts | 5 +- .../users/managers/managers.component.html | 81 ------- .../users/managers/managers.component.ts | 129 ----------- dashboard/users/managers/managers.module.ts | 24 -- .../users/members/members.component.html | 81 ------- dashboard/users/members/members.component.ts | 129 ----------- .../role-users/role-users.component.html | 100 +++++++++ .../users/role-users/role-users.component.ts | 191 ++++++++++++++++ .../role-users.module.ts} | 10 +- login/utils/helper.class.ts | 207 ++++++++++-------- monitor/services/stakeholder.service.ts | 2 +- .../role-verification.component.ts | 2 +- services/user-registry.service.ts | 91 +++----- verification/verification.component.ts | 2 +- 16 files changed, 463 insertions(+), 624 deletions(-) delete mode 100644 dashboard/users/managers/managers.component.html delete mode 100644 dashboard/users/managers/managers.component.ts delete mode 100644 dashboard/users/managers/managers.module.ts delete mode 100644 dashboard/users/members/members.component.html delete mode 100644 dashboard/users/members/members.component.ts create mode 100644 dashboard/users/role-users/role-users.component.html create mode 100644 dashboard/users/role-users/role-users.component.ts rename dashboard/users/{members/members.module.ts => role-users/role-users.module.ts} (86%) diff --git a/dashboard/users/dashboard-users.component.html b/dashboard/users/dashboard-users.component.html index 74b30195..57617a32 100644 --- a/dashboard/users/dashboard-users.component.html +++ b/dashboard/users/dashboard-users.component.html @@ -1,16 +1,9 @@ -
- - - -
-
- - - -
+ + + diff --git a/dashboard/users/dashboard-users.component.ts b/dashboard/users/dashboard-users.component.ts index 02e090d0..e4edc7fa 100644 --- a/dashboard/users/dashboard-users.component.ts +++ b/dashboard/users/dashboard-users.component.ts @@ -1,4 +1,6 @@ import {Component, Input, OnInit} from "@angular/core"; +import {UserManagementService} from "../../services/user-management.service"; +import {Session, User} from "../../login/utils/helper.class"; @Component({ selector: 'dashboard-users', @@ -14,15 +16,23 @@ export class DashboardUsersComponent implements OnInit{ public name: string; @Input() public link: string; - public tab: "managers" | "members" = 'managers'; + public user: User; + public tab: "manager" | "member" = 'manager'; - constructor() { + constructor(private userManagementService: UserManagementService) { } ngOnInit() { + this.userManagementService.getUserInfo().subscribe(user => { + this.user = user; + }); } - changeTab(tab: "managers" | "members") { + changeTab(tab: "manager" | "member") { this.tab = tab; } + + public get isPortalAdmin() { + return Session.isPortalAdministrator(this.user); + } } diff --git a/dashboard/users/dashboard-users.module.ts b/dashboard/users/dashboard-users.module.ts index e44735c9..45758f20 100644 --- a/dashboard/users/dashboard-users.module.ts +++ b/dashboard/users/dashboard-users.module.ts @@ -1,11 +1,10 @@ import {NgModule} from "@angular/core"; import {DashboardUsersComponent} from "./dashboard-users.component"; import {CommonModule} from "@angular/common"; -import {ManagersModule} from "./managers/managers.module"; -import {MembersModule} from "./members/members.module"; +import {RoleUsersModule} from "./role-users/role-users.module"; @NgModule({ - imports: [CommonModule, ManagersModule, MembersModule], + imports: [CommonModule, RoleUsersModule], declarations: [DashboardUsersComponent], exports: [DashboardUsersComponent] }) diff --git a/dashboard/users/managers/managers.component.html b/dashboard/users/managers/managers.component.html deleted file mode 100644 index c6b3ce5c..00000000 --- a/dashboard/users/managers/managers.component.html +++ /dev/null @@ -1,81 +0,0 @@ -
-
-
- -
- {{error}} -
-
- - -
-
-
- -
-
-
-
No managers for {{name}}
-
No pending manager invitations for {{name}}
-
-
-
-
-
-
- Email: - {{(showManagers) ? item.email : item}} -
-
- -
-
-
-
-
-
- -
-
-
-
- -
- Are you sure you want to remove {{selectedUser}} from managers? -
-
- -
- Are you sure you want to cancel manager invitation of {{selectedUser}}? -
-
diff --git a/dashboard/users/managers/managers.component.ts b/dashboard/users/managers/managers.component.ts deleted file mode 100644 index 8bed04e5..00000000 --- a/dashboard/users/managers/managers.component.ts +++ /dev/null @@ -1,129 +0,0 @@ -import {Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {Subscription} from 'rxjs/Rx'; -import {FormBuilder, FormControl, Validators} from '@angular/forms'; -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"; - -@Component({ - selector: 'managers', - templateUrl: 'managers.component.html' -}) -export class ManagersComponent implements OnInit, OnDestroy { - - @Input() - public id: string; - @Input() - public type: string; - @Input() - public name: string; - @Input() - public link: string; - public managers: any[]; - public pending: any[]; - public showManagers: boolean = true; - public subs: any[] = []; - public loadManagers: boolean = true; - public loadPending: boolean = true; - public error: string; - public selectedUser: string = null; - public invited: FormControl; - public properties: EnvProperties = properties; - @ViewChild('inviteManagerModal') inviteManagerModal: AlertModal; - @ViewChild('deleteManagerModal') deleteManagerModal: AlertModal; - @ViewChild('deletePendingModal') deletePendingModal: AlertModal; - - constructor(private userRegistryService: UserRegistryService, - private fb: FormBuilder) { - } - - ngOnInit() { - this.subs.push(this.userRegistryService.getManagersEmail(this.type, this.id).subscribe(managers => { - this.managers = managers; - this.loadManagers = false; - }, error => { - this.managers = []; - this.error = error.error.response; - this.loadManagers = false; - })); - this.subs.push(this.userRegistryService.getPendingManagers(this.type, this.id).subscribe(pending => { - this.pending = pending; - this.loadPending = false; - }, error => { - this.managers = []; - this.error = error.error.response; - this.loadManagers = false; - })); - } - - ngOnDestroy() { - this.subs.forEach(sub => { - if (sub instanceof Subscription) { - sub.unsubscribe(); - } - }); - } - - openDeleteModal(item: any) { - if (this.showManagers) { - this.selectedUser = item.email; - this.deleteManagerModal.alertTitle = 'Delete manager'; - this.deleteManagerModal.open(); - } else { - this.selectedUser = item; - this.deletePendingModal.alertTitle = 'Cancel invitation'; - this.deletePendingModal.open(); - } - } - - openInviteModal() { - this.inviteManagerModal.alertTitle = 'Invite manager'; - this.inviteManagerModal.okButtonLeft = false; - this.inviteManagerModal.okButtonText = 'Send'; - this.invited = this.fb.control('', [Validators.required, Validators.email]); - this.inviteManagerModal.open(); - } - - deleteManager() { - this.loadManagers = true; - this.userRegistryService.removeManager(this.type, this.id, this.selectedUser).subscribe(() => { - this.managers = this.managers.filter(manager => manager.email != this.selectedUser); - this.loadManagers = false; - this.error = null; - }, error => { - this.error = error.error.response; - this.loadManagers = false; - }); - } - - deletePendingManager() { - this.loadPending = true; - this.userRegistryService.cancelManagerInvitation(this.type, this.id, this.selectedUser).subscribe(() => { - this.pending = this.pending.filter(manager => manager != this.selectedUser); - this.error = null; - this.loadPending = false; - }, error => { - this.error = error.error.response; - this.loadPending = false; - }); - } - - inviteManager() { - this.loadManagers = true; - let details = { - name: this.name, - link: this.link - } - this.userRegistryService.inviteManager(this.type, this.id, this.invited.value, details).subscribe(() => { - this.error = null; - if (!this.pending.includes(this.invited.value)) { - this.pending.push(this.invited.value); - } - this.loadManagers = false; - }, error => { - this.error = error.error.response; - this.loadManagers = false; - }) - } -} diff --git a/dashboard/users/managers/managers.module.ts b/dashboard/users/managers/managers.module.ts deleted file mode 100644 index ae238139..00000000 --- a/dashboard/users/managers/managers.module.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {NgModule} from '@angular/core'; -import {CommonModule} from '@angular/common'; -import {ManagersComponent} from './managers.component'; -import {ReactiveFormsModule} from '@angular/forms'; -import {EmailService} from "../../../utils/email/email.service"; -import {AlertModalModule} from "../../../utils/modal/alertModal.module"; -import {LoadingModule} from "../../../utils/loading/loading.module"; -import {IconsService} from "../../../utils/icons/icons.service"; -import {person_add, remove_circle_outline} from "../../../utils/icons/icons"; -import {IconsModule} from "../../../utils/icons/icons.module"; -import {InputModule} from "../../sharedComponents/input/input.module"; -import {PageContentModule} from "../../sharedComponents/page-content/page-content.module"; - -@NgModule({ - imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule], - declarations: [ManagersComponent], - exports: [ManagersComponent], - providers: [EmailService] -}) -export class ManagersModule { - constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([remove_circle_outline, person_add]); - } -} diff --git a/dashboard/users/members/members.component.html b/dashboard/users/members/members.component.html deleted file mode 100644 index 4b9756cf..00000000 --- a/dashboard/users/members/members.component.html +++ /dev/null @@ -1,81 +0,0 @@ -
-
-
- -
- {{error}} -
-
- - -
-
-
- -
-
-
-
No members for {{name}}
-
No pending member invitations for {{name}}
-
-
-
-
-
-
- Email: - {{(showMembers) ? item.email : item}} -
-
- -
-
-
-
-
-
- -
-
-
-
- -
- Are you sure you want to remove {{selectedUser}} from members? -
-
- -
- Are you sure you want to cancel member invitation of {{selectedUser}}? -
-
diff --git a/dashboard/users/members/members.component.ts b/dashboard/users/members/members.component.ts deleted file mode 100644 index 7d295a7a..00000000 --- a/dashboard/users/members/members.component.ts +++ /dev/null @@ -1,129 +0,0 @@ -import {Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {Subscription} from 'rxjs/Rx'; -import {UserRegistryService} from "../../../services/user-registry.service"; -import {EnvProperties} from "../../../utils/properties/env-properties"; -import {properties} from "../../../../../environments/environment"; -import {FormBuilder, FormControl, Validators} from "@angular/forms"; -import {AlertModal} from "../../../utils/modal/alert"; - -@Component({ - selector: 'members', - templateUrl: 'members.component.html' -}) -export class MembersComponent implements OnInit, OnDestroy { - - @Input() - public id: string; - @Input() - public type: string; - @Input() - public name: string; - @Input() - public link: string; - public members: any[]; - public pending: any[]; - public showMembers: boolean = true; - public subs: any[] = []; - public loadMembers: boolean = true; - public loadPending: boolean = true; - public error: string; - public selectedUser: string = null; - public invited: FormControl; - public properties: EnvProperties = properties; - @ViewChild('inviteMemberModal') inviteMemberModal: AlertModal; - @ViewChild('deleteMemberModal') deleteMemberModal: AlertModal; - @ViewChild('deletePendingModal') deletePendingModal: AlertModal; - - constructor(private userRegistryService: UserRegistryService, - private fb: FormBuilder) { - } - - ngOnInit() { - this.subs.push(this.userRegistryService.getMembersEmail(this.type, this.id).subscribe(members => { - this.members = members; - this.loadMembers = false; - }, error => { - this.members = []; - this.error = error.error.response; - this.loadMembers = false; - })); - this.subs.push(this.userRegistryService.getPendingMembers(this.type, this.id).subscribe(pending => { - this.pending = pending; - this.loadPending = false; - }, error => { - this.members = []; - this.error = error.error.response; - this.loadMembers = false; - })); - } - - ngOnDestroy() { - this.subs.forEach(sub => { - if (sub instanceof Subscription) { - sub.unsubscribe(); - } - }); - } - - openDeleteModal(item: any) { - if (this.showMembers) { - this.selectedUser = item.email; - this.deleteMemberModal.alertTitle = 'Delete member'; - this.deleteMemberModal.open(); - } else { - this.selectedUser = item; - this.deletePendingModal.alertTitle = 'Cancel invitation'; - this.deletePendingModal.open(); - } - } - - openInviteModal() { - this.inviteMemberModal.alertTitle = 'Invite member'; - this.inviteMemberModal.okButtonText = 'Send'; - this.inviteMemberModal.okButtonLeft = false; - this.invited = this.fb.control('', [Validators.required, Validators.email]); - this.inviteMemberModal.open(); - } - - deleteMember() { - this.loadMembers = true; - this.userRegistryService.removeMember(this.type, this.id, this.selectedUser).subscribe(() => { - this.members = this.members.filter(manager => manager.email != this.selectedUser); - this.loadMembers = false; - this.error = null; - }, error => { - this.error = error.error.response; - this.loadMembers = false; - }); - } - - deletePendingMember() { - this.loadPending = true; - this.userRegistryService.cancelMemberInvitation(this.type, this.id, this.selectedUser).subscribe(() => { - this.pending = this.pending.filter(manager => manager != this.selectedUser); - this.error = null; - this.loadPending = false; - }, error => { - this.error = error.error.response; - this.loadPending = false; - }); - } - - inviteMember() { - this.loadMembers = true; - let details = { - name: this.name, - link: this.link - } - this.userRegistryService.inviteMember(this.type, this.id, this.invited.value, details).subscribe(() => { - this.error = null; - if (!this.pending.includes(this.invited.value)) { - this.pending.push(this.invited.value); - } - this.loadMembers = false; - }, error => { - this.error = error.error.response; - this.loadMembers = false; - }) - } -} diff --git a/dashboard/users/role-users/role-users.component.html b/dashboard/users/role-users/role-users.component.html new file mode 100644 index 00000000..3dd10d41 --- /dev/null +++ b/dashboard/users/role-users/role-users.component.html @@ -0,0 +1,100 @@ +
+
+
+ +
+ {{error}} +
+
+ + +
+
+
+ +
+
+
+
No {{role}}s for {{name}}
+
No pending {{role}} invitations for {{name}}
+
+
+
+
+
+
+ Email: + {{(showActive) ? item.email : item}} +
+
+ +
+
+
+
+
+
+ +
+
+
+
+ +
+ Are you sure you want to remove {{selectedUser}} from {{role}}s? +
+
+ +
+ Are you sure you want to cancel {{role}} invitation of {{selectedUser}}? +
+
+ +
+
+
+
+
+
+
diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts new file mode 100644 index 00000000..f6a35d97 --- /dev/null +++ b/dashboard/users/role-users/role-users.component.ts @@ -0,0 +1,191 @@ +import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild} from '@angular/core'; +import {Subscription} from 'rxjs/Rx'; +import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms'; +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} from "../../../login/utils/helper.class"; + +declare var UIkit; + +@Component({ + selector: 'role-users', + templateUrl: 'role-users.component.html' +}) +export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { + + @Input() + public id: string; + @Input() + public type: string; + @Input() + public name: string; + @Input() + public link: string; + @Input() + public isPortalAdmin: boolean = false; + @Input() role: "member" | "manager" = "manager"; + public active: any[]; + public pending: any[]; + public showActive: boolean = true; + public subs: any[] = []; + public loadActive: boolean = true; + public loadPending: boolean = true; + public error: string; + public selectedUser: string = null; + public invited: FormControl; + public properties: EnvProperties = properties; + public exists: boolean = true; + public roleFb: FormGroup; + @ViewChild('inviteModal') inviteModal: AlertModal; + @ViewChild('deleteModal') deleteModal: AlertModal; + @ViewChild('deletePendingModal') deletePendingModal: AlertModal; + @ViewChild('createRoleModal') createRoleModal: AlertModal; + + constructor(private userRegistryService: UserRegistryService, + private fb: FormBuilder) { + } + + ngOnInit() { + this.updateLists(); + } + + ngOnChanges(changes: SimpleChanges) { + if(changes.role) { + this.updateLists(); + } + } + + ngOnDestroy() { + this.subs.forEach(sub => { + if (sub instanceof Subscription) { + sub.unsubscribe(); + } + }); + } + + updateLists() { + this.loadActive = true; + this.loadPending = true; + this.subs.push(this.userRegistryService.getActiveEmail(this.type, this.id, this.role).subscribe(users => { + this.active = users; + this.loadActive = false; + this.exists = true; + }, error => { + this.active = []; + if(error.status === 404) { + this.exists = false; + } else { + this.error = error.error.response; + } + this.loadActive = false; + })); + this.subs.push(this.userRegistryService.getPending(this.type, this.id, this.role).subscribe(users => { + this.pending = users; + this.loadPending = false; + }, error => { + this.active = []; + this.error = error.error.response; + this.loadActive = false; + })); + } + + openDeleteModal(item: any) { + if (this.showActive) { + this.selectedUser = item.email; + this.deleteModal.alertTitle = 'Delete ' + this.role; + this.deleteModal.open(); + } else { + this.selectedUser = item; + this.deletePendingModal.alertTitle = 'Cancel invitation'; + this.deletePendingModal.open(); + } + } + + openInviteModal() { + this.inviteModal.alertTitle = 'Invite ' + this.role; + this.inviteModal.okButtonLeft = false; + this.inviteModal.okButtonText = 'Send'; + this.invited = this.fb.control('', [Validators.required, Validators.email]); + this.inviteModal.open(); + } + + openCreateRoleModal() { + this.createRoleModal.alertTitle = 'Create group'; + 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), + description: this.fb.control('', Validators.required) + }); + setTimeout(() => { + this.roleFb.get('name').disable(); + }, 0); + this.createRoleModal.open(); + } + + deleteActive() { + this.loadActive = true; + this.userRegistryService.remove(this.type, this.id, this.selectedUser, this.role).subscribe(() => { + this.active = this.active.filter(user => user.email != this.selectedUser); + this.loadActive = false; + this.error = null; + }, error => { + this.error = error.error.response; + this.loadActive = false; + }); + } + + deletePending() { + this.loadPending = true; + this.userRegistryService.cancelInvitation(this.type, this.id, this.selectedUser, this.role).subscribe(() => { + this.pending = this.pending.filter(user => user != this.selectedUser); + this.error = null; + this.loadPending = false; + }, error => { + this.error = error.error.response; + this.loadPending = false; + }); + } + + invite() { + this.loadActive = true; + let details = { + name: this.name, + link: this.link + } + this.userRegistryService.invite(this.type, this.id, this.invited.value, details, this.role).subscribe(() => { + this.error = null; + if (!this.pending.includes(this.invited.value)) { + this.pending.push(this.invited.value); + } + this.loadActive = false; + }, error => { + this.error = error.error.response; + this.loadActive = false; + }) + } + + createGroup() { + this.loadActive = true; + this.loadPending = true; + this.roleFb.get('name').enable(); + this.userRegistryService.createRole(this.type, this.id, this.roleFb.value).subscribe(() => { + UIkit.notification('Group has been created', { + status: 'success', + timeout: 3000, + pos: 'top-left' + }); + this.updateLists(); + }, error => { + UIkit.notification('An error has occurred. Please try again later', { + status: 'danger', + timeout: 3000, + pos: 'top-left' + }); + this.loadActive = false; + this.loadPending = false; + }); + } +} diff --git a/dashboard/users/members/members.module.ts b/dashboard/users/role-users/role-users.module.ts similarity index 86% rename from dashboard/users/members/members.module.ts rename to dashboard/users/role-users/role-users.module.ts index 58666ada..d087d4d2 100644 --- a/dashboard/users/members/members.module.ts +++ b/dashboard/users/role-users/role-users.module.ts @@ -1,23 +1,23 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; -import {MembersComponent} from './members.component'; +import {RoleUsersComponent} from './role-users.component'; import {ReactiveFormsModule} from '@angular/forms'; import {EmailService} from "../../../utils/email/email.service"; import {AlertModalModule} from "../../../utils/modal/alertModal.module"; import {LoadingModule} from "../../../utils/loading/loading.module"; -import {IconsModule} from "../../../utils/icons/icons.module"; import {IconsService} from "../../../utils/icons/icons.service"; import {person_add, remove_circle_outline} from "../../../utils/icons/icons"; +import {IconsModule} from "../../../utils/icons/icons.module"; import {InputModule} from "../../sharedComponents/input/input.module"; import {PageContentModule} from "../../sharedComponents/page-content/page-content.module"; @NgModule({ imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule], - declarations: [MembersComponent], - exports: [MembersComponent], + declarations: [RoleUsersComponent], + exports: [RoleUsersComponent], providers: [EmailService] }) -export class MembersModule { +export class RoleUsersModule { constructor(private iconsService: IconsService) { this.iconsService.registerIcons([remove_circle_outline, person_add]); } diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index 907dda61..66c7047d 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -1,174 +1,193 @@ import {StringUtils} from "../../utils/string-utils.class"; export class User { - email:string; - firstname: string; - lastname: string; - id: string; - fullname: string; - expirationDate: number; - role:string[]; - jwt:string; - + email: string; + firstname: string; + lastname: string; + id: string; + fullname: string; + expirationDate: number; + role: string[]; + jwt: string; + } -export class Session{ +export class Session { public static removeUser() { COOKIE.deleteCookie(COOKIE.cookieName_id); //COOKIE.deleteCookie("openAIRESession"); COOKIE.deleteCookie("openAIREUser"); } - + public static isLoggedIn(): boolean { - var cookie= COOKIE.getCookie(COOKIE.cookieName_id); - return (cookie != null && cookie != ""); + var cookie = COOKIE.getCookie(COOKIE.cookieName_id); + return (cookie != null && cookie != ""); } - - public static setReloadUrl(host:string,path:string, params:string) { + + public static setReloadUrl(host: string, path: string, params: string) { var URL = {}; - URL["host"]=host; - URL["path"]=path; - URL["params"]=params; + URL["host"] = host; + URL["path"] = path; + URL["params"] = params; COOKIE.setCookie("reloadURL", JSON.stringify(URL), -1); } - public static getReloadUrl(plainText:boolean =false) { + + public static getReloadUrl(plainText: boolean = false) { var URL = COOKIE.getCookie("reloadURL"); URL = JSON.parse(URL); return URL; - + } - public static getParamsObj(params:string) { - var object = null; - if(params.split("&").length > 0){ - object = {}; - } - params =(params && params.split("?").length > 1 )?params.split("?")[1]:params; - for(var i=0; i 0) { + object = {}; + } + params = (params && params.split("?").length > 1) ? params.split("?")[1] : params; + for (var i = 0; i < params.split("&").length; i++) { + object[(params.split("&")[i]).split("=")[0]] = (params.split("&")[i]).split("=")[1]; + } + return object; - + } - + //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); + user.role.indexOf('CURATOR_CLAIM') !== -1); } + public static isMonitorCurator(user: User): boolean { - return this.isCommunityCurator(user) || this.isProjectCurator(user) ||this.isFunderCurator(user) || this.isOrganizationCurator(user); + return this.isCommunityCurator(user) || this.isProjectCurator(user) || this.isFunderCurator(user) || this.isOrganizationCurator(user); } + public static isCommunityCurator(user: User): boolean { return this.isTypeCurator("Community", user); } + public static isFunderCurator(user: User): boolean { - return this.isTypeCurator("Funder", user); + return this.isTypeCurator("Funder", user); } + public static isProjectCurator(user: User): boolean { return this.isTypeCurator("Project", user); } + public static isOrganizationCurator(user: User): boolean { return this.isTypeCurator("Institution", user); } + private static isTypeCurator(type: string, user: User): boolean { return user && - ( user.role.indexOf('CURATOR_'+type.toUpperCase()) !== -1 || + (user.role.indexOf('CURATOR_' + type.toUpperCase()) !== -1 || user.role.indexOf('urn:geant:openaire.eu:group:Curator+-+' + type + '#aai.openaire.eu') !== -1); } + public static isCurator(type: string, user: User): boolean { - if(type == 'funder'){ - return user && this.isFunderCurator( user); - }else if(type == 'ri' || type == 'community'){ + if (type == 'funder') { + return user && this.isFunderCurator(user); + } else if (type == 'ri' || type == 'community') { return user && this.isCommunityCurator(user); - }else if(type == 'organization' || type == 'institution'){ + } else if (type == 'organization' || type == 'institution') { return user && this.isOrganizationCurator(user); - }else if(type == 'project'){ + } else if (type == 'project') { return user && this.isProjectCurator(user); } } - + 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); + user.role.indexOf('PORTAL_ADMINISTRATOR') !== -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); + user.role.indexOf('USER_MANAGER') !== -1); } public static isSubscribedTo(type: string, id: string, user: User): boolean { - return user && user.role.indexOf(type.toUpperCase() + '_' + id.toUpperCase()) !== -1; + return user && user.role.indexOf(this.mapType(type).toUpperCase() + '_' + id.toUpperCase()) !== -1; + } + + public static isMember(type: string, id: string, user: User): boolean { + return user && user.role.indexOf(this.mapType(type).toUpperCase() + '_' + id.toUpperCase()) !== -1; } public static isManager(type: string, id: string, user: User): boolean { - if(type == "ri"){ - type = "community"; - }else if (type == "organization"){ - type = "institution"; - } - return user && user.role.indexOf(type.toUpperCase() + '_' + id.toUpperCase() + '_MANAGER') !== -1 + return user && user.role.indexOf(this.mapType(type).toUpperCase() + '_' + id.toUpperCase() + '_MANAGER') !== -1 } - public static isKindOfMonitorManager(user: User): boolean { - if(user){ - for(let role of user.role ){ - if(role.indexOf('_MANAGER') !== -1){ - return true; - } - } + + public static isKindOfMonitorManager(user: User): boolean { + if (user) { + for (let role of user.role) { + if (role.indexOf('_MANAGER') !== -1) { + return true; } - return false; + } } - + return false; + } + 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); + user.role.indexOf('REGISTERED_USER') !== -1); + } + + public static mapType(type: string): string { + if (type == "ri") { + type = "community"; + } else if (type == "organization") { + type = "institution"; + } + return type; } - - } -export class COOKIE{ - public static cookieName_id:string="AccessToken"; - public static getCookie(name: string) : string { - if(typeof document == 'undefined'){ - return null; - } - let ca: Array = document.cookie.split(';'); - let caLen: number = ca.length; - let cookieName = `${name}=`; - let c: string; - - for (let i: number = 0; i < caLen; i += 1) { - c = ca[i].replace(/^\s+/g, ''); - if (c.indexOf(cookieName) == 0) { - return c.substring(cookieName.length, c.length); - } - } +export class COOKIE { + public static cookieName_id: string = "AccessToken"; + + public static getCookie(name: string): string { + if (typeof document == 'undefined') { return null; + } + let ca: Array = document.cookie.split(';'); + let caLen: number = ca.length; + let cookieName = `${name}=`; + let c: string; + + for (let i: number = 0; i < caLen; i += 1) { + c = ca[i].replace(/^\s+/g, ''); + if (c.indexOf(cookieName) == 0) { + return c.substring(cookieName.length, c.length); + } + } + return null; } + public static deleteCookie(name) { - this.setCookie(name, '', -1); + this.setCookie(name, '', -1); } + public static setCookie(name: string, value: string, expireDays: number, path: string = '/') { //TODO fix domain? - let d:Date = new Date(); - d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000); - let expires:string = `expires=${d.toUTCString()}`; - // let cpath:string = path ? `; path=${path}` : ''; - let domain = ""; - if(typeof document !== 'undefined'){ - if(document.domain.indexOf(".di.uoa.gr")!= -1){ // for development - domain = ".di.uoa.gr"; - }else if(document.domain.indexOf(".openaire.eu") != -1){ - domain = ".openaire.eu"; - } - document.cookie = name+'='+value+'; path='+path+'; domain='+domain+';SameSite=Lax;'; + let d: Date = new Date(); + d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000); + let expires: string = `expires=${d.toUTCString()}`; + // let cpath:string = path ? `; path=${path}` : ''; + let domain = ""; + if (typeof document !== 'undefined') { + if (document.domain.indexOf(".di.uoa.gr") != -1) { // for development + domain = ".di.uoa.gr"; + } else if (document.domain.indexOf(".openaire.eu") != -1) { + domain = ".openaire.eu"; } + document.cookie = name + '=' + value + '; path=' + path + '; domain=' + domain + ';SameSite=Lax;'; + } } } diff --git a/monitor/services/stakeholder.service.ts b/monitor/services/stakeholder.service.ts index 16c75051..bbf2fb97 100644 --- a/monitor/services/stakeholder.service.ts +++ b/monitor/services/stakeholder.service.ts @@ -25,7 +25,7 @@ export class StakeholderService { getStakeholder(alias:string): Observable { if(!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== alias) { this.promise = new Promise((resolve, reject) => { - this.http.get(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent(alias)).pipe(map(stakeholder => { + this.http.get(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent(alias), CustomOptions.registryOptions()).pipe(map(stakeholder => { return this.formalize(stakeholder); })).subscribe(stakeholder => { this.stakeholderSubject.next(stakeholder); diff --git a/role-verification/role-verification.component.ts b/role-verification/role-verification.component.ts index 98b26189..ef58e3f6 100644 --- a/role-verification/role-verification.component.ts +++ b/role-verification/role-verification.component.ts @@ -172,7 +172,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy { public verifyManager() { this.loading = true; - this.userRegistryService.verifyManager(this.verification.id, this.code.value).subscribe(() => { + this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => { this.loading = false; this.managerModal.cancel(); this.error = null; diff --git a/services/user-registry.service.ts b/services/user-registry.service.ts index c23b6e47..640b5a61 100644 --- a/services/user-registry.service.ts +++ b/services/user-registry.service.ts @@ -12,7 +12,12 @@ export class UserRegistryService { constructor(private http: HttpClient) { } - + + public createRole(type: string, id: string, role): Observable { + return this.http.post(properties.registryUrl + 'createRole', role, + 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'); } @@ -27,62 +32,19 @@ export class UserRegistryService { null, CustomOptions.registryOptions()); } - public removeManager(type: string, id: string, email: string): Observable { + public remove(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable { return this.http.delete(properties.registryUrl + - encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email), CustomOptions.registryOptions()); + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions()); } - public removeMember(type: string, id: string, email: string): Observable { - return this.http.delete(properties.registryUrl + - encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/member/' + encodeURIComponent(email), CustomOptions.registryOptions()); - } - - public inviteManager(type: string, id: string, email: string, details: any): Observable { + public invite(type: string, id: string, email: string, details: any, role: "member" | "manager" = "manager"): Observable { return this.http.post(properties.registryUrl + 'invite/' + - encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email), details, + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), details, CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); } - public inviteMember(type: string, id: string, email: string, details: any): Observable { - return this.http.post(properties.registryUrl + 'invite/' + - encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/member/' + encodeURIComponent(email), details, - CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); - } - - public cancelManagerInvitation(type: string, id: string, email: string): Observable { - return this.http.delete(properties.registryUrl + 'invite/' + - encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/manager/' + encodeURIComponent(email), - CustomOptions.registryOptions()); - } - - public cancelMemberInvitation(type: string, id: string, email: string): Observable { - return this.http.delete(properties.registryUrl + 'invite/' + - encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/member/' + encodeURIComponent(email), - CustomOptions.registryOptions()); - } - - public getPendingManagers(type: string, id: string): Observable { - return this.http.get(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/', - CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); - } - - public getPendingMembers(type: string, id: string): Observable { - return this.http.get(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/', - CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); - } - - public getMembers(type: string, id: string): Observable { - return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/', - CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); - } - - public getManagers(type: string, id: string): Observable { - return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/').pipe(map(response => response.response)); - } - - public getMembersEmail(type: string, id: string): Observable { - return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/members/email', - CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); + public verify(id: string, code: string, role: "member" | "manager" = "manager"): Observable { + return this.http.post(properties.registryUrl + 'verification/' + role + '/' + encodeURIComponent(id), code, CustomOptions.registryOptions()); } public getInvitation(id: string): Observable { @@ -90,19 +52,28 @@ export class UserRegistryService { .pipe(map((response: any) => response.response)); } - public verifyManager(id: string, code: string): Observable { - return this.http.post(properties.registryUrl + 'verification/manager/' + encodeURIComponent(id), code, CustomOptions.registryOptions()); - } - - public verifyMember(id: string, code: string): Observable { - return this.http.post(properties.registryUrl + 'verification/member/' + encodeURIComponent(id), code, CustomOptions.registryOptions()); - } - public deleteVerification(id: string): Observable { return this.http.delete(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions()); } - public getManagersEmail(type: string, id: string): Observable { - return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/email').pipe(map(response => response.response)); + public getActiveEmail(type: string, id: string, role: "member" | "manager" = "manager"): Observable { + return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/email', + CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); + } + + public getActiveNames(type: string, id: string, role: "member" | "manager" = "manager"): Observable { + return this.http.get(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/', + CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); + } + + public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable { + return this.http.get(properties.registryUrl + 'invite/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/', + CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); + } + + public cancelInvitation(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable { + return this.http.delete(properties.registryUrl + 'invite/' + + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/' + role + '/' + encodeURIComponent(email), + CustomOptions.registryOptions()); } } diff --git a/verification/verification.component.ts b/verification/verification.component.ts index 910df54d..6df0e063 100644 --- a/verification/verification.component.ts +++ b/verification/verification.component.ts @@ -55,7 +55,7 @@ export class VerificationComponent implements OnInit { verify() { this.loading = true; - this.userRegistryService.verifyManager(this.invitation.id, this.code.value).subscribe(() => { + this.userRegistryService.verify(this.invitation.id, this.code.value).subscribe(() => { this.state = 'verified'; this.loading = false; });