Add Mailgun region setting

Fixes #1834.
This commit is contained in:
Vladimir Vinogradov 2020-01-10 18:16:23 +01:00 committed by Daniël Klabbers
parent 63801484fa
commit 0560238945
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( for (const driver in this.driverFields) {
key => { for (const field in this.driverFields[driver]) {
this.fields.push(key); this.fields.push(field);
this.values[key] = m.prop(settings[key]); this.values[field] = m.prop(settings[field]);
} }
); }
this.loading = false; this.loading = false;
m.redraw(); m.redraw();
}); });
@ -87,9 +88,9 @@ export default class MailPage extends Page {
className: 'MailPage-MailSettings', className: 'MailPage-MailSettings',
children: [ children: [
<div className="MailPage-MailSettings-input"> <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>, <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> </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() { changed() {
return this.fields.some(key => this.values[key]() !== app.data.settings[key]); 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 public function availableSettings(): array
{ {
return [ return [
'mail_mailgun_secret', // the secret key 'mail_mailgun_secret' => '', // the secret key
'mail_mailgun_domain', // the API base URL '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( return new MailgunTransport(
new Client(['connect_timeout' => 60]), new Client(['connect_timeout' => 60]),
$settings->get('mail_mailgun_secret'), $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 public function availableSettings(): array
{ {
return [ return [
'mail_mandrill_secret', 'mail_mandrill_secret' => '',
]; ];
} }

View File

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

View File

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