Add emal composer for cache indicators report. Move parse userinfo from user-management service to helper.
This commit is contained in:
parent
4e91d169e0
commit
0f265f435b
|
@ -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 {
|
||||
|
|
|
@ -41,7 +41,7 @@ export class UserManagementService {
|
|||
|
||||
public updateUserInfo(resolve: Function = null) {
|
||||
this.subscription = this.http.get<User>(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('?');
|
||||
|
|
|
@ -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 {
|
|||
+ "<span><b>Affiliation</b>: " + (contactForm.affiliation ? contactForm.affiliation : '-') + "</span><br>"
|
||||
+ "<p>" + contactForm.message + "</p>"
|
||||
+ "</div>";
|
||||
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 = "<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 {
|
||||
let fromMessageAndName = "";
|
||||
|
||||
|
|
Loading…
Reference in New Issue