Add "Send Test Message" functionality to settings.
This commit is contained in:
parent
9964d6dc32
commit
d4c48003de
|
@ -84,6 +84,11 @@ return static function (RouteCollectorProxy $group) {
|
|||
Controller\Api\Admin\SettingsController::class . ':updateAction'
|
||||
);
|
||||
|
||||
$group->post(
|
||||
'/send-test-message',
|
||||
Controller\Api\Admin\SendTestMessageAction::class
|
||||
)->setName('api:admin:send-test-message');
|
||||
|
||||
$group->get(
|
||||
'/custom_assets/{type}',
|
||||
Controller\Api\Admin\CustomAssets\GetCustomAssetAction::class
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
<settings-security-privacy-tab :form="$v.form"
|
||||
:tab-class="getTabClass($v.securityPrivacyTab)"></settings-security-privacy-tab>
|
||||
<settings-services-tab :form="$v.form" :tab-class="getTabClass($v.servicesTab)"
|
||||
:release-channel="releaseChannel"></settings-services-tab>
|
||||
:release-channel="releaseChannel"
|
||||
:test-message-url="testMessageUrl"></settings-services-tab>
|
||||
</b-tabs>
|
||||
</b-overlay>
|
||||
|
||||
|
@ -50,6 +51,7 @@ export default {
|
|||
emits: ['saved'],
|
||||
props: {
|
||||
apiUrl: String,
|
||||
testMessageUrl: String,
|
||||
releaseChannel: {
|
||||
type: String,
|
||||
default: 'rolling',
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</b-wrapped-form-checkbox>
|
||||
</b-form-row>
|
||||
|
||||
<b-form-row v-if="form.mail_enabled.$model">
|
||||
<b-form-row v-if="form.mail_enabled.$model" class="mt-2">
|
||||
<b-wrapped-form-group class="col-md-6" id="edit_form_mail_sender_name"
|
||||
:field="form.mail_sender_name">
|
||||
<template #label="{lang}">
|
||||
|
@ -104,6 +104,16 @@
|
|||
<translate :key="lang">SMTP Password</translate>
|
||||
</template>
|
||||
</b-wrapped-form-group>
|
||||
|
||||
<div class="form-group col">
|
||||
<b-button size="sm" variant="primary" :disabled="form.$anyDirty" v-b-modal.send_test_message>
|
||||
<icon icon="send"></icon>
|
||||
<translate key="lang_btn_test_message">Send Test Message</translate>
|
||||
<span v-if="form.$anyDirty">
|
||||
(<translate key="lang_btn_test_message_save_changes">Save Changes first</translate>)
|
||||
</span>
|
||||
</b-button>
|
||||
</div>
|
||||
</b-form-row>
|
||||
</b-form-fieldset>
|
||||
|
||||
|
@ -166,6 +176,8 @@
|
|||
</b-wrapped-form-group>
|
||||
</b-form-row>
|
||||
</b-form-fieldset>
|
||||
|
||||
<admin-settings-test-message-modal :test-message-url="testMessageUrl"></admin-settings-test-message-modal>
|
||||
</b-tab>
|
||||
</template>
|
||||
|
||||
|
@ -174,14 +186,20 @@ import BFormMarkup from "~/components/Form/BFormMarkup";
|
|||
import BWrappedFormGroup from "~/components/Form/BWrappedFormGroup";
|
||||
import BFormFieldset from "~/components/Form/BFormFieldset";
|
||||
import BWrappedFormCheckbox from "~/components/Form/BWrappedFormCheckbox";
|
||||
import AdminSettingsTestMessageModal from "~/components/Admin/Settings/TestMessageModal";
|
||||
import Icon from "~/components/Common/Icon";
|
||||
|
||||
export default {
|
||||
name: 'SettingsServicesTab',
|
||||
components: {BWrappedFormCheckbox, BFormFieldset, BWrappedFormGroup, BFormMarkup},
|
||||
components: {
|
||||
Icon,
|
||||
AdminSettingsTestMessageModal, BWrappedFormCheckbox, BFormFieldset, BWrappedFormGroup, BFormMarkup
|
||||
},
|
||||
props: {
|
||||
form: Object,
|
||||
tabClass: {},
|
||||
releaseChannel: String,
|
||||
testMessageUrl: String,
|
||||
},
|
||||
computed: {
|
||||
langTabTitle() {
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<template>
|
||||
<b-modal id="send_test_message" centered ref="modal" :title="langTitle">
|
||||
<b-form @submit.prevent="doSendTest">
|
||||
<b-wrapped-form-group id="email_address" :field="$v.emailAddress" autofocus>
|
||||
<template #label="{lang}">
|
||||
<translate :key="lang">E-mail Address</translate>
|
||||
</template>
|
||||
</b-wrapped-form-group>
|
||||
</b-form>
|
||||
<template #modal-footer>
|
||||
<b-button variant="default" @click="close">
|
||||
<translate key="lang_btn_close">Close</translate>
|
||||
</b-button>
|
||||
<b-button :variant="($v.$invalid) ? 'danger' : 'primary'" @click="doSendTest">
|
||||
<translate key="lang_btn_send">Send Test Message</translate>
|
||||
</b-button>
|
||||
</template>
|
||||
</b-modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BWrappedFormGroup from "~/components/Form/BWrappedFormGroup";
|
||||
import {validationMixin} from "vuelidate";
|
||||
import {email, required} from 'vuelidate/dist/validators.min.js';
|
||||
|
||||
export default {
|
||||
name: 'AdminSettingsTestMessageModal',
|
||||
components: {BWrappedFormGroup},
|
||||
mixins: [validationMixin],
|
||||
props: {
|
||||
testMessageUrl: String
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
emailAddress: null
|
||||
};
|
||||
},
|
||||
validations: {
|
||||
emailAddress: {required, email}
|
||||
},
|
||||
computed: {
|
||||
langTitle() {
|
||||
return this.$gettext('Send Test Message');
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
close() {
|
||||
this.emailAddress = null;
|
||||
this.$v.$reset();
|
||||
this.$refs.modal.hide();
|
||||
},
|
||||
doSendTest() {
|
||||
this.$v.$touch();
|
||||
if (this.$v.$anyError) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.$wrapWithLoading(
|
||||
this.axios.post(this.testMessageUrl, {
|
||||
'email': this.emailAddress
|
||||
})
|
||||
).then(() => {
|
||||
this.$notifySuccess(this.$gettext('Test message sent.'));
|
||||
}).finally(() => {
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -25,9 +25,10 @@ class SettingsAction
|
|||
id: 'admin-settings',
|
||||
title: __('System Settings'),
|
||||
props: [
|
||||
'apiUrl' => (string)$router->named('api:admin:settings', [
|
||||
'apiUrl' => (string)$router->named('api:admin:settings', [
|
||||
'group' => Settings::GROUP_GENERAL,
|
||||
]),
|
||||
'testMessageUrl' => (string)$router->named('api:admin:send-test-message'),
|
||||
'releaseChannel' => $version->getReleaseChannelEnum()->value,
|
||||
],
|
||||
);
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Api\Admin;
|
||||
|
||||
use App\Entity;
|
||||
use App\Exception\ValidationException;
|
||||
use App\Http\Response;
|
||||
use App\Http\ServerRequest;
|
||||
use App\Service\Mail;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Symfony\Component\Mailer\Exception\TransportException;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\Required;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class SendTestMessageAction
|
||||
{
|
||||
public function __invoke(
|
||||
ServerRequest $request,
|
||||
Response $response,
|
||||
ValidatorInterface $validator,
|
||||
Mail $mail
|
||||
): ResponseInterface {
|
||||
$emailAddress = $request->getParam('email', '');
|
||||
|
||||
$errors = $validator->validate(
|
||||
$emailAddress,
|
||||
[
|
||||
new Required(),
|
||||
new Email(),
|
||||
]
|
||||
);
|
||||
if (count($errors) > 0) {
|
||||
throw ValidationException::fromValidationErrors($errors);
|
||||
}
|
||||
|
||||
try {
|
||||
$email = $mail->createMessage();
|
||||
$email->to($emailAddress);
|
||||
$email->subject(
|
||||
__('Test Message')
|
||||
);
|
||||
$email->text(
|
||||
__(
|
||||
'This is a test message from AzuraCast. If you are receiving this message, it means your '
|
||||
. 'e-mail settings are configured correctly.'
|
||||
)
|
||||
);
|
||||
|
||||
$mail->send($email);
|
||||
} catch (TransportException $e) {
|
||||
return $response->withStatus(400)->withJson(Entity\Api\Error::fromException($e));
|
||||
}
|
||||
|
||||
return $response->withJson(
|
||||
new Entity\Api\Status(
|
||||
true,
|
||||
__('Test message sent successfully.')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue