From ffdee7d1f626a80b09d8b24408a2a520cb9262bb Mon Sep 17 00:00:00 2001
From: FORESTIER Fabien <fabien.forestier@soprasteria.com>
Date: Thu, 2 May 2019 10:59:02 +0200
Subject: [PATCH] Add var env to be able to send the feedback to many email
 address

---
 .gitlab-ci.yml                      | 1 +
 docker-compose.yml                  | 1 +
 package.json                        | 4 ++--
 src/configuration/config.service.ts | 1 +
 src/configuration/config.ts         | 1 +
 src/configuration/template.env      | 5 ++++-
 src/email/email.service.ts          | 5 +++++
 swagger-spec.json                   | 2 +-
 8 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8ac72ce..7eb4a64 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,6 +4,7 @@ stages:
 
 variables:
   USER_SUPPORT_MAILBOX: alpha-test@erasme.org
+  ADDITIONAL_FEEDBACK_EMAILS: fabien.forestier@soprasteria.com,castejon.nicolas@gmail.com,florent.dufier@gmail.com
 
 build_development:
   stage: build
diff --git a/docker-compose.yml b/docker-compose.yml
index 978d069..eae8767 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -15,6 +15,7 @@ services:
       - EMAIL_WRITER_GROUP_NAME=email-writer
       - MAIL_SUBJECT_PREFIX=${MAIL_SUBJECT_PREFIX}
       - NO_REPLY_MAIL_ADDRESS=${NO_REPLY_MAIL_ADDRESS}
+      - ADDITIONAL_FEEDBACK_EMAILS=${ADDITIONAL_FEEDBACK_EMAILS}
     restart: unless-stopped
 
   rabbitmq:
diff --git a/package.json b/package.json
index 64c37b4..8053cc6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "service-email",
-  "version": "1.1.1",
+  "version": "1.1.2",
   "description": "description",
   "author": "",
   "license": "MIT",
@@ -68,4 +68,4 @@
     "coverageDirectory": "../coverage",
     "testEnvironment": "node"
   }
-}
+}
\ No newline at end of file
diff --git a/src/configuration/config.service.ts b/src/configuration/config.service.ts
index 80c8f4b..193cb34 100644
--- a/src/configuration/config.service.ts
+++ b/src/configuration/config.service.ts
@@ -25,6 +25,7 @@ export class ConfigService {
     this._config.groupHeader = process.env.GROUP_HEADER;
     this._config.mailSubjectPrefix = process.env.MAIL_SUBJECT_PREFIX;
     this._config.noReplyMailAddress = process.env.NO_REPLY_MAIL_ADDRESS;
+    this._config.additionalFeedbackEmails = process.env.ADDITIONAL_FEEDBACK_EMAILS;
   }
 
   get config() {
diff --git a/src/configuration/config.ts b/src/configuration/config.ts
index b842d19..7f1ddb7 100644
--- a/src/configuration/config.ts
+++ b/src/configuration/config.ts
@@ -14,4 +14,5 @@ export const config = {
   groupHeader: '',
   mailSubjectPrefix: '',
   noReplyMailAddress: '',
+  additionalFeedbackEmails: '',
 };
\ No newline at end of file
diff --git a/src/configuration/template.env b/src/configuration/template.env
index 06f4d17..ae1b2eb 100644
--- a/src/configuration/template.env
+++ b/src/configuration/template.env
@@ -2,4 +2,7 @@ RABBITMQ_USER=
 RABBITMQ_PASSWORD=
 USER_SUPPORT_MAILBOX=
 MAIL_SUBJECT_PREFIX=
-NO_REPLY_MAIL_ADDRESS=
\ No newline at end of file
+NO_REPLY_MAIL_ADDRESS=
+ADDITIONAL_FEEDBACK_EMAILS=
+GROUP_HEADER=
+EMAIL_WRITER_GROUP_NAME=
\ No newline at end of file
diff --git a/src/email/email.service.ts b/src/email/email.service.ts
index 26b4bbe..e78709f 100644
--- a/src/email/email.service.ts
+++ b/src/email/email.service.ts
@@ -76,6 +76,11 @@ export class EmailService {
     });
     const feedbackEmail = new EmailWithoutFrom();
     feedbackEmail.to = [this.config.userSupportMailbox];
+
+    if (this.config.additionalFeedbackEmails) {
+      feedbackEmail.to = feedbackEmail.to.concat(this.config.additionalFeedbackEmails.split(','));
+    }
+
     feedbackEmail.subject = 'Feedback';
     feedbackEmail.html = feedbackEmailBody;
 
diff --git a/swagger-spec.json b/swagger-spec.json
index c3eeaa5..c47056c 100644
--- a/swagger-spec.json
+++ b/swagger-spec.json
@@ -1 +1 @@
-{"swagger":"2.0","info":{"description":"Service providing the method to send emails.","version":"0.1","title":"Email service API"},"basePath":"/","tags":[{"name":"email","description":""}],"schemes":["http"],"paths":{"/email/contact":{"post":{"summary":"Send email to admin (emails defined as var env of the project, see docker-compose.yml file) and recap email to user email.","parameters":[{"name":"ContactForm","required":true,"in":"body","schema":{"$ref":"#/definitions/ContactForm"}}],"responses":{"200":{"description":"OK"},"400":{"description":"Missing fields"},"500":{"description":"Internal error, this is probably a rabbitMQ related error (unreachable service...)"}},"tags":["email"],"produces":["application/json"],"consumes":["application/json"]}},"/email/feedback":{"post":{"summary":"Send email to admin with the user feedback","parameters":[{"name":"FeedbackForm","required":true,"in":"body","schema":{"$ref":"#/definitions/FeedbackForm"}}],"responses":{"200":{"description":"OK"},"400":{"description":"Missing fields"},"500":{"description":"Internal error, this is probably a rabbitMQ related error (unreachable service...)"}},"tags":["email"],"produces":["application/json"],"consumes":["application/json"]}},"/email/send":{"post":{"summary":"Send email.","parameters":[{"name":"EmailWithoutFrom","required":true,"in":"body","schema":{"$ref":"#/definitions/EmailWithoutFrom"}}],"responses":{"200":{"description":"OK"},"400":{"description":"Missing fields"},"500":{"description":"Internal error, this is probably a rabbitMQ related error (unreachable service...)"}},"tags":["email"],"produces":["application/json"],"consumes":["application/json"]}}},"definitions":{"ContactForm":{"type":"object","properties":{"email":{"type":"string"},"subject":{"type":"string"},"firstname":{"type":"string"},"lastname":{"type":"string"},"text":{"type":"string"}},"required":["email","subject","firstname","lastname","text"]},"FeedbackForm":{"type":"object","properties":{"url":{"type":"string"},"version":{"type":"string"},"message":{"type":"string"}},"required":["url","version","message"]},"EmailWithoutFrom":{"type":"object","properties":{"to":{"type":"array","items":{"type":"string"}},"replyTo":{"type":"string"},"cc":{"type":"array","items":{"type":"string"}},"bcc":{"type":"array","items":{"type":"string"}},"subject":{"type":"string"},"html":{"type":"string"}},"required":["to","subject","html"]}}}
\ No newline at end of file
+{"swagger":"2.0","info":{"description":"Service providing the method to send emails.","version":"0.1","title":"Email service API"},"basePath":"/","tags":[{"name":"email","description":""}],"schemes":["http"],"paths":{"/contact":{"post":{"summary":"Send email to admin (emails defined as var env of the project, see docker-compose.yml file) and recap email to user email.","parameters":[{"name":"ContactForm","required":true,"in":"body","schema":{"$ref":"#/definitions/ContactForm"}}],"responses":{"200":{"description":"OK"},"400":{"description":"Missing fields"},"500":{"description":"Internal error, this is probably a rabbitMQ related error (unreachable service...)"}},"produces":["application/json"],"consumes":["application/json"]}},"/feedback":{"post":{"summary":"Send email to admin with the user feedback","parameters":[{"name":"FeedbackForm","required":true,"in":"body","schema":{"$ref":"#/definitions/FeedbackForm"}}],"responses":{"200":{"description":"OK"},"400":{"description":"Missing fields"},"500":{"description":"Internal error, this is probably a rabbitMQ related error (unreachable service...)"}},"produces":["application/json"],"consumes":["application/json"]}},"/send":{"post":{"summary":"Send email.","parameters":[{"name":"EmailWithoutFrom","required":true,"in":"body","schema":{"$ref":"#/definitions/EmailWithoutFrom"}}],"responses":{"200":{"description":"OK"},"400":{"description":"Missing fields"},"500":{"description":"Internal error, this is probably a rabbitMQ related error (unreachable service...)"}},"produces":["application/json"],"consumes":["application/json"]}}},"definitions":{"ContactForm":{"type":"object","properties":{"email":{"type":"string"},"subject":{"type":"string"},"firstname":{"type":"string"},"lastname":{"type":"string"},"text":{"type":"string"}},"required":["email","subject","firstname","lastname","text"]},"FeedbackForm":{"type":"object","properties":{"url":{"type":"string"},"version":{"type":"string"},"message":{"type":"string"}},"required":["url","version","message"]},"EmailWithoutFrom":{"type":"object","properties":{"to":{"type":"array","items":{"type":"string"}},"replyTo":{"type":"string"},"cc":{"type":"array","items":{"type":"string"}},"bcc":{"type":"array","items":{"type":"string"}},"subject":{"type":"string"},"html":{"type":"string"}},"required":["to","subject","html"]}}}
\ No newline at end of file
-- 
GitLab