Add emal composer for cache indicators report. Move parse userinfo from user-management service to helper.

This commit is contained in:
Konstantinos Triantafyllou 2023-06-07 14:22:14 +03:00
parent 4e91d169e0
commit 0f265f435b
3 changed files with 48 additions and 34 deletions

View File

@ -8,6 +8,36 @@ export class User {
role: string[]; role: string[];
jwt: 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 { export class Session {

View File

@ -41,7 +41,7 @@ export class UserManagementService {
public updateUserInfo(resolve: Function = null) { public updateUserInfo(resolve: Function = null) {
this.subscription = this.http.get<User>(properties.userInfoUrl, CustomOptions.registryOptions()).pipe(map(userInfo => { this.subscription = this.http.get<User>(properties.userInfoUrl, CustomOptions.registryOptions()).pipe(map(userInfo => {
return this.parseUserInfo(userInfo); return new User(userInfo);
})).subscribe(user => { })).subscribe(user => {
this.getUserInfoSubject.next(user); this.getUserInfoSubject.next(user);
if (resolve) { 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) { public setRedirectUrl(url: string = null) {
if (url) { if (url) {
let parts = url.split('?'); let parts = url.split('?');

View File

@ -2,6 +2,9 @@ import {Email} from "./email";
import {Body} from "./body"; import {Body} from "./body";
import {FormArray} from "@angular/forms"; import {FormArray} from "@angular/forms";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {Stakeholder} from "../../monitor/entities/stakeholder";
import {Report} from "../../../../cache-indicators";
import {error} from "protractor";
export class Composer { export class Composer {
private static noteBodySize = "14px"; private static noteBodySize = "14px";
@ -89,7 +92,7 @@ export class Composer {
+ "<span><b>Affiliation</b>: " + (contactForm.affiliation ? contactForm.affiliation : '-') + "</span><br>" + "<span><b>Affiliation</b>: " + (contactForm.affiliation ? contactForm.affiliation : '-') + "</span><br>"
+ "<p>" + contactForm.message + "</p>" + "<p>" + contactForm.message + "</p>"
+ "</div>"; + "</div>";
email.recipients = admins; email.recipients = admins;
return email; return email;
} }
@ -184,6 +187,19 @@ export class Composer {
return email; 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 = "<div style='font-size" + this.noteBodySize + "'>"
+ "<p>"
+ "<div>Success: " + report.success + "/" + report.total + "</div>"
+ "<div>Errors: " + report.errors.map(error => error.url + ' - ' + error.status).join('<br>') + "</div>"
+ "</p>"
+ "</div>";
return email;
}
public static formatEmailBodyForInvitation(body: Body): string { public static formatEmailBodyForInvitation(body: Body): string {
let fromMessageAndName = ""; let fromMessageAndName = "";