Add Mailgun region setting

Fixes #1834.
This commit is contained in:
Vladimir Vinogradov 2020-01-10 18:16:23 +01:00 committed by Franz Liedke
parent eb9ee85b9d
commit 7ca7150b37
5 changed files with 37 additions and 19 deletions

View File

@ -29,12 +29,13 @@ export default class MailPage extends Page {
{}
);
Object.keys(this.driverFields).flatMap(key => this.driverFields[key]).forEach(
key => {
this.fields.push(key);
this.values[key] = m.prop(settings[key]);
for (const driver in this.driverFields) {
for (const field in this.driverFields[driver]) {
this.fields.push(field);
this.values[field] = m.prop(settings[field]);
}
);
}
this.loading = false;
m.redraw();
});
@ -87,9 +88,9 @@ export default class MailPage extends Page {
className: 'MailPage-MailSettings',
children: [
<div className="MailPage-MailSettings-input">
{this.driverFields[this.values.mail_driver()].flatMap(field => [
{Object.keys(this.driverFields[this.values.mail_driver()]).map(field => [
<label>{app.translator.trans(`core.admin.email.${field}_label`)}</label>,
<input className="FormControl" value={this.values[field]() || ''} oninput={m.withAttr('value', this.values[field])} />
this.renderField(field),
])}
</div>
]
@ -108,6 +109,18 @@ export default class MailPage extends Page {
);
}
renderField(name) {
const driver = this.values.mail_driver();
const field = this.driverFields[driver][name];
const prop = this.values[name];
if (typeof field === 'string') {
return <input className="FormControl" value={prop() || ''} oninput={m.withAttr('value', prop)}/>;
} else {
return <Select value={prop()} options={field} onchange={prop} />;
}
}
changed() {
return this.fields.some(key => this.values[key]() !== app.data.settings[key]);
}

View File

@ -19,8 +19,12 @@ class MailgunDriver implements DriverInterface
public function availableSettings(): array
{
return [
'mail_mailgun_secret', // the secret key
'mail_mailgun_domain', // the API base URL
'mail_mailgun_secret' => '', // the secret key
'mail_mailgun_domain' => '', // the API base URL
'mail_mailgun_region' => [ // region's endpoint
'api.mailgun.net' => 'US',
'api.eu.mailgun.net' => 'EU',
],
];
}
@ -29,7 +33,8 @@ class MailgunDriver implements DriverInterface
return new MailgunTransport(
new Client(['connect_timeout' => 60]),
$settings->get('mail_mailgun_secret'),
$settings->get('mail_mailgun_domain')
$settings->get('mail_mailgun_domain'),
$settings->get('mail_mailgun_region')
);
}
}

View File

@ -19,7 +19,7 @@ class MandrillDriver implements DriverInterface
public function availableSettings(): array
{
return [
'mail_mandrill_secret',
'mail_mandrill_secret' => '',
];
}

View File

@ -19,9 +19,9 @@ class SesDriver implements DriverInterface
public function availableSettings(): array
{
return [
'mail_ses_key',
'mail_ses_secret',
'mail_ses_region',
'mail_ses_key' => '',
'mail_ses_secret' => '',
'mail_ses_region' => '',
];
}

View File

@ -18,11 +18,11 @@ class SmtpDriver implements DriverInterface
public function availableSettings(): array
{
return [
'mail_host', // a hostname, IPv4 address or IPv6 wrapped in []
'mail_port', // a number, defaults to 25
'mail_encryption', // "tls" or "ssl"
'mail_username', // required
'mail_password', // required
'mail_host' => '', // a hostname, IPv4 address or IPv6 wrapped in []
'mail_port' => '', // a number, defaults to 25
'mail_encryption' => '', // "tls" or "ssl"
'mail_username' => '', // required
'mail_password' => '', // required
];
}