From 0f265f435b0cd243bdfcde3f4c4d2696246ce0c9 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 7 Jun 2023 14:22:14 +0300 Subject: [PATCH] Add emal composer for cache indicators report. Move parse userinfo from user-management service to helper. --- login/utils/helper.class.ts | 30 +++++++++++++++++++++++++ services/user-management.service.ts | 34 +---------------------------- utils/email/composer.ts | 18 ++++++++++++++- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index ca98fd5c..e178b9e7 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -8,6 +8,36 @@ export class User { role: string[]; jwt: string; + + constructor(info: any) { + this.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub; + this.firstname = (info.given_name) ? info.given_name : ""; + this.lastname = (info.family_name) ? info.family_name : ""; + this.email = info.email.toLowerCase(); // TODO remove, is a quick fix + this.fullname = (info.name) ? info.name : ""; + if (this.fullname == "") { + if (this.firstname != "") { + this.fullname += this.firstname; + } + if (this.lastname != "") { + this.fullname += this.lastname; + } + if (this.fullname == "") { //fullname is still empty set a default + this.fullname = "Anonymous user"; + } + } + this.role = []; + if (info.roles) { + info.roles.forEach(role => { + this.role.push(role); + }); + } else { + if (info.edu_person_entitlements) { + this.role = info.edu_person_entitlements; + } + } + this.expirationDate = info.exp_date; + } } export class Session { diff --git a/services/user-management.service.ts b/services/user-management.service.ts index 9291cc6a..33984410 100644 --- a/services/user-management.service.ts +++ b/services/user-management.service.ts @@ -41,7 +41,7 @@ export class UserManagementService { public updateUserInfo(resolve: Function = null) { this.subscription = this.http.get(properties.userInfoUrl, CustomOptions.registryOptions()).pipe(map(userInfo => { - return this.parseUserInfo(userInfo); + return new User(userInfo); })).subscribe(user => { this.getUserInfoSubject.next(user); if (resolve) { @@ -55,38 +55,6 @@ export class UserManagementService { }); } - private parseUserInfo(info: any) { - const user: User = new User(); - user.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub; - user.firstname = (info.given_name) ? info.given_name : ""; - user.lastname = (info.family_name) ? info.family_name : ""; - user.email = info.email.toLowerCase(); // TODO remove, is a quick fix - user.fullname = (info.name) ? info.name : ""; - if (user.fullname == "") { - if (user.firstname != "") { - user.fullname += user.firstname; - } - if (user.lastname != "") { - user.fullname += user.lastname; - } - if (user.fullname == "") { //fullname is still empty set a default - user.fullname = "Anonymous user"; - } - } - user.role = []; - if (info.roles) { - info.roles.forEach(role => { - user.role.push(role); - }); - } else { - if (info.edu_person_entitlements) { - user.role = info.edu_person_entitlements; - } - } - user.expirationDate = info.exp_date; - return user; - } - public setRedirectUrl(url: string = null) { if (url) { let parts = url.split('?'); diff --git a/utils/email/composer.ts b/utils/email/composer.ts index 14de4338..6f57e3ed 100644 --- a/utils/email/composer.ts +++ b/utils/email/composer.ts @@ -2,6 +2,9 @@ import {Email} from "./email"; import {Body} from "./body"; import {FormArray} from "@angular/forms"; import {properties} from "../../../../environments/environment"; +import {Stakeholder} from "../../monitor/entities/stakeholder"; +import {Report} from "../../../../cache-indicators"; +import {error} from "protractor"; export class Composer { private static noteBodySize = "14px"; @@ -89,7 +92,7 @@ export class Composer { + "Affiliation: " + (contactForm.affiliation ? contactForm.affiliation : '-') + "
" + "

" + contactForm.message + "

" + ""; - email.recipients = admins; + email.recipients = admins; return email; } @@ -184,6 +187,19 @@ export class Composer { return email; } + public static composeEmailToReportCachingProcess(report: Report) { + let email: Email = new Email(); + email.recipients = [report.creator]; + email.subject = 'OpenAIRE | Monitor Dashboard - ' + report.name + '\'s caching process has been finished'; + email.body = "
" + + "

" + + "

Success: " + report.success + "/" + report.total + "
" + + "
Errors: " + report.errors.map(error => error.url + ' - ' + error.status).join('
') + "
" + + "

" + + "
"; + return email; + } + public static formatEmailBodyForInvitation(body: Body): string { let fromMessageAndName = "";