Add lists config
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
9b1e423210
commit
e4c0b9079d
|
@ -21,6 +21,10 @@ class SettingIndexAction
|
|||
'is_active' => $settings->is_active,
|
||||
'base_url' => $settings->base_url,
|
||||
'username' => $settings->username,
|
||||
'all_list' => $settings->all_list,
|
||||
'all_parents_list' => $settings->all_parents_list,
|
||||
'active_leaders_list' => $settings->active_leaders_list,
|
||||
'passive_leaders_list' => $settings->passive_leaders_list,
|
||||
'password' => '',
|
||||
];
|
||||
}
|
||||
|
@ -30,13 +34,18 @@ 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)->fromSettings($settings)->check()
|
||||
: null;
|
||||
if ($settings->is_active) {
|
||||
$state = app(MailmanService::class)->fromSettings($settings)->check();
|
||||
$lists = app(MailmanService::class)->fromSettings($settings)->getLists();
|
||||
} else {
|
||||
$state = null;
|
||||
$lists = [];
|
||||
}
|
||||
|
||||
return Inertia::render('setting/Mailman', [
|
||||
'data' => $this->handle($settings),
|
||||
'state' => $state,
|
||||
'lists' => $lists,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,10 @@ class SettingSaveAction
|
|||
'base_url' => $input['base_url'] ?? null,
|
||||
'username' => $input['username'] ?? null,
|
||||
'password' => $input['password'] ?? null,
|
||||
'all_list' => $input['all_list'] ?? null,
|
||||
'all_parents_list' => $input['all_parents_list'] ?? null,
|
||||
'active_leaders_list' => $input['active_leaders_list'] ?? null,
|
||||
'passive_leaders_list' => $input['passive_leaders_list'] ?? null,
|
||||
'is_active' => $input['is_active'] ?? false,
|
||||
]);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Mailman\Data;
|
||||
|
||||
use Spatie\LaravelData\Attributes\MapName;
|
||||
use Spatie\LaravelData\Attributes\MapOutputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
|
@ -12,7 +13,9 @@ class MailingList extends Data
|
|||
public function __construct(
|
||||
public string $description,
|
||||
public string $displayName,
|
||||
#[MapOutputName('name')]
|
||||
public string $fqdnListname,
|
||||
#[MapOutputName('id')]
|
||||
public string $listId,
|
||||
public string $listName,
|
||||
public string $mailHost,
|
||||
|
|
|
@ -16,6 +16,14 @@ class MailmanSettings extends LocalSettings
|
|||
|
||||
public bool $is_active;
|
||||
|
||||
public ?string $all_list;
|
||||
|
||||
public ?string $all_parents_list;
|
||||
|
||||
public ?string $active_leaders_list;
|
||||
|
||||
public ?string $passive_leaders_list;
|
||||
|
||||
public static function group(): string
|
||||
{
|
||||
return 'mailman';
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
use Spatie\LaravelSettings\Migrations\SettingsMigration;
|
||||
|
||||
class MailmanLists extends SettingsMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->migrator->add('mailman.all_parents_list', null);
|
||||
$this->migrator->add('mailman.all_list', null);
|
||||
$this->migrator->add('mailman.active_leaders_list', null);
|
||||
$this->migrator->add('mailman.passive_leaders_list', null);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,34 @@
|
|||
<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 type="password" label="Passwort" name="password" id="password" v-model="inner.password"></f-text>
|
||||
<f-select
|
||||
label="Liste für alle Mitglieder"
|
||||
name="all_list"
|
||||
id="all_list"
|
||||
v-model="inner.all_list"
|
||||
:options="lists"
|
||||
></f-select>
|
||||
<f-select
|
||||
label="Liste für Eltern"
|
||||
name="all_parents_list"
|
||||
id="all_parents_list"
|
||||
v-model="inner.all_parents_list"
|
||||
:options="lists"
|
||||
></f-select>
|
||||
<f-select
|
||||
label="Liste für aktive Leiter"
|
||||
name="active_leaders_list"
|
||||
id="active_leaders_list"
|
||||
v-model="inner.active_leaders_list"
|
||||
:options="lists"
|
||||
></f-select>
|
||||
<f-select
|
||||
label="Liste für passive Leiter"
|
||||
name="passive_leaders_list"
|
||||
id="passive_leaders_list"
|
||||
v-model="inner.passive_leaders_list"
|
||||
:options="lists"
|
||||
></f-select>
|
||||
<div></div>
|
||||
<div>
|
||||
<button type="submit" class="mt-3 btn block btn-primary">Speichern</button>
|
||||
|
@ -42,6 +70,7 @@ export default {
|
|||
props: {
|
||||
data: {},
|
||||
state: {},
|
||||
lists: {},
|
||||
},
|
||||
computed: {
|
||||
stateDisplay() {
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
namespace Tests\Feature\Mailman;
|
||||
|
||||
use App\Mailman\Data\MailingList;
|
||||
use App\Mailman\MailmanSettings;
|
||||
use App\Mailman\Support\MailmanService;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Phake;
|
||||
use Tests\RequestFactories\MailmanListRequestFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingTest extends TestCase
|
||||
|
@ -16,8 +19,11 @@ class SettingTest extends TestCase
|
|||
{
|
||||
$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)->fromSettings(Phake::anyParameters())->thenReturn($mock);
|
||||
Phake::when($mock)->check()->thenReturn(true);
|
||||
Phake::when($mock)->getLists()->thenReturn(LazyCollection::make(function () {
|
||||
yield MailingList::from(MailmanListRequestFactory::new()->create(['list_id' => 'F', 'fqdn_listname' => 'admin@example.com']));
|
||||
}));
|
||||
});
|
||||
MailmanSettings::fake([
|
||||
'base_url' => 'http://mailman.test/api',
|
||||
|
@ -36,13 +42,15 @@ class SettingTest extends TestCase
|
|||
'is_active' => true,
|
||||
], $response, 'data');
|
||||
$this->assertInertiaHas(true, $response, 'state');
|
||||
$this->assertInertiaHas('admin@example.com', $response, 'lists.0.name');
|
||||
$this->assertInertiaHas('F', $response, 'lists.0.id');
|
||||
}
|
||||
|
||||
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)->fromSettings(Phake::anyParameters())->thenReturn($mock);
|
||||
Phake::when($mock)->check()->thenReturn(false);
|
||||
});
|
||||
MailmanSettings::fake([
|
||||
|
@ -61,10 +69,7 @@ class SettingTest extends TestCase
|
|||
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);
|
||||
});
|
||||
$this->stubIo(MailmanService::class, fn ($mock) => $mock);
|
||||
MailmanSettings::fake([
|
||||
'base_url' => 'http://mailman.test/api',
|
||||
'username' => 'user',
|
||||
|
@ -92,6 +97,8 @@ class SettingTest extends TestCase
|
|||
'username' => 'user',
|
||||
'password' => 'secret',
|
||||
'is_active' => true,
|
||||
'all_parents_list' => 'P',
|
||||
'all_list' => 'X',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/setting/mailman');
|
||||
|
@ -99,6 +106,8 @@ class SettingTest extends TestCase
|
|||
$this->assertEquals('http://mailman.test/api', $settings->base_url);
|
||||
$this->assertEquals('secret', $settings->password);
|
||||
$this->assertEquals('user', $settings->username);
|
||||
$this->assertEquals('X', $settings->all_list);
|
||||
$this->assertEquals('P', $settings->all_parents_list);
|
||||
Phake::verify(app(MailmanService::class))->setCredentials('http://mailman.test/api', 'user', 'secret');
|
||||
Phake::verify(app(MailmanService::class))->check();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue