Mattias van den Belt 8aaf797a1c
Add email test in plugin settings (#8156)
* Add email test route and controller

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Add email settings page

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Add email Settings Container

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Remove unused getProviderConfig email service

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Add email (disabled) config fields

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email settings config form

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email settings container

Move Test button
Add testEmail input
Update config fields

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email settings form

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email plugin settings

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email plugin docs

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email settings page

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email settings permissions

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update settings container form

* Update mail text
* Fix alignment
* Add yup validation
* Update form submission

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Fix e2e test

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Fix e2e test

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Fix Baseline

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email plugin docs

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update (temp) BaselineAlignment component

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update text and button styles and placement

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email routes and permissions

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email controller and service

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email admin permissions

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update test permissions snapshot

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email admin permissions

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update all test snapshot

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update email settings permissions

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Update test snapshots

* Fix text width

* Update styling, baseline, and docs link

Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
2021-03-05 10:37:33 +01:00

45 lines
1.3 KiB
JavaScript

'use strict';
const _ = require('lodash');
const getProviderSettings = () => {
return strapi.plugins.email.config;
};
const send = async options => {
return strapi.plugins.email.provider.send(options);
};
/**
* fill subject, text and html using lodash template
* @param {object} emailOptions - to, from and replyto...
* @param {object} emailTemplate - object containing attributes to fill
* @param {object} data - data used to fill the template
* @returns {{ subject, text, subject }}
*/
const sendTemplatedEmail = (emailOptions = {}, emailTemplate = {}, data = {}) => {
const attributes = ['subject', 'text', 'html'];
const missingAttributes = _.difference(attributes, Object.keys(emailTemplate));
if (missingAttributes.length > 0) {
throw new Error(
`Following attributes are missing from your email template : ${missingAttributes.join(', ')}`
);
}
const templatedAttributes = attributes.reduce(
(compiled, attribute) =>
emailTemplate[attribute]
? Object.assign(compiled, { [attribute]: _.template(emailTemplate[attribute])(data) })
: compiled,
{}
);
return strapi.plugins.email.provider.send({ ...emailOptions, ...templatedAttributes });
};
module.exports = {
getProviderSettings,
send,
sendTemplatedEmail,
};