2023-12-18 16:35:36 +01:00
|
|
|
import {AfterViewInit, ChangeDetectorRef, Component, Input, OnInit, ViewChild} from "@angular/core";
|
2023-11-30 13:20:00 +01:00
|
|
|
import {Role, User} from "../login/utils/helper.class";
|
2020-10-05 15:15:33 +02:00
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
|
|
import {UserManagementService} from "../services/user-management.service";
|
|
|
|
import {UserRegistryService} from "../services/user-registry.service";
|
|
|
|
import {LoginErrorCodes} from "../login/utils/guardHelper.class";
|
2023-12-18 16:35:36 +01:00
|
|
|
import {Subscription} from "rxjs";
|
2022-09-23 12:25:08 +02:00
|
|
|
import {UntypedFormBuilder, UntypedFormControl, Validators} from "@angular/forms";
|
2020-10-05 15:15:33 +02:00
|
|
|
import {AlertModal} from "../utils/modal/alert";
|
2021-02-19 18:50:34 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
2021-03-01 17:05:37 +01:00
|
|
|
import {EmailService} from "../utils/email/email.service";
|
|
|
|
import {Composer} from "../utils/email/composer";
|
2023-02-09 15:30:24 +01:00
|
|
|
import {ClearCacheService} from "../services/clear-cache.service";
|
2023-11-30 13:20:00 +01:00
|
|
|
import {BaseComponent} from "../sharedComponents/base/base.component";
|
2020-10-05 15:15:33 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'role-verification',
|
|
|
|
template: `
|
2022-06-20 15:17:26 +02:00
|
|
|
<modal-alert #managerModal [overflowBody]="false" (alertOutput)="verifyManager()" (cancelOutput)="cancel()"
|
|
|
|
[okDisabled]="code.invalid || loading">
|
2020-10-05 15:15:33 +02:00
|
|
|
<div>
|
2022-06-20 15:17:26 +02:00
|
|
|
You have been invited to join <span
|
|
|
|
class="uk-text-bold">{{name}}</span> {{(service === 'monitor' ? 'Monitor' : 'Research Community')}} Dashboard
|
|
|
|
as a manager.
|
|
|
|
<span class="uk-text-primary">Fill</span> in the <span class="uk-text-primary">verification code</span>, sent to
|
|
|
|
your
|
2020-10-05 15:15:33 +02:00
|
|
|
email, to accept the invitation request.
|
|
|
|
</div>
|
2020-11-12 18:49:20 +01:00
|
|
|
<div *ngIf="!loading" class="uk-margin-medium-top uk-flex uk-flex-center">
|
2022-04-11 11:27:10 +02:00
|
|
|
<div input [formInput]="code" class="uk-width-medium" placeholder="Verification code">
|
2021-03-03 19:04:53 +01:00
|
|
|
<span *ngIf="error" error>{{error}}</span>
|
2020-11-12 18:49:20 +01:00
|
|
|
</div>
|
2020-10-05 15:15:33 +02:00
|
|
|
</div>
|
2021-02-19 18:50:34 +01:00
|
|
|
<div *ngIf="loading" class="uk-margin-medium-top uk-flex uk-flex-center">
|
2020-10-05 15:15:33 +02:00
|
|
|
<loading></loading>
|
|
|
|
</div>
|
|
|
|
</modal-alert>
|
2023-10-10 21:40:01 +02:00
|
|
|
<modal-alert #memberModal [overflowBody]="false" (cancelOutput)="cancel()"
|
2023-03-21 13:02:59 +01:00
|
|
|
(alertOutput)="verifyMember()" [okDisabled]="(code.invalid || loading) && !isMember">
|
2020-10-05 15:15:33 +02:00
|
|
|
<div *ngIf="!isMember">
|
|
|
|
<div>
|
2020-11-13 13:51:35 +01:00
|
|
|
You have been invited to join <span class="uk-text-bold">{{name}}</span> Monitor Dashboard as a member.
|
2022-06-20 15:17:26 +02:00
|
|
|
<span class="uk-text-primary">Fill</span> in the <span class="uk-text-primary">verification code</span>, sent
|
|
|
|
to
|
2020-10-05 15:15:33 +02:00
|
|
|
your
|
|
|
|
email, to accept the invitation request.
|
|
|
|
</div>
|
2020-11-12 18:49:20 +01:00
|
|
|
<div *ngIf="!loading" class="uk-margin-medium-top uk-flex uk-flex-wrap uk-flex-center">
|
2022-04-11 11:27:10 +02:00
|
|
|
<div input [formInput]="code" class="uk-width-medium" placeholder="Verification code">
|
2021-09-06 17:06:43 +02:00
|
|
|
<span *ngIf="error" error>{{error}}</span>
|
2020-11-12 18:49:20 +01:00
|
|
|
</div>
|
2020-10-05 15:15:33 +02:00
|
|
|
</div>
|
|
|
|
<div *ngIf="loading" class="uk-margin-medium-top">
|
|
|
|
<loading></loading>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="isMember">
|
|
|
|
<div>
|
2022-06-20 15:17:26 +02:00
|
|
|
Welcome! You are now a member of the OpenAIRE Monitor Dashboard for the <span
|
|
|
|
class="uk-text-bold">{{name}}</span>!
|
2020-10-05 15:15:33 +02:00
|
|
|
From now on, you will have access to our restricted content.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</modal-alert>
|
2022-06-20 15:17:26 +02:00
|
|
|
<modal-alert #errorModal (alertOutput)="cancel()" [overflowBody]="false">
|
2020-10-05 15:15:33 +02:00
|
|
|
<div>
|
2022-12-09 17:01:18 +01:00
|
|
|
We are unable to process the request. What happened?
|
2022-12-10 00:56:56 +01:00
|
|
|
<ul class="uk-margin-top uk-list uk-list-circle uk-list-primary">
|
2022-12-12 18:01:05 +01:00
|
|
|
<li>You are logged in with a different email, than the one you have received the invitation.
|
2023-01-20 16:31:36 +01:00
|
|
|
Check
|
|
|
|
<a *ngIf="!userInfoLink" [routerLink]="[userInfoLinkPrefix + '/user-info']" (click)="errorModal.cancel()">here</a>
|
|
|
|
<a *ngIf="userInfoLink" [href]="userInfoLink" (click)="errorModal.cancel()">here</a>
|
|
|
|
the email of your account.</li>
|
2022-12-09 17:01:18 +01:00
|
|
|
<li>The invitation has been canceled.</li>
|
|
|
|
<li>The URL is invalid.</li>
|
2022-12-10 00:56:56 +01:00
|
|
|
</ul>
|
2020-10-05 15:15:33 +02:00
|
|
|
</div>
|
|
|
|
</modal-alert>
|
|
|
|
`
|
|
|
|
})
|
2023-11-30 13:20:00 +01:00
|
|
|
export class RoleVerificationComponent extends BaseComponent implements OnInit, AfterViewInit {
|
2020-10-05 15:15:33 +02:00
|
|
|
@Input()
|
|
|
|
public id: string;
|
|
|
|
@Input()
|
2023-11-30 13:20:00 +01:00
|
|
|
set type(type: string) {
|
|
|
|
this._type = Role.GROUP + type;
|
|
|
|
}
|
2020-10-05 15:15:33 +02:00
|
|
|
@Input()
|
|
|
|
public name: string;
|
2021-02-19 18:50:34 +01:00
|
|
|
@Input()
|
2023-12-18 16:35:36 +01:00
|
|
|
public service: "connect" | "monitor" | "irish" = "monitor";
|
2022-12-09 17:01:18 +01:00
|
|
|
@Input()
|
|
|
|
public userInfoLinkPrefix = '';
|
2023-01-20 16:31:36 +01:00
|
|
|
@Input()
|
|
|
|
public userInfoLink = null;
|
2020-10-05 15:15:33 +02:00
|
|
|
public user: User;
|
|
|
|
public verification: any;
|
2022-09-23 12:25:08 +02:00
|
|
|
public code: UntypedFormControl;
|
2023-11-30 13:20:00 +01:00
|
|
|
private _type: string;
|
2022-10-24 16:21:32 +02:00
|
|
|
private paramsSubscription: Subscription;
|
2021-09-07 09:51:07 +02:00
|
|
|
@ViewChild('managerModal') managerModal: AlertModal;
|
|
|
|
@ViewChild('memberModal') memberModal: AlertModal;
|
|
|
|
@ViewChild('errorModal') errorModal: AlertModal;
|
2020-10-05 15:15:33 +02:00
|
|
|
public error: string = null;
|
|
|
|
public loading: boolean = false;
|
|
|
|
public isMember: boolean = false;
|
|
|
|
|
2023-11-30 13:20:00 +01:00
|
|
|
constructor(protected _route: ActivatedRoute,
|
|
|
|
protected _router: Router,
|
2022-09-23 12:25:08 +02:00
|
|
|
private fb: UntypedFormBuilder,
|
2021-03-01 17:05:37 +01:00
|
|
|
private emailService: EmailService,
|
2020-10-05 15:15:33 +02:00
|
|
|
private userManagementService: UserManagementService,
|
2023-02-09 15:30:24 +01:00
|
|
|
private userRegistryService: UserRegistryService,
|
2023-03-21 13:02:59 +01:00
|
|
|
private clearCacheService: ClearCacheService,
|
|
|
|
private cdr: ChangeDetectorRef) {
|
2023-11-30 13:20:00 +01:00
|
|
|
super();
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.reset();
|
2021-09-07 09:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2022-10-24 16:21:32 +02:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
|
|
|
this.user = user;
|
2023-11-30 13:20:00 +01:00
|
|
|
this.paramsSubscription = this._route.queryParams.subscribe(params => {
|
2023-03-21 13:02:59 +01:00
|
|
|
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;
|
2023-11-30 13:20:00 +01:00
|
|
|
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this._type === this.verification.type) {
|
2023-03-21 13:02:59 +01:00
|
|
|
if (this.verification.verificationType === 'manager') {
|
|
|
|
this.openManagerModal();
|
2023-10-10 21:40:01 +02:00
|
|
|
} else if (this.verification.verificationType === 'member') {
|
2023-03-21 13:02:59 +01:00
|
|
|
this.openMemberModal();
|
|
|
|
} else {
|
|
|
|
this.openErrorModal();
|
|
|
|
}
|
2022-06-20 15:17:26 +02:00
|
|
|
} else {
|
2021-02-19 18:50:34 +01:00
|
|
|
this.openErrorModal();
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
2023-03-21 13:02:59 +01:00
|
|
|
}, error => {
|
2020-10-05 15:15:33 +02:00
|
|
|
this.openErrorModal();
|
2023-03-21 13:02:59 +01:00
|
|
|
}));
|
|
|
|
} else {
|
2023-11-30 13:20:00 +01:00
|
|
|
this._router.navigate(['user-info'], {
|
2023-03-21 13:02:59 +01:00
|
|
|
queryParams: {
|
|
|
|
'errorCode': LoginErrorCodes.NOT_LOGIN,
|
2023-11-30 13:20:00 +01:00
|
|
|
'redirectUrl': this._router.url
|
2023-03-21 13:02:59 +01:00
|
|
|
},
|
2023-11-30 13:20:00 +01:00
|
|
|
relativeTo: this._route
|
2023-03-21 13:02:59 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if(this.isMember) {
|
|
|
|
this.openMemberModal();
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
2023-03-21 13:02:59 +01:00
|
|
|
} else {
|
|
|
|
this.isMember = false;
|
|
|
|
this.cdr.detectChanges();
|
2022-10-25 14:31:59 +02:00
|
|
|
}
|
|
|
|
});
|
2020-10-05 15:15:33 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2023-11-30 13:20:00 +01:00
|
|
|
super.ngOnDestroy();
|
2022-10-25 14:31:59 +02:00
|
|
|
if (this.paramsSubscription instanceof Subscription) {
|
2022-10-24 16:21:32 +02:00
|
|
|
this.paramsSubscription.unsubscribe();
|
|
|
|
}
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public openManagerModal() {
|
|
|
|
this.error = null;
|
2022-06-20 15:17:26 +02:00
|
|
|
this.managerModal.okButtonLeft = false;
|
|
|
|
this.managerModal.okButtonText = 'Accept';
|
|
|
|
this.managerModal.stayOpen = true;
|
|
|
|
this.managerModal.cancelButtonText = 'Cancel';
|
2020-10-05 15:15:33 +02:00
|
|
|
this.managerModal.alertTitle = 'Manager Invitation';
|
|
|
|
this.managerModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public openMemberModal() {
|
|
|
|
this.error = null;
|
2023-03-21 13:02:59 +01:00
|
|
|
if(this.isMember) {
|
|
|
|
this.memberModal.cancelButton = false;
|
|
|
|
this.memberModal.okButtonText = 'Close';
|
|
|
|
} else {
|
|
|
|
this.memberModal.cancelButton = true;
|
|
|
|
this.memberModal.okButtonText = 'Accept';
|
|
|
|
}
|
2022-06-20 15:17:26 +02:00
|
|
|
this.memberModal.okButtonLeft = false;
|
|
|
|
this.memberModal.stayOpen = true;
|
|
|
|
this.memberModal.cancelButtonText = 'Cancel';
|
2020-10-05 15:15:33 +02:00
|
|
|
this.memberModal.alertTitle = 'Member Invitation';
|
2023-03-21 13:02:59 +01:00
|
|
|
this.cdr.detectChanges();
|
2020-10-05 15:15:33 +02:00
|
|
|
this.memberModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public openErrorModal() {
|
|
|
|
this.error = null;
|
|
|
|
this.errorModal.cancelButton = false;
|
|
|
|
this.errorModal.okButtonText = 'Ok';
|
2022-12-12 18:01:05 +01:00
|
|
|
this.errorModal.alertTitle = 'Invalid URL';
|
2020-10-05 15:15:33 +02:00
|
|
|
this.errorModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public verifyManager() {
|
|
|
|
this.loading = true;
|
2022-10-24 16:21:32 +02:00
|
|
|
this.subscriptions.push(this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => {
|
2023-02-09 15:30:24 +01:00
|
|
|
this.clearCacheService.clearCache('Managers updated');
|
2020-10-05 15:15:33 +02:00
|
|
|
this.managerModal.cancel();
|
|
|
|
this.error = null;
|
2020-12-23 17:06:31 +01:00
|
|
|
this.userManagementService.updateUserInfo(() => {
|
2023-10-10 21:40:01 +02:00
|
|
|
if (this.paramsSubscription instanceof Subscription) {
|
|
|
|
this.paramsSubscription.unsubscribe();
|
|
|
|
}
|
2023-12-18 16:35:36 +01:00
|
|
|
if(this.service === "irish") {
|
|
|
|
this.loading = false;
|
|
|
|
this.userManagementService.login(properties.domain + '/admin/' + this.verification.entity);
|
|
|
|
} else if (this.service === "monitor" ) {
|
2021-03-01 17:05:37 +01:00
|
|
|
this.loading = false;
|
2023-11-30 13:20:00 +01:00
|
|
|
this._router.navigate(['/admin/' + this.verification.entity]);
|
2021-02-19 18:50:34 +01:00
|
|
|
} else {
|
2022-10-24 16:21:32 +02:00
|
|
|
this.subscriptions.push(this.emailService.notifyManagers(this.id, 'manager',
|
2021-03-01 17:05:37 +01:00
|
|
|
Composer.composeEmailToInformOldManagersForTheNewOnes(this.name, this.id)).subscribe(() => {
|
2022-10-24 16:21:32 +02:00
|
|
|
this.subscriptions.push(this.emailService.notifyNewManager(Composer.composeEmailForNewManager(this.id, this.name)).subscribe(
|
2021-03-01 17:05:37 +01:00
|
|
|
() => {
|
|
|
|
this.loading = false;
|
|
|
|
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
|
|
|
},
|
|
|
|
error1 => {
|
|
|
|
console.error(error1);
|
|
|
|
this.loading = false;
|
|
|
|
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}, error => {
|
|
|
|
console.error(error);
|
|
|
|
this.loading = false;
|
|
|
|
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
|
|
|
}));
|
2021-02-19 18:50:34 +01:00
|
|
|
}
|
2020-12-23 17:06:31 +01:00
|
|
|
});
|
2020-10-05 15:15:33 +02:00
|
|
|
}, error => {
|
|
|
|
this.loading = false;
|
|
|
|
this.error = 'The verification code is invalid';
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public verifyMember() {
|
|
|
|
this.loading = true;
|
2022-06-20 15:17:26 +02:00
|
|
|
if (!this.isMember) {
|
2022-10-24 16:21:32 +02:00
|
|
|
this.subscriptions.push(this.userRegistryService.verify(this.verification.id, this.code.value, "member").subscribe(() => {
|
2023-02-09 15:30:24 +01:00
|
|
|
this.clearCacheService.clearCache('Members updated');
|
2022-06-20 15:17:26 +02:00
|
|
|
this.loading = false;
|
|
|
|
this.error = null;
|
2023-10-10 21:40:01 +02:00
|
|
|
this.isMember = true;
|
2022-06-20 15:17:26 +02:00
|
|
|
this.userManagementService.updateUserInfo(() => {
|
2023-10-10 21:40:01 +02:00
|
|
|
if (this.paramsSubscription instanceof Subscription) {
|
|
|
|
this.paramsSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
this.cancel();
|
2022-06-20 15:17:26 +02:00
|
|
|
});
|
|
|
|
}, error => {
|
|
|
|
this.loading = false;
|
|
|
|
this.error = 'The verification code is invalid';
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
this.memberModal.cancel();
|
|
|
|
}
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
this.code = this.fb.control('', [Validators.required, Validators.pattern('^[+0-9]{6}$')]);
|
|
|
|
}
|
|
|
|
|
2022-06-20 15:17:26 +02:00
|
|
|
cancel() {
|
2023-10-10 21:40:01 +02:00
|
|
|
this.isMember = false;
|
2023-11-30 13:20:00 +01:00
|
|
|
this._router.navigate([]);
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
}
|