From e32f6cdae825bcff4826b894d6e569849fd953fc Mon Sep 17 00:00:00 2001 From: "sofia.baltzi" Date: Tue, 20 Nov 2018 15:53:54 +0000 Subject: [PATCH] Send email to a new Manager git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@53894 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../community-edit-form.component.ts | 45 ++++++++++++++++++- .../community-edit-form.module.ts | 3 +- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/app/pages/community/community-edit-form/community-edit-form.component.ts b/src/app/pages/community/community-edit-form/community-edit-form.component.ts index bb13397..aacf613 100644 --- a/src/app/pages/community/community-edit-form/community-edit-form.component.ts +++ b/src/app/pages/community/community-edit-form/community-edit-form.component.ts @@ -5,10 +5,13 @@ import {ActivatedRoute, Router} from '@angular/router'; import {HelpContentService} from "../../../services/help-content.service"; import {CommunityService} from "../../../openaireLibrary/connect/community/community.service"; -import {SubscribeService} from "../../../openaireLibrary/utils/subscribe/subscribe.service" +import {SubscribeService} from "../../../openaireLibrary/utils/subscribe/subscribe.service"; +import {EmailService} from "../../../openaireLibrary/utils/email/email.service"; + import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties'; import {CommunityInfo} from '../../../openaireLibrary/connect/community/communityInfo'; +import {Email} from "../../../openaireLibrary/utils/email/email"; import {Session} from '../../../openaireLibrary/login/utils/helper.class'; import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; @@ -41,6 +44,8 @@ export class CommunityEditFormComponent implements OnInit{ public firstVersionOfManagers: string[]; public newManagersToSubscribe: string[]; + public email: Email; + public properties:EnvProperties = null; constructor (private route: ActivatedRoute, @@ -48,7 +53,8 @@ export class CommunityEditFormComponent implements OnInit{ public _fb: FormBuilder, private _helpContentService: HelpContentService, private _communityService: CommunityService, - private _subscribeService: SubscribeService){ } + private _subscribeService: SubscribeService, + private _emailService: EmailService){ } ngOnInit() { @@ -58,6 +64,8 @@ export class CommunityEditFormComponent implements OnInit{ communityId => { this.communityId = communityId['communityId']; + this.email = {body: "", subject: "", recipients: []}; + if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); @@ -146,6 +154,7 @@ export class CommunityEditFormComponent implements OnInit{ // TODO delete after testing console.log("New managers in component: " + newManagers); if (newManagers !== null) { + this.sendMailToNewManagers(newManagers); for (let i = 0; i < newManagers.length; i++) { console.log(newManagers[i]); this._subscribeService.subscribeToCommunity(this.communityId, newManagers[i], this.properties.adminToolsAPIURL).subscribe( @@ -206,6 +215,38 @@ export class CommunityEditFormComponent implements OnInit{ return newManagers; } + private sendMailToNewManagers(managers: any) { + this._emailService.sendEmail("http://scoobydoo.di.uoa.gr:8080/uoa-admin-tools/sendMail", this.composeEmailForNewManager(this.community.title, managers)).subscribe( + res => { + console.log("The email has been sent successfully!") + }, + error => console.log(error) + ); + // console.log("Stelnei mail"); + } + + private informOldManagersForTheNewOnes(managers: any) { + + } + + // TODO find the right place to write it + private composeEmailForNewManager(communityName: string, newCommunityManagers: any): Email { + this.email.subject = "[OpenAIRE-Connect] " + communityName + ": Managers list notification"; + this.email.body = "

There are updates in the managers list for" + communityName + "community.
" + + "The list of managers is: " + newCommunityManagers + "



" + + "OpenAIRE team
"+ "www.openaire.eu"; + this.email.recipients = newCommunityManagers; + + console.log(this.email); + + return this.email; + } + + // TODO find the right place to write it + private composeEmailToInformOldManagersForTheNewOnes() { + + } + private subscribeNewManagers(newManagers: string[]): boolean { return true; } diff --git a/src/app/pages/community/community-edit-form/community-edit-form.module.ts b/src/app/pages/community/community-edit-form/community-edit-form.module.ts index 8b6c0ad..3a3374f 100644 --- a/src/app/pages/community/community-edit-form/community-edit-form.module.ts +++ b/src/app/pages/community/community-edit-form/community-edit-form.module.ts @@ -6,6 +6,7 @@ import {RouterModule} from '@angular/router'; import {CommunityEditFormComponent} from './community-edit-form.component'; import {CommunityService} from '../../../openaireLibrary/connect/community/community.service'; +import {EmailService} from '../../../openaireLibrary/utils/email/email.service'; @NgModule({ imports:[ @@ -15,7 +16,7 @@ import {CommunityService} from '../../../openaireLibrary/connect/commu CommunityEditFormComponent ], providers:[ - CommunityService + CommunityService, EmailService ], exports: [ CommunityEditFormComponent