[Library | Trunk]: Change notification emails methods

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60529 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-03-01 16:05:37 +00:00
parent fe7fa1298e
commit 57d4983341
3 changed files with 42 additions and 29 deletions

View File

@ -8,6 +8,8 @@ import {Subscriber} from "rxjs";
import {FormBuilder, FormControl, Validators} from "@angular/forms";
import {AlertModal} from "../utils/modal/alert";
import {properties} from "../../../environments/environment";
import {EmailService} from "../utils/email/email.service";
import {Composer} from "../utils/email/composer";
@Component({
selector: 'role-verification',
@ -103,6 +105,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy {
constructor(private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private emailService: EmailService,
private userManagementService: UserManagementService,
private userRegistryService: UserRegistryService) {
}
@ -178,14 +181,31 @@ export class RoleVerificationComponent implements OnInit, OnDestroy {
public verifyManager() {
this.loading = true;
this.subs.push(this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => {
this.loading = false;
this.managerModal.cancel();
this.error = null;
this.userManagementService.updateUserInfo(() => {
if(this.service === "monitor") {
this.loading = false;
this.router.navigate(['/admin/' + this.verification.entity]);
} else {
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
this.subs.push(this.emailService.notifyManagers(this.id, 'manager',
Composer.composeEmailToInformOldManagersForTheNewOnes(this.name, this.id)).subscribe(() => {
this.subs.push(this.emailService.notifyNewManager(Composer.composeEmailForNewManager(this.id, this.name)).subscribe(
() => {
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;
}));
}
});
}, error => {

View File

@ -14,11 +14,11 @@ export class Composer {
private static ifYouAreNotResponsible(mail): string {
return "If you are not responsible for this community, please "
+ "<a href=\mailto:'" + mail + "\'>contact us</a>. ";
+ "<a href='mailto:" + mail + "'>contact us</a>. ";
}
private static manageNotificationSettings(communityId: string): string {
return "Click <a href='" + properties.adminPortalURL+ "/manage-user-notifications?communityId="
return "Click <a href='" + properties.adminPortalURL + "/" + communityId + "/users/notifications"
+ communityId + "'>here</a> to manage your notification settings. ";
}
@ -27,7 +27,7 @@ export class Composer {
+ "<a href='https://"+ (properties.environment == "production"?'':'beta.') + communityId + ".openaire.eu/'>" + communityName + "</a>. ";
}
public static composeEmailForNewManager(communityId: string, communityName: string, newCommunityManagers: any, mail: string): Email {
public static composeEmailForNewManager(communityId: string, communityName: string): Email {
let email: Email = new Email();
email.subject = this.subjectPrefix + communityName + ": Welcome new manager";
@ -41,10 +41,8 @@ export class Composer {
+ "You can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the dashboard."
+ "</p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>" + this.ifYouAreNotResponsible(mail) + "<p>"
+ "<p style='font-size:" + this.noteFontSize + "'>" + this.ifYouAreNotResponsible(properties.admins[0]) + "<p>"
+ "</div>";
email.recipients = newCommunityManagers;
return email;
}
@ -135,34 +133,32 @@ export class Composer {
return email;
}
public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string, firstVersionOfManagers: any, managers: any, mail: string) : Email {
public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string) : Email {
let email: Email = new Email();
email.subject = this.subjectPrefix + communityName + ": Managers list notification";
email.body = "<div style='font-size:" + this.noteBodySize + "'>"
+ "<p>There are updates in the managers list for \"" + communityName + "\" community.<br>"
+ "The list of managers is: " + managers.join(', ') + "</p>"
+ "The list of managers is: ((__managers__))</p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>"
+ this.youAreManagerOfTheCommunity(communityId, communityName)
+ this.ifYouAreNotResponsible(mail)
+ this.ifYouAreNotResponsible(properties.admins[0])
+ "<br>"
+ this.manageNotificationSettings(communityId)
+ "</p>"
+ "</div>";
email.recipients = firstVersionOfManagers;
return email;
}
public static composeEmailToInformManagers(communityName: string, communityId: string, managers: any, subscriberMail: any, adminPortalURL: string): Email {
public static composeEmailToInformManagers(communityName: string, communityId: string, subscriberName: string): Email {
let email: Email = new Email();
email.subject = this.subjectPrefix + communityName + ": New subscriber notification";
email.body = "<div style='font-size" + this.noteBodySize + "'>"
+ "<p>There is a new subscriber ("+subscriberMail+") for \"" + communityName + "\" community. Click "
+ "<a href='" + adminPortalURL + "/manage-subscribers?communityId="
+ communityId + "'>here</a> to manage the subscribers list. </p>"
+ "<p>There is a new subscriber ("+subscriberName+") for \"" + communityName + "\" community. Click "
+ "<a href='" + properties.adminPortalURL + "/" + communityId + "/users/subscribers"
+ "'>here</a> to manage the subscribers list. </p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>"
+ this.youAreManagerOfTheCommunity(communityId, communityName)
@ -170,8 +166,6 @@ export class Composer {
+ this.manageNotificationSettings(communityId)
+ "</p>"
+ "</div>";
email.recipients = managers;
return email;
}

View File

@ -5,25 +5,24 @@ import {CustomOptions} from '../../services/servicesUtils/customOptions.class';
import {EmailRecaptcha} from "../entities/EmailRecaptcha";
import {Observable} from "rxjs";
import {EnvProperties} from "../properties/env-properties";
import {properties} from "../../../../environments/environment";
@Injectable()
export class EmailService {
constructor(private http:HttpClient) {
}
notifyForNewManagers(properties: EnvProperties, pid: string, email: Email) {
let body = JSON.stringify(email);
return this.http.post(properties.adminToolsAPIURL + "/notifyForNewSubscribers/" + pid, body, CustomOptions.getAuthOptionsWithBody());
//.map(request => request.json());
notifyManagers(pid: string, role: "manager" | "subscriber", email: Email) {
return this.http.post(properties.adminToolsAPIURL + '/notifyManagers/' + pid + '/' + role, email, CustomOptions.getAuthOptions())
}
notifyNewManager(email: Email) {
return this.http.post(properties.adminToolsAPIURL + '/notifyNewManager', email, CustomOptions.getAuthOptions())
}
sendEmail(properties: EnvProperties, email: Email) {
let body = JSON.stringify(email);
return this.http.post(properties.adminToolsAPIURL + "/sendMail/", body, CustomOptions.getAuthOptionsWithBody());
//.map(request => request.json());
return this.http.post(properties.adminToolsAPIURL + "/sendMail/", email, CustomOptions.registryOptions());
}
contact(properties: EnvProperties, email: Email, recaptcha: string = null):Observable<boolean> {