diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index 665a8303..ac0961a9 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -8,14 +8,7 @@ import { SimpleChanges, ViewChild } from '@angular/core'; -import { - UntypedFormArray, - UntypedFormBuilder, - UntypedFormControl, - UntypedFormGroup, - ValidatorFn, - Validators -} from '@angular/forms'; +import {UntypedFormArray, UntypedFormBuilder, UntypedFormGroup, ValidatorFn, Validators} from '@angular/forms'; import {AlertModal} from "../../../utils/modal/alert"; import {UserRegistryService} from "../../../services/user-registry.service"; import {EnvProperties} from "../../../utils/properties/env-properties"; @@ -29,7 +22,6 @@ import {forkJoin, of, Subscription} from "rxjs"; import {NotificationHandler} from "../../../utils/notification-handler"; import {ClearCacheService} from "../../../services/clear-cache.service"; import {catchError, map, tap} from "rxjs/operators"; -import notification = CKEDITOR.plugins.notification; import {InputComponent} from "../../../sharedComponents/input/input.component"; class InvitationResponse { diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index c58991ac..4c6301af 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -207,6 +207,7 @@ export class COOKIE { } export class Role { + public static GROUP = ''; public static PORTAL_ADMIN = 'PORTAL_ADMINISTRATOR'; public static REGISTERED_USER = 'REGISTERED_USER'; public static ANONYMOUS_USER = 'ROLE_ANONYMOUS'; @@ -220,7 +221,7 @@ export class Role { } else if (type == "organization") { type = "institution"; } - return type; + return Role.GROUP + type; } /** diff --git a/role-verification/role-verification.component.ts b/role-verification/role-verification.component.ts index c4a9a71a..29d993dc 100644 --- a/role-verification/role-verification.component.ts +++ b/role-verification/role-verification.component.ts @@ -1,5 +1,5 @@ import {AfterViewInit, ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core"; -import {User} from "../login/utils/helper.class"; +import {Role, User} from "../login/utils/helper.class"; import {ActivatedRoute, Router} from "@angular/router"; import {UserManagementService} from "../services/user-management.service"; import {UserRegistryService} from "../services/user-registry.service"; @@ -11,6 +11,7 @@ import {properties} from "../../../environments/environment"; import {EmailService} from "../utils/email/email.service"; import {Composer} from "../utils/email/composer"; import {ClearCacheService} from "../services/clear-cache.service"; +import {BaseComponent} from "../sharedComponents/base/base.component"; @Component({ selector: 'role-verification', @@ -77,11 +78,13 @@ import {ClearCacheService} from "../services/clear-cache.service"; ` }) -export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewInit { +export class RoleVerificationComponent extends BaseComponent implements OnInit, AfterViewInit { @Input() public id: string; @Input() - public type: string; + set type(type: string) { + this._type = Role.GROUP + type; + } @Input() public name: string; @Input() @@ -93,7 +96,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn public user: User; public verification: any; public code: UntypedFormControl; - private subscriptions: any[] = []; + private _type: string; private paramsSubscription: Subscription; @ViewChild('managerModal') managerModal: AlertModal; @ViewChild('memberModal') memberModal: AlertModal; @@ -102,14 +105,15 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn public loading: boolean = false; public isMember: boolean = false; - constructor(private route: ActivatedRoute, - private router: Router, + constructor(protected _route: ActivatedRoute, + protected _router: Router, private fb: UntypedFormBuilder, private emailService: EmailService, private userManagementService: UserManagementService, private userRegistryService: UserRegistryService, private clearCacheService: ClearCacheService, private cdr: ChangeDetectorRef) { + super(); } ngOnInit() { @@ -119,14 +123,14 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn ngAfterViewInit() { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.user = user; - this.paramsSubscription = this.route.queryParams.subscribe(params => { + this.paramsSubscription = this._route.queryParams.subscribe(params => { if (params) { this.cdr.detectChanges(); if(params['verify'] && !this.isMember) { if (this.user) { this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => { this.verification = verification; - if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) { + if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this._type === this.verification.type) { if (this.verification.verificationType === 'manager') { this.openManagerModal(); } else if (this.verification.verificationType === 'member') { @@ -141,12 +145,12 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn this.openErrorModal(); })); } else { - this.router.navigate(['user-info'], { + this._router.navigate(['user-info'], { queryParams: { 'errorCode': LoginErrorCodes.NOT_LOGIN, - 'redirectUrl': this.router.url + 'redirectUrl': this._router.url }, - relativeTo: this.route + relativeTo: this._route }); } } else if(this.isMember) { @@ -161,14 +165,10 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn } ngOnDestroy() { + super.ngOnDestroy(); if (this.paramsSubscription instanceof Subscription) { this.paramsSubscription.unsubscribe(); } - this.subscriptions.forEach(subscription => { - if (subscription instanceof Subscriber) { - subscription.unsubscribe(); - } - }); } public openManagerModal() { @@ -216,9 +216,9 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn if (this.paramsSubscription instanceof Subscription) { this.paramsSubscription.unsubscribe(); } - if (this.service === "monitor") { + if (this.service === "monitor" ) { this.loading = false; - this.router.navigate(['/admin/' + this.verification.entity]); + this._router.navigate(['/admin/' + this.verification.entity]); } else { this.subscriptions.push(this.emailService.notifyManagers(this.id, 'manager', Composer.composeEmailToInformOldManagersForTheNewOnes(this.name, this.id)).subscribe(() => { @@ -275,6 +275,6 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn cancel() { this.isMember = false; - this.router.navigate([]); + this._router.navigate([]); } } diff --git a/services/user-registry.service.ts b/services/user-registry.service.ts index 0e8db8ea..561e7da8 100644 --- a/services/user-registry.service.ts +++ b/services/user-registry.service.ts @@ -4,6 +4,7 @@ import {Observable} from 'rxjs'; import {properties} from '../../../environments/environment'; import {CustomOptions} from './servicesUtils/customOptions.class'; import {map} from 'rxjs/operators'; +import {Role} from "../login/utils/helper.class"; @Injectable({ providedIn: 'root' @@ -14,7 +15,7 @@ export class UserRegistryService { } public createRole(type: string, id: string): Observable { - return this.http.post(properties.registryUrl + 'create/' + type + '/' + id, null, + return this.http.post(properties.registryUrl + 'create/' + Role.GROUP + type + '/' + id, null, CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); } @@ -35,12 +36,12 @@ export class UserRegistryService { public remove(type: string, id: string, email: string, role: "member" | "manager" = "manager"): Observable { return this.http.delete(properties.registryUrl + - type + '/' + id + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions()); + Role.GROUP + type + '/' + id + '/' + role + '/' + encodeURIComponent(email), CustomOptions.registryOptions()); } public invite(type: string, id: string, details: any, role: "member" | "manager" = "manager"): Observable { return this.http.post(properties.registryUrl + 'invite/' + - type + '/' + id + '/' + role, details, + Role.GROUP + type + '/' + id + '/' + role, details, CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); } @@ -58,7 +59,7 @@ export class UserRegistryService { } public getActive(type: string, id: string, role: "member" | "manager" = "manager"): Observable { - let url = properties.registryUrl + type + '/' + id + "/" + role + 's'; + let url = properties.registryUrl + Role.GROUP + type + '/' + id + "/" + role + 's'; return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url, CustomOptions.registryOptions()).pipe(map((response:any) => response.response), map(users => { if(users.length > 0 && !users[0].email) { @@ -70,7 +71,7 @@ export class UserRegistryService { } public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable { - let url = properties.registryUrl + 'invite/' +type + '/' +id + "/" + role + 's/'; + let url = properties.registryUrl + 'invite/' + Role.GROUP + type + '/' +id + "/" + role + 's/'; return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url, CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); }