diff --git a/app/Mailman/Actions/SettingIndexAction.php b/app/Mailman/Actions/SettingIndexAction.php index e1dd093d..0d33762d 100644 --- a/app/Mailman/Actions/SettingIndexAction.php +++ b/app/Mailman/Actions/SettingIndexAction.php @@ -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, ]); } } diff --git a/app/Mailman/Actions/SettingSaveAction.php b/app/Mailman/Actions/SettingSaveAction.php index 04b25b90..708cf2b5 100644 --- a/app/Mailman/Actions/SettingSaveAction.php +++ b/app/Mailman/Actions/SettingSaveAction.php @@ -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, ]); diff --git a/app/Mailman/Data/MailingList.php b/app/Mailman/Data/MailingList.php index 24a0cedb..dca67997 100644 --- a/app/Mailman/Data/MailingList.php +++ b/app/Mailman/Data/MailingList.php @@ -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, diff --git a/app/Mailman/MailmanSettings.php b/app/Mailman/MailmanSettings.php index a3269a43..71421d38 100644 --- a/app/Mailman/MailmanSettings.php +++ b/app/Mailman/MailmanSettings.php @@ -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'; diff --git a/database/settings/2022_10_18_123919_mailman_lists.php b/database/settings/2022_10_18_123919_mailman_lists.php new file mode 100644 index 00000000..2286a222 --- /dev/null +++ b/database/settings/2022_10_18_123919_mailman_lists.php @@ -0,0 +1,14 @@ +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); + } +} diff --git a/resources/js/views/setting/Mailman.vue b/resources/js/views/setting/Mailman.vue index 274d0a21..fde12259 100644 --- a/resources/js/views/setting/Mailman.vue +++ b/resources/js/views/setting/Mailman.vue @@ -20,6 +20,34 @@ + + + +
@@ -42,6 +70,7 @@ export default { props: { data: {}, state: {}, + lists: {}, }, computed: { stateDisplay() { diff --git a/tests/Feature/Mailman/SettingTest.php b/tests/Feature/Mailman/SettingTest.php index 6a685044..dc7a596f 100644 --- a/tests/Feature/Mailman/SettingTest.php +++ b/tests/Feature/Mailman/SettingTest.php @@ -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(); }