Add is_active setting for mailman
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
2189d95da8
commit
c593096bf9
|
@ -3,6 +3,7 @@
|
|||
namespace App\Mailman\Actions;
|
||||
|
||||
use App\Mailman\MailmanSettings;
|
||||
use App\Mailman\Support\MailmanService;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
@ -17,6 +18,7 @@ class SettingIndexAction
|
|||
public function handle(MailmanSettings $settings): array
|
||||
{
|
||||
return [
|
||||
'is_active' => $settings->is_active,
|
||||
'base_url' => $settings->base_url,
|
||||
'username' => $settings->username,
|
||||
'password' => '',
|
||||
|
@ -28,8 +30,13 @@ class SettingIndexAction
|
|||
session()->put('menu', 'setting');
|
||||
session()->put('title', 'Mailman-Einstellungen');
|
||||
|
||||
$state = $settings->base_url && $settings->username && $settings->password && $settings->is_active
|
||||
? app(MailmanService::class)->setCredentials($settings->base_url, $settings->username, $settings->password)->check()
|
||||
: null;
|
||||
|
||||
return Inertia::render('setting/Mailman', [
|
||||
'data' => $this->handle($settings),
|
||||
'state' => $state,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ class SettingSaveAction
|
|||
'base_url' => $input['base_url'] ?? null,
|
||||
'username' => $input['username'] ?? null,
|
||||
'password' => $input['password'] ?? null,
|
||||
'is_active' => $input['is_active'] ?? false,
|
||||
]);
|
||||
|
||||
$settings->save();
|
||||
|
@ -35,15 +36,24 @@ class SettingSaveAction
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'base_url' => 'required',
|
||||
'username' => 'required',
|
||||
'password' => 'required',
|
||||
'base_url' => 'required_if:is_active,true',
|
||||
'username' => 'required_if:is_active,true',
|
||||
'password' => 'required_if:is_active,true',
|
||||
];
|
||||
}
|
||||
|
||||
public function getValidationMessages(): array
|
||||
{
|
||||
return [
|
||||
'base_url.required_if' => 'URL ist erforderlich.',
|
||||
'username.required_if' => 'Benutzername ist erforderlich.',
|
||||
'password.required_if' => 'Passwort ist erforderlich.',
|
||||
];
|
||||
}
|
||||
|
||||
public function afterValidator(Validator $validator, ActionRequest $request): void
|
||||
{
|
||||
if (!$request->filled(['base_url', 'username', 'password'])) {
|
||||
if (false === $request->is_active || !$request->filled(['base_url', 'username', 'password'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ class MailmanSettings extends LocalSettings
|
|||
|
||||
public ?string $password;
|
||||
|
||||
public bool $is_active;
|
||||
|
||||
public static function group(): string
|
||||
{
|
||||
return 'mailman';
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
use Spatie\LaravelSettings\Migrations\SettingsMigration;
|
||||
|
||||
class MailmanIsActive extends SettingsMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->migrator->add('mailman.is_active', false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 167.751 167.751" style="enable-background:new 0 0 167.751 167.751" xml:space="preserve"><path d="M0 83.875c0 46.249 37.626 83.875 83.875 83.875s83.875-37.626 83.875-83.875S130.125 0 83.875 0 0 37.626 0 83.875zm83.875 68.876C45.897 152.751 15 121.854 15 83.875c0-16.292 5.698-31.272 15.191-43.078l96.762 96.762c-11.806 9.493-26.785 15.192-43.078 15.192zm68.875-68.876c0 16.292-5.698 31.272-15.19 43.078L40.797 30.191C52.603 20.698 67.583 15 83.875 15c37.978 0 68.875 30.897 68.875 68.875z"/></svg>
|
After Width: | Height: | Size: 549 B |
|
@ -10,9 +10,16 @@
|
|||
Scoutrobot wird nach der Ersteinrichtung deine Mitglieder zu bestehenden E-Mail-Verteilern hinzufügen.
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<f-switch id="is_active" v-model="inner.is_active" label="Mailman-Synchronisation aktiv"></f-switch>
|
||||
</div>
|
||||
<div class="flex h-full items-center">
|
||||
<svg-sprite :src="stateDisplay.icon" :class="stateDisplay.text" class="w-5 h-5"></svg-sprite>
|
||||
<span class="ml-3" :class="stateDisplay.text" v-text="stateDisplay.label"></span>
|
||||
</div>
|
||||
<f-text label="URL" hint="URL der Mailman Api" name="base_url" id="base_url" v-model="inner.base_url"></f-text>
|
||||
<f-text label="Benutzername" name="username" id="username" v-model="inner.username"></f-text>
|
||||
<f-text label="Passwort" name="password" id="password" v-model="inner.password"></f-text>
|
||||
<f-text type="password" label="Passwort" name="password" id="password" v-model="inner.password"></f-text>
|
||||
<div></div>
|
||||
<div>
|
||||
<button type="submit" class="mt-3 btn block btn-primary">Speichern</button>
|
||||
|
@ -34,10 +41,41 @@ export default {
|
|||
},
|
||||
props: {
|
||||
data: {},
|
||||
state: {},
|
||||
},
|
||||
computed: {
|
||||
stateDisplay() {
|
||||
if (this.state === null) {
|
||||
return {
|
||||
text: 'text-gray-500',
|
||||
icon: 'disabled',
|
||||
label: 'Deaktiviert',
|
||||
};
|
||||
}
|
||||
|
||||
return this.state
|
||||
? {
|
||||
text: 'text-green-500',
|
||||
icon: 'check',
|
||||
label: 'Verbindung erfolgreich.',
|
||||
}
|
||||
: {
|
||||
text: 'text-red-500',
|
||||
icon: 'close',
|
||||
label: 'Verbindung fehlgeschlagen.',
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
submit() {
|
||||
this.$inertia.post('/setting/mailman', this.inner);
|
||||
var _self = this;
|
||||
|
||||
this.$inertia.post('/setting/mailman', this.inner, {
|
||||
onSuccess(page) {
|
||||
_self.inner = page.props.data;
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
created() {
|
||||
|
|
|
@ -15,10 +15,15 @@ class SettingTest extends TestCase
|
|||
public function testItGetsMailSettings(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$this->stubIo(MailmanService::class, function ($mock) {
|
||||
Phake::when($mock)->setCredentials('http://mailman.test/api', 'user', 'secret')->thenReturn($mock);
|
||||
Phake::when($mock)->check()->thenReturn(true);
|
||||
});
|
||||
MailmanSettings::fake([
|
||||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
'password' => 'secret',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->get('/setting/mailman');
|
||||
|
@ -28,10 +33,53 @@ class SettingTest extends TestCase
|
|||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
'password' => '',
|
||||
'is_active' => true,
|
||||
], $response, 'data');
|
||||
$this->assertInertiaHas(true, $response, 'state');
|
||||
}
|
||||
|
||||
public function testItSaesMailmanSettings(): void
|
||||
public function testItReturnsWrongStateWhenLoginFailed(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$this->stubIo(MailmanService::class, function ($mock) {
|
||||
Phake::when($mock)->setCredentials('http://mailman.test/api', 'user', 'secret')->thenReturn($mock);
|
||||
Phake::when($mock)->check()->thenReturn(false);
|
||||
});
|
||||
MailmanSettings::fake([
|
||||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
'password' => 'secret',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->get('/setting/mailman');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertInertiaHas(false, $response, 'state');
|
||||
}
|
||||
|
||||
public function testItDoesntReturnAnyStateWhenMailmanIsInactive(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$this->stubIo(MailmanService::class, function ($mock) {
|
||||
Phake::when($mock)->setCredentials('http://mailman.test/api', 'user', 'secret')->thenReturn($mock);
|
||||
Phake::when($mock)->check()->thenReturn(false);
|
||||
});
|
||||
MailmanSettings::fake([
|
||||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
'password' => 'secret',
|
||||
'is_active' => false,
|
||||
]);
|
||||
|
||||
$response = $this->get('/setting/mailman');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertInertiaHas(null, $response, 'state');
|
||||
Phake::verifyNoInteraction(app(MailmanService::class));
|
||||
}
|
||||
|
||||
public function testItSetsMailmanSettings(): void
|
||||
{
|
||||
$this->stubIo(MailmanService::class, function ($mock) {
|
||||
Phake::when($mock)->setCredentials('http://mailman.test/api', 'user', 'secret')->thenReturn($mock);
|
||||
|
@ -43,6 +91,7 @@ class SettingTest extends TestCase
|
|||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
'password' => 'secret',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/setting/mailman');
|
||||
|
@ -66,6 +115,7 @@ class SettingTest extends TestCase
|
|||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
'password' => 'secret',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors(['mailman' => 'Verbindung fehlgeschlagen.']);
|
||||
|
@ -82,6 +132,7 @@ class SettingTest extends TestCase
|
|||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
'password' => '',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors(['password' => 'Passwort ist erforderlich.']);
|
||||
|
|
Loading…
Reference in New Issue