From 9116632a33596f54d368523fb8febe873293bf52 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Mon, 22 Jul 2024 09:33:30 +0200 Subject: [PATCH 01/12] email action wip --- src/jobs/actions/emailaction.ts | 61 ++++++++++++-------------- src/jobs/config/jobConfig.example.json | 8 ++++ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index 54d67a186..b9aba11d6 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -13,13 +13,8 @@ import { compile, TemplateDelegate } from "handlebars"; * Send an email following a job */ export class EmailJobAction implements JobAction { - private mailService: Transporter; - private toTemplate: TemplateDelegate; - private from: string; - private subjectTemplate: TemplateDelegate; - private bodyTemplate?: TemplateDelegate; - public static readonly actionType = "email"; + private mailerDetails; getActionType(): string { return EmailJobAction.actionType; @@ -31,28 +26,13 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); - if (!data["mailer"]) { - throw new NotFoundException("Param 'mailer' is undefined"); - } - if (!data["to"]) { - throw new NotFoundException("Param 'to' is undefined"); - } - if (!data["from"]) { - throw new NotFoundException("Param 'from' is undefined"); - } - if (!data["subject"]) { - throw new NotFoundException("Param 'subject' is undefined"); - } - if (!data["body"]) { - throw new NotFoundException("Param 'body' is undefined"); - } - Logger.log("EmailJobAction parameters are valid.", "EmailJobAction"); - - this.mailService = createTransport(data["mailer"]); - this.toTemplate = compile(data["to"]); - this.from = data["from"]; - this.subjectTemplate = compile(data["subject"]); - this.bodyTemplate = compile(data["body"]); + this.mailerDetails = { + mailer: data.mailer, + to: data.to, + from: data.from, + subject: data.subject, + bodyTemplate: data.bodyTemplate, + }; } async validate(dto: T) { @@ -60,6 +40,11 @@ export class EmailJobAction implements JobAction { "Validating EmailJobAction: " + JSON.stringify(dto), "EmailJobAction", ); + + const mailerDetailsMissing = [undefined, ""].some(el => Object.values(this.mailerDetails).includes(el)); + if (mailerDetailsMissing) { + throw new NotFoundException("Email action is not configured correctly."); + } } async performJob(job: JobClass) { @@ -68,15 +53,23 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); + // const mailService: Transporter = createTransport(this.mailerDetails.mailer); + const toTemplate: TemplateDelegate = compile(this.mailerDetails.to); + const subjectTemplate: TemplateDelegate = compile(this.mailerDetails.subject); + const bodyTemplate: TemplateDelegate = compile(this.mailerDetails.bodyTemplate); + // Fill templates const mail: any = { - to: this.toTemplate(job), - from: this.from, - subject: this.subjectTemplate(job), + to: toTemplate(job), + from: this.mailerDetails.from, + subject: subjectTemplate(job), }; - if (this.bodyTemplate) { - mail.text = this.bodyTemplate(job); + if (bodyTemplate) { + mail.text = bodyTemplate(job); } - await this.mailService.sendMail(mail); + + Logger.log(mail); + + // await mailService.sendMail(mail); } } diff --git a/src/jobs/config/jobConfig.example.json b/src/jobs/config/jobConfig.example.json index 83133d71e..5fce6f9f0 100644 --- a/src/jobs/config/jobConfig.example.json +++ b/src/jobs/config/jobConfig.example.json @@ -15,6 +15,14 @@ "headers": { "accept": "application/json" } + }, + { + "actionType": "email", + "mailer": "smtp", + "to": "{{job.contactEmail}}", + "from": "someone", + "subject": "[SciCat] Your {{job.type}} job was submitted successfully", + "bodyTemplate": "some-file" } ] }, From 2baf98c0c945495357afc1b77f24f3eec0a50eb2 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Thu, 25 Jul 2024 15:34:14 +0200 Subject: [PATCH 02/12] wip --- .../job-template-simplified.html | 89 +++++++++++++++++++ src/jobs/actions/emailaction.ts | 64 +++++++++---- src/jobs/config/jobConfig.example.json | 10 +-- src/jobs/schemas/job.schema.mapping.json | 30 +++++++ 4 files changed, 170 insertions(+), 23 deletions(-) create mode 100644 src/common/email-templates/job-template-simplified.html create mode 100644 src/jobs/schemas/job.schema.mapping.json diff --git a/src/common/email-templates/job-template-simplified.html b/src/common/email-templates/job-template-simplified.html new file mode 100644 index 000000000..50989b065 --- /dev/null +++ b/src/common/email-templates/job-template-simplified.html @@ -0,0 +1,89 @@ + + + + + +
+
+ Your {{type}} job has been submitted and will be processed as soon as possible.
+ You will be notified by email as soon as the job is completed.
+ Job id: {{id}} +
+ {{#if jobParams.datasetIds}} +

Job will be perfomed on the following dataset(s):

+ + {{#each jobParams.datasetIds}} + + + + {{/each}} +
+ {{this}} +
+ {{/if}} + + +
+ + diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index b9aba11d6..bd4ce6f6b 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -3,18 +3,35 @@ * This is intended as an example of the JobAction interface * */ +import { readFileSync } from "fs"; +import { compile, TemplateDelegate } from "handlebars"; import { Logger, NotFoundException } from "@nestjs/common"; import { JobAction } from "../config/jobconfig"; import { JobClass } from "../schemas/job.schema"; -import { createTransport, Transporter } from "nodemailer"; -import { compile, TemplateDelegate } from "handlebars"; +import configuration from "src/config/configuration"; +import { createTransport, Transporter, } from "nodemailer"; + + +// Handlebar options for JobClass templates +const jobTemplateOptions = { + allowedProtoProperties: { + id: true, + type: true, + statusCode: true, + statusMessage: true, + createdBy: true, + jobParams: true, + }, + allowProtoPropertiesByDefault: false, // limit accessible fields for security +}; + /** * Send an email following a job */ export class EmailJobAction implements JobAction { public static readonly actionType = "email"; - private mailerDetails; + private messageDetails; getActionType(): string { return EmailJobAction.actionType; @@ -26,10 +43,10 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); - this.mailerDetails = { - mailer: data.mailer, + this.messageDetails = { to: data.to, from: data.from, + password: data.password, subject: data.subject, bodyTemplate: data.bodyTemplate, }; @@ -41,8 +58,8 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); - const mailerDetailsMissing = [undefined, ""].some(el => Object.values(this.mailerDetails).includes(el)); - if (mailerDetailsMissing) { + const messageDetailsMissing = [undefined, ""].some(el => Object.values(this.messageDetails).includes(el)); + if (messageDetailsMissing) { throw new NotFoundException("Email action is not configured correctly."); } } @@ -53,23 +70,34 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); - // const mailService: Transporter = createTransport(this.mailerDetails.mailer); - const toTemplate: TemplateDelegate = compile(this.mailerDetails.to); - const subjectTemplate: TemplateDelegate = compile(this.mailerDetails.subject); - const bodyTemplate: TemplateDelegate = compile(this.mailerDetails.bodyTemplate); + const mailerConfig = configuration().smtp; + + const mailService: Transporter = createTransport({ + host: mailerConfig.host, + port: mailerConfig.port, + secure: mailerConfig.secure, + auth: { + user: this.messageDetails.from, + pass: this.messageDetails.password + } + } as any); + const toTemplate: TemplateDelegate = compile(this.messageDetails.to); + const subjectTemplate: TemplateDelegate = compile(this.messageDetails.subject); + + const templateFile = readFileSync(this.messageDetails.bodyTemplate, "utf8"); + const bodyTemplate: TemplateDelegate = compile(templateFile); // Fill templates const mail: any = { - to: toTemplate(job), - from: this.mailerDetails.from, - subject: subjectTemplate(job), + to: toTemplate(job, jobTemplateOptions), + from: this.messageDetails.from, + subject: subjectTemplate(job, jobTemplateOptions), }; if (bodyTemplate) { - mail.text = bodyTemplate(job); + mail.text = bodyTemplate(job, jobTemplateOptions); } - Logger.log(mail); - - // await mailService.sendMail(mail); + // Send the email + await mailService.sendMail(mail); } } diff --git a/src/jobs/config/jobConfig.example.json b/src/jobs/config/jobConfig.example.json index f776b9759..d82e9cf4a 100644 --- a/src/jobs/config/jobConfig.example.json +++ b/src/jobs/config/jobConfig.example.json @@ -28,11 +28,11 @@ }, { "actionType": "email", - "mailer": "smtp", - "to": "{{job.contactEmail}}", - "from": "someone", - "subject": "[SciCat] Your {{job.type}} job was submitted successfully", - "bodyTemplate": "some-file" + "to": "{{contactEmail}}", + "from": "", + "password": "", + "subject": "[SciCat] Your {{type}} job was submitted successfully", + "bodyTemplate": "src/common/email-templates/job-template-simplified.html" } ] }, diff --git a/src/jobs/schemas/job.schema.mapping.json b/src/jobs/schemas/job.schema.mapping.json new file mode 100644 index 000000000..482e7c80a --- /dev/null +++ b/src/jobs/schemas/job.schema.mapping.json @@ -0,0 +1,30 @@ +{ + "id": "id", + "emailJobInitiator": "contactEmail", + "type": "type", + "creationTime": "DateTime", + "jobParams": "jobParams", + "jobStatusMessage": "statusCode", + "datasetList": { + "source": "jobParams.datasetIds", + "value": { + "pid": "", + "files": [] + } + }, + "createdBy": "createdBy", + "createdAt": "DateTime", + "updatedAt": "DateTime", + + + + "updatedBy": "updatedBy", + "ownerGroup": "ownerGroup", + "accessGroups": "accessGroups", + "isPublished": "isPublished", + "ownerUser": "ownerUser", + "statusMessage": "statusMessage", + "datasetsValidation": "datasetsValidation", + "configuration": "configuration" +} + From 9be1316e94f83086348633e8f7481c75b905ec32 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Thu, 8 Aug 2024 17:23:19 +0200 Subject: [PATCH 03/12] fix email templating --- .../job-template-simplified.html | 100 +++++++++--------- src/jobs/actions/emailaction.ts | 41 ++++--- src/jobs/config/jobConfig.example.json | 4 +- src/jobs/jobs.controller.ts | 4 + 4 files changed, 74 insertions(+), 75 deletions(-) diff --git a/src/common/email-templates/job-template-simplified.html b/src/common/email-templates/job-template-simplified.html index 50989b065..b80251ab5 100644 --- a/src/common/email-templates/job-template-simplified.html +++ b/src/common/email-templates/job-template-simplified.html @@ -1,61 +1,55 @@ @@ -63,8 +57,10 @@
Your {{type}} job has been submitted and will be processed as soon as possible.
- You will be notified by email as soon as the job is completed.
- Job id: {{id}} + You will be notified by email as soon as the job is completed. +
+
+ Job id: {{id}}
{{#if jobParams.datasetIds}}

Job will be perfomed on the following dataset(s):

@@ -81,8 +77,8 @@
diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index a278f9eb3..472fd1e65 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -21,11 +21,11 @@ const jobTemplateOptions = { statusMessage: true, createdBy: true, jobParams: true, + contactEmail: true, }, allowProtoPropertiesByDefault: false, // limit accessible fields for security }; - type MailOptions = { to: string; from: string; @@ -56,9 +56,6 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); - if (!data["mailer"]) { - throw new NotFoundException("Param 'mailer' is undefined"); - } if (!data["to"]) { throw new NotFoundException("Param 'to' is undefined"); } @@ -77,29 +74,30 @@ export class EmailJobAction implements JobAction { if (!data["subject"]) { throw new NotFoundException("Param 'subject' is undefined"); } - if (!data["body"]) { - throw new NotFoundException("Param 'body' is undefined"); + if (!data["bodyTemplate"]) { + throw new NotFoundException("Param 'bodyTemplate' is undefined"); } Logger.log("EmailJobAction parameters are valid.", "EmailJobAction"); - const mailerConfig = configuration().smtp; - this.mailService = createTransport({ - host: mailerConfig.host, - port: mailerConfig.port, - secure: mailerConfig.secure, - auth: { - user: this.from, - pass: this.password - } - } as any); - - this.toTemplate = compile(data["to"]); this.from = data["from"]; this.password = data["password"]; + + // const mailerConfig = configuration().smtp; + // this.mailService = createTransport({ + // host: mailerConfig.host, + // port: mailerConfig.port, + // secure: mailerConfig.secure, + // auth: { + // user: this.from, + // pass: this.password + // } + // } as any); + + this.toTemplate = compile(data["to"]); this.subjectTemplate = compile(data["subject"]); - const templateFile = readFileSync(data["body"] as string, "utf8"); + const templateFile = readFileSync(data["bodyTemplate"] as string, "utf8"); this.bodyTemplate = compile(templateFile); } @@ -108,7 +106,7 @@ export class EmailJobAction implements JobAction { "Performing EmailJobAction: " + JSON.stringify(job), "EmailJobAction", ); - + // Fill templates const mail: MailOptions = { to: this.toTemplate(job, jobTemplateOptions), @@ -116,8 +114,9 @@ export class EmailJobAction implements JobAction { subject: this.subjectTemplate(job, jobTemplateOptions), }; mail.text = this.bodyTemplate(job, jobTemplateOptions); + Logger.log(mail); // Send the email - await this.mailService.sendMail(mail); + // await this.mailService.sendMail(mail); } } diff --git a/src/jobs/config/jobConfig.example.json b/src/jobs/config/jobConfig.example.json index d82e9cf4a..350260408 100644 --- a/src/jobs/config/jobConfig.example.json +++ b/src/jobs/config/jobConfig.example.json @@ -29,8 +29,8 @@ { "actionType": "email", "to": "{{contactEmail}}", - "from": "", - "password": "", + "from": "from", + "password": "password", "subject": "[SciCat] Your {{type}} job was submitted successfully", "bodyTemplate": "src/common/email-templates/job-template-simplified.html" } diff --git a/src/jobs/jobs.controller.ts b/src/jobs/jobs.controller.ts index fb97fbca3..471d8ec94 100644 --- a/src/jobs/jobs.controller.ts +++ b/src/jobs/jobs.controller.ts @@ -401,6 +401,10 @@ export class JobsController { let datasetIds: string[] = []; if (JobsConfigSchema.DatasetIds in jobCreateDto.jobParams) { datasetIds = await this.checkDatasetIds(jobCreateDto.jobParams); + jobInstance.jobParams = { + ...jobInstance.jobParams, + [JobsConfigSchema.DatasetIds]: datasetIds, + }; } if (user) { // the request comes from a user who is logged in. From b9bd9ab1c4436bde7464b28b25a4efa55ed39d0a Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Thu, 8 Aug 2024 17:33:34 +0200 Subject: [PATCH 04/12] fix linting --- src/jobs/actions/emailaction.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index 472fd1e65..b3986d1b9 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -11,7 +11,6 @@ import { JobAction } from "../config/jobconfig"; import { JobClass } from "../schemas/job.schema"; import configuration from "src/config/configuration"; - // Handlebar options for JobClass templates const jobTemplateOptions = { allowedProtoProperties: { @@ -106,7 +105,7 @@ export class EmailJobAction implements JobAction { "Performing EmailJobAction: " + JSON.stringify(job), "EmailJobAction", ); - + // Fill templates const mail: MailOptions = { to: this.toTemplate(job, jobTemplateOptions), From 32c871249bb670ecf620416a137fe9432be02dc6 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Sat, 10 Aug 2024 01:05:35 +0200 Subject: [PATCH 05/12] remove unnecessary file --- src/jobs/schemas/job.schema.mapping.json | 30 ------------------------ 1 file changed, 30 deletions(-) delete mode 100644 src/jobs/schemas/job.schema.mapping.json diff --git a/src/jobs/schemas/job.schema.mapping.json b/src/jobs/schemas/job.schema.mapping.json deleted file mode 100644 index 482e7c80a..000000000 --- a/src/jobs/schemas/job.schema.mapping.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "id": "id", - "emailJobInitiator": "contactEmail", - "type": "type", - "creationTime": "DateTime", - "jobParams": "jobParams", - "jobStatusMessage": "statusCode", - "datasetList": { - "source": "jobParams.datasetIds", - "value": { - "pid": "", - "files": [] - } - }, - "createdBy": "createdBy", - "createdAt": "DateTime", - "updatedAt": "DateTime", - - - - "updatedBy": "updatedBy", - "ownerGroup": "ownerGroup", - "accessGroups": "accessGroups", - "isPublished": "isPublished", - "ownerUser": "ownerUser", - "statusMessage": "statusMessage", - "datasetsValidation": "datasetsValidation", - "configuration": "configuration" -} - From 64c897195a5d3cd1b967dca4bdcc9a94870d3c77 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Thu, 5 Sep 2024 13:18:40 +0200 Subject: [PATCH 06/12] add optional auth field --- src/jobs/actions/emailaction.ts | 36 +++++++++++++------------- src/jobs/config/jobConfig.example.json | 5 +++- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index b3986d1b9..0e77128f2 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -32,6 +32,11 @@ type MailOptions = { text?: string; }; +type Auth = { + user: string; + password: string; +}; + /** * Send an email following a job */ @@ -41,7 +46,7 @@ export class EmailJobAction implements JobAction { private mailService: Transporter; private toTemplate: TemplateDelegate; private from: string; - private password: string; + private auth: Auth | Object = {}; private subjectTemplate: TemplateDelegate; private bodyTemplate: TemplateDelegate; @@ -55,44 +60,39 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); + if (data["auth"]) { // check optional auth field + function CheckAuthDefinition(obj: any): obj is Auth { + return Object.keys(obj).length == 2 && "user" in obj && "password" in obj; + } + + if (!CheckAuthDefinition(data["auth"])) { + throw new NotFoundException("Param 'auth' should contain fields 'user' and 'password' only."); + } + this.auth = data["auth"] as Auth; + } if (!data["to"]) { throw new NotFoundException("Param 'to' is undefined"); } if (!data["from"]) { throw new NotFoundException("Param 'from' is undefined"); } - if (typeof data["from"] !== "string") { - throw new TypeError("Param 'from' should be a string"); - } - if (!data["password"]) { - throw new NotFoundException("Param 'from' is undefined"); - } - if (typeof data["password"] !== "string") { - throw new TypeError("Param 'password' should be a string"); - } if (!data["subject"]) { throw new NotFoundException("Param 'subject' is undefined"); } if (!data["bodyTemplate"]) { throw new NotFoundException("Param 'bodyTemplate' is undefined"); } - Logger.log("EmailJobAction parameters are valid.", "EmailJobAction"); - this.from = data["from"]; - this.password = data["password"]; - // const mailerConfig = configuration().smtp; // this.mailService = createTransport({ // host: mailerConfig.host, // port: mailerConfig.port, // secure: mailerConfig.secure, - // auth: { - // user: this.from, - // pass: this.password - // } + // auth: this.auth // } as any); + this.from = data["from"] as string; this.toTemplate = compile(data["to"]); this.subjectTemplate = compile(data["subject"]); diff --git a/src/jobs/config/jobConfig.example.json b/src/jobs/config/jobConfig.example.json index 350260408..3f0157064 100644 --- a/src/jobs/config/jobConfig.example.json +++ b/src/jobs/config/jobConfig.example.json @@ -28,9 +28,12 @@ }, { "actionType": "email", + "auth": { + "user": "user", + "password": "password" + }, "to": "{{contactEmail}}", "from": "from", - "password": "password", "subject": "[SciCat] Your {{type}} job was submitted successfully", "bodyTemplate": "src/common/email-templates/job-template-simplified.html" } From 11c9ae2978fbcb53778775ae5bd012fd9eb4923d Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou <16343312+despadam@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:26:54 +0200 Subject: [PATCH 07/12] fix linting --- src/jobs/actions/emailaction.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index 0e77128f2..c56d77cff 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -60,13 +60,18 @@ export class EmailJobAction implements JobAction { "EmailJobAction", ); - if (data["auth"]) { // check optional auth field - function CheckAuthDefinition(obj: any): obj is Auth { - return Object.keys(obj).length == 2 && "user" in obj && "password" in obj; + if (data["auth"]) { + // check optional auth field + function CheckAuthDefinition(obj: Object): obj is Auth { + return ( + Object.keys(obj).length == 2 && "user" in obj && "password" in obj; + ) } if (!CheckAuthDefinition(data["auth"])) { - throw new NotFoundException("Param 'auth' should contain fields 'user' and 'password' only."); + throw new NotFoundException( + "Param 'auth' should contain fields 'user' and 'password' only." + ); } this.auth = data["auth"] as Auth; } From d2e058649db09494513e8e64c72a14723d48a1b3 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou <16343312+despadam@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:28:42 +0200 Subject: [PATCH 08/12] fix typo --- src/jobs/actions/emailaction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index c56d77cff..b63abe084 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -64,8 +64,8 @@ export class EmailJobAction implements JobAction { // check optional auth field function CheckAuthDefinition(obj: Object): obj is Auth { return ( - Object.keys(obj).length == 2 && "user" in obj && "password" in obj; - ) + Object.keys(obj).length == 2 && "user" in obj && "password" in obj + ); } if (!CheckAuthDefinition(data["auth"])) { From b8e0f2a8da0d0b46ae0d939c9da39ea83b7839b2 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou <16343312+despadam@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:31:35 +0200 Subject: [PATCH 09/12] fix lint error --- src/jobs/actions/emailaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index b63abe084..c247a8c89 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -70,7 +70,7 @@ export class EmailJobAction implements JobAction { if (!CheckAuthDefinition(data["auth"])) { throw new NotFoundException( - "Param 'auth' should contain fields 'user' and 'password' only." + "Param 'auth' should contain fields 'user' and 'password' only.", ); } this.auth = data["auth"] as Auth; From 90c495eca9901125c5032e6830e05a9b6c2b4285 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou <16343312+despadam@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:34:20 +0200 Subject: [PATCH 10/12] fix lint errors --- src/jobs/actions/emailaction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index c247a8c89..e8a1bee6e 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -46,7 +46,7 @@ export class EmailJobAction implements JobAction { private mailService: Transporter; private toTemplate: TemplateDelegate; private from: string; - private auth: Auth | Object = {}; + private auth: Auth | object = {}; private subjectTemplate: TemplateDelegate; private bodyTemplate: TemplateDelegate; @@ -62,7 +62,7 @@ export class EmailJobAction implements JobAction { if (data["auth"]) { // check optional auth field - function CheckAuthDefinition(obj: Object): obj is Auth { + function CheckAuthDefinition(obj: object): obj is Auth { return ( Object.keys(obj).length == 2 && "user" in obj && "password" in obj ); From 3a75dde9760ed89eb5584d8abffc6913bc24ad9d Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Mon, 9 Sep 2024 12:37:13 +0200 Subject: [PATCH 11/12] rename field to bodyTemplateFile --- src/jobs/actions/emailaction.ts | 6 +++--- src/jobs/config/jobConfig.example.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index e8a1bee6e..7932ebc4a 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -84,8 +84,8 @@ export class EmailJobAction implements JobAction { if (!data["subject"]) { throw new NotFoundException("Param 'subject' is undefined"); } - if (!data["bodyTemplate"]) { - throw new NotFoundException("Param 'bodyTemplate' is undefined"); + if (!data["bodyTemplateFile"]) { + throw new NotFoundException("Param 'bodyTemplateFile' is undefined"); } Logger.log("EmailJobAction parameters are valid.", "EmailJobAction"); @@ -101,7 +101,7 @@ export class EmailJobAction implements JobAction { this.toTemplate = compile(data["to"]); this.subjectTemplate = compile(data["subject"]); - const templateFile = readFileSync(data["bodyTemplate"] as string, "utf8"); + const templateFile = readFileSync(data["bodyTemplateFile"] as string, "utf8"); this.bodyTemplate = compile(templateFile); } diff --git a/src/jobs/config/jobConfig.example.json b/src/jobs/config/jobConfig.example.json index 3f0157064..fae19537e 100644 --- a/src/jobs/config/jobConfig.example.json +++ b/src/jobs/config/jobConfig.example.json @@ -35,7 +35,7 @@ "to": "{{contactEmail}}", "from": "from", "subject": "[SciCat] Your {{type}} job was submitted successfully", - "bodyTemplate": "src/common/email-templates/job-template-simplified.html" + "bodyTemplateFile": "src/common/email-templates/job-template-simplified.html" } ] }, From fb07deaa8d1e4dce448ded100376ebdc36910070 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Mon, 9 Sep 2024 12:41:49 +0200 Subject: [PATCH 12/12] fix lint error --- src/jobs/actions/emailaction.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/jobs/actions/emailaction.ts b/src/jobs/actions/emailaction.ts index 7932ebc4a..6ac6fa8f7 100644 --- a/src/jobs/actions/emailaction.ts +++ b/src/jobs/actions/emailaction.ts @@ -101,7 +101,10 @@ export class EmailJobAction implements JobAction { this.toTemplate = compile(data["to"]); this.subjectTemplate = compile(data["subject"]); - const templateFile = readFileSync(data["bodyTemplateFile"] as string, "utf8"); + const templateFile = readFileSync( + data["bodyTemplateFile"] as string, + "utf8", + ); this.bodyTemplate = compile(templateFile); }