Compare commits

..

1 Commits

Author SHA1 Message Date
philipp lang 774a85f935 --wip-- [skip ci] 2024-08-01 07:49:12 +02:00
23 changed files with 334 additions and 187 deletions

View File

@ -178,7 +178,7 @@ class Principal implements PrincipalBackendInterface
private function userToPrincipal(User $user): array
{
return [
'{DAV:}displayname' => $user->firstname . ' ' . $user->lastname,
'{DAV:}displayname' => $user->name,
'uri' => 'principals/' . $user->email,
'{http://sabredav.org/ns}email-address' => $user->email,
];

View File

@ -0,0 +1,24 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare;
use App\Fileshare\Resources\FileshareResource;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareIndexAction
{
use AsAction;
public function handle(): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Datei-Verbindungen');
return Inertia::render('fileshare/Index', [
'data' => FileshareResource::collection(Fileshare::paginate(15)),
]);
}
}

View File

@ -2,12 +2,11 @@
namespace App\Fileshare;
use App\Fileshare\Models\Fileshare;
use App\Fileshare\Resources\FileshareResource;
use App\Setting\Contracts\Viewable;
use App\Fileshare\Actions\FileshareIndexAction;
use App\Setting\Contracts\Indexable;
use App\Setting\LocalSettings;
class FileshareSettings extends LocalSettings implements Viewable
class FileshareSettings extends LocalSettings implements Indexable
{
public static function group(): string
{
@ -19,18 +18,13 @@ class FileshareSettings extends LocalSettings implements Viewable
return 'fileshare';
}
public static function indexAction(): string
{
return FileshareIndexAction::class;
}
public static function title(): string
{
return 'Datei-Verbindungen';
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => FileshareResource::collection(Fileshare::paginate(15))
];
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Form\Actions;
use App\Form\FormSettings;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function handle(FormSettings $settings): array
{
return [
'data' => [
'register_url' => $settings->registerUrl,
'clear_cache_url' => $settings->clearCacheUrl,
],
];
}
public function asController(FormSettings $settings): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Module');
return Inertia::render('setting/Form', [
'data' => $this->handle($settings),
]);
}
}

View File

@ -2,12 +2,13 @@
namespace App\Form;
use App\Form\Actions\SettingIndexAction;
use App\Form\Actions\SettingStoreAction;
use App\Setting\Contracts\Viewable;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings;
class FormSettings extends LocalSettings implements Viewable, Storeable
class FormSettings extends LocalSettings implements Indexable, Storeable
{
public string $registerUrl;
public string $clearCacheUrl;
@ -27,23 +28,13 @@ class FormSettings extends LocalSettings implements Viewable, Storeable
return 'Formulare';
}
public static function indexAction(): string
{
return SettingIndexAction::class;
}
public static function storeAction(): string
{
return SettingStoreAction::class;
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => [
'data' => [
'register_url' => $this->registerUrl,
'clear_cache_url' => $this->clearCacheUrl,
]
]
];
}
}

View File

@ -2,11 +2,11 @@
namespace App\Invoice;
use App\Setting\Contracts\Viewable;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings;
class InvoiceSettings extends LocalSettings implements Viewable, Storeable
class InvoiceSettings extends LocalSettings implements Indexable, Storeable
{
public string $from_long;
@ -40,26 +40,9 @@ class InvoiceSettings extends LocalSettings implements Viewable, Storeable
return 'bill';
}
/**
* @inheritdoc
*/
public function viewData(): array
public static function indexAction(): string
{
return [
'data' => [
'from_long' => $this->from_long,
'from' => $this->from,
'mobile' => $this->mobile,
'email' => $this->email,
'website' => $this->website,
'address' => $this->address,
'place' => $this->place,
'zip' => $this->zip,
'iban' => $this->iban,
'bic' => $this->bic,
'remember_weeks' => $this->rememberWeeks,
]
];
return SettingIndexAction::class;
}
public static function storeAction(): string

View File

@ -0,0 +1,42 @@
<?php
namespace App\Invoice;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
* @return array<string, string>
*/
public function handle(InvoiceSettings $settings): array
{
return [
'from_long' => $settings->from_long,
'from' => $settings->from,
'mobile' => $settings->mobile,
'email' => $settings->email,
'website' => $settings->website,
'address' => $settings->address,
'place' => $settings->place,
'zip' => $settings->zip,
'iban' => $settings->iban,
'bic' => $settings->bic,
'remember_weeks' => $settings->rememberWeeks,
];
}
public function asController(InvoiceSettings $settings): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Rechnungs-Einstellungen');
return Inertia::render('setting/Bill', [
'data' => $this->handle($settings),
]);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Mailgateway\Actions;
use App\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Resources\MailgatewayResource;
use Illuminate\Database\Eloquent\Builder;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class IndexAction
{
use AsAction;
/**
* @return Builder<Mailgateway>
*/
public function handle(): Builder
{
return (new Mailgateway())->newQuery();
}
public function asController(): Response
{
session()->put('menu', 'setting');
session()->put('title', 'E-Mail-Verbindungen');
return Inertia::render('mailgateway/Index', [
'data' => MailgatewayResource::collection($this->handle()->paginate(10)),
]);
}
}

View File

@ -3,12 +3,10 @@
namespace App\Mailgateway;
use App\Mailgateway\Actions\IndexAction;
use App\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Resources\MailgatewayResource;
use App\Setting\Contracts\Viewable;
use App\Setting\Contracts\Indexable;
use App\Setting\LocalSettings;
class MailgatewaySettings extends LocalSettings implements Viewable
class MailgatewaySettings extends LocalSettings implements Indexable
{
public static function group(): string
{
@ -20,18 +18,13 @@ class MailgatewaySettings extends LocalSettings implements Viewable
return 'mailgateway';
}
public static function indexAction(): string
{
return IndexAction::class;
}
public static function title(): string
{
return 'E-Mail-Verbindungen';
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => MailgatewayResource::collection(Mailgateway::paginate(10)),
];
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Module;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class ModuleIndexAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
public function handle(ModuleSettings $settings): array
{
return [
'data' => [
'modules' => $settings->modules,
],
'meta' => ['modules' => Module::forSelect()],
];
}
public function asController(ModuleSettings $settings): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Module');
return Inertia::render('setting/Module', [
'data' => $this->handle($settings),
]);
}
}

View File

@ -2,11 +2,11 @@
namespace App\Module;
use App\Setting\Contracts\Viewable;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings;
class ModuleSettings extends LocalSettings implements Viewable, Storeable
class ModuleSettings extends LocalSettings implements Indexable, Storeable
{
/** @var array<int, string> */
public array $modules;
@ -26,6 +26,11 @@ class ModuleSettings extends LocalSettings implements Viewable, Storeable
return 'Module';
}
public static function indexAction(): string
{
return ModuleIndexAction::class;
}
public static function storeAction(): string
{
return ModuleStoreAction::class;
@ -35,19 +40,4 @@ class ModuleSettings extends LocalSettings implements Viewable, Storeable
{
return in_array($module, $this->modules);
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => [
'data' => [
'modules' => $this->modules,
],
'meta' => ['modules' => Module::forSelect()],
]
];
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Nami\Actions;
use App\Setting\NamiSettings;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
* @return array<string, string>
*/
public function handle(NamiSettings $settings): array
{
return [
'mglnr' => $settings->mglnr,
'password' => '',
'default_group_id' => $settings->default_group_id,
];
}
public function asController(NamiSettings $settings): Response
{
session()->put('menu', 'setting');
session()->put('title', 'NaMi-Settings');
return Inertia::render('setting/Nami', [
'data' => $this->handle($settings),
]);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Prevention\Actions;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class PreventionIndexAction
{
use AsAction;
public function handle(): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Prävention');
return Inertia::render('setting/Prevention');
}
}

View File

@ -3,10 +3,11 @@
namespace App\Prevention;
use App\Lib\Editor\EditorData;
use App\Setting\Contracts\Viewable;
use App\Prevention\Actions\PreventionIndexAction;
use App\Setting\Contracts\Indexable;
use App\Setting\LocalSettings;
class PreventionSettings extends LocalSettings implements Viewable
class PreventionSettings extends LocalSettings implements Indexable
{
public EditorData $formmail;
@ -21,16 +22,13 @@ class PreventionSettings extends LocalSettings implements Viewable
return 'prevention';
}
public static function indexAction(): string
{
return PreventionIndexAction::class;
}
public static function title(): string
{
return 'Prävention';
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [];
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace App\Setting\Actions;
use App\Setting\Contracts\Viewable;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class ViewAction
{
use AsAction;
public function handle(Viewable $settingGroup): Response
{
session()->put('menu', 'setting');
session()->put('title', $settingGroup::title());
return Inertia::render('setting/' . ucfirst($settingGroup::group()), $settingGroup->viewData());
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Setting\Contracts;
interface Indexable
{
/**
* @return class-string
*/
public static function indexAction(): string;
}

View File

@ -1,17 +0,0 @@
<?php
namespace App\Setting\Contracts;
interface Viewable
{
public static function url(): string;
public static function title(): string;
public static function group(): string;
/**
* @return array<string, mixed>
*/
public function viewData(): array;
}

View File

@ -5,12 +5,12 @@ namespace App\Setting;
use App\Group;
use App\Nami\Actions\SettingIndexAction;
use App\Nami\Actions\SettingSaveAction;
use App\Setting\Contracts\Viewable;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable;
use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\Nami;
class NamiSettings extends LocalSettings implements Viewable, Storeable
class NamiSettings extends LocalSettings implements Indexable, Storeable
{
public int $mglnr;
@ -41,6 +41,11 @@ class NamiSettings extends LocalSettings implements Viewable, Storeable
return 'nami';
}
public static function indexAction(): string
{
return SettingIndexAction::class;
}
public static function storeAction(): string
{
return SettingSaveAction::class;
@ -50,18 +55,4 @@ class NamiSettings extends LocalSettings implements Viewable, Storeable
{
return 'NaMi-Login';
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => [
'mglnr' => $this->mglnr,
'password' => '',
'default_group_id' => $this->default_group_id,
]
];
}
}

View File

@ -2,9 +2,8 @@
namespace App\Setting;
use App\Invoice\InvoiceSettings;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable;
use App\Setting\Contracts\Viewable;
use Illuminate\Routing\Router;
class SettingFactory
@ -21,8 +20,12 @@ class SettingFactory
{
$this->settings[] = $setting;
if (new $setting() instanceof Indexable) {
app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->get($setting::url(), $setting::indexAction());
}
if (new $setting() instanceof Storeable) {
app(Router::class)->middleware(['web', 'auth:web'])->post($setting::url(), $setting::storeAction());
app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->post($setting::url(), $setting::storeAction());
}
if (1 === count($this->settings)) {
@ -42,11 +45,4 @@ class SettingFactory
])
->toArray();
}
public function resolveGroupName(string $name): Viewable
{
$settingClass = collect($this->settings)->filter(fn ($setting) => new $setting() instanceof Viewable)->first(fn ($setting) => $setting::group() === $name);
return app($settingClass);
}
}

View File

@ -8,8 +8,6 @@ use App\Invoice\InvoiceSettings;
use App\Mailgateway\MailgatewaySettings;
use App\Module\ModuleSettings;
use App\Prevention\PreventionSettings;
use App\Setting\Actions\ViewAction;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
class SettingServiceProvider extends ServiceProvider
@ -22,8 +20,6 @@ class SettingServiceProvider extends ServiceProvider
public function register()
{
app()->singleton(SettingFactory::class, fn () => new SettingFactory());
app(Router::class)->bind('settingGroup', fn ($param) => app(SettingFactory::class)->resolveGroupName($param));
app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->get('/setting/{settingGroup}', ViewAction::class);
}
/**

View File

@ -10,10 +10,17 @@ class SettingTest extends TestCase
{
use DatabaseTransactions;
public function testDisplaySettings(): void
public function testSettingIndex(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
app(InvoiceSettings::class)->fill([
$response = $this->get('/setting/bill')->assertInertiaComponent('setting/Bill')->assertInertia('url', route('settingapilist');
}
public function testItGetsSettingsFromApi(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
InvoiceSettings::fake([
'from_long' => 'DPSG Stamm Muster',
'from' => 'Stamm Muster',
'mobile' => '+49 176 55555',
@ -25,33 +32,43 @@ class SettingTest extends TestCase
'iban' => 'DE05',
'bic' => 'SOLSDE',
'rememberWeeks' => 6
])->save();
]);
$this->get('/setting/bill')
->assertOk()
->assertComponent('setting/Bill')
->assertInertiaPath('data.from_long', 'DPSG Stamm Muster')
->assertInertiaPath('data.from', 'Stamm Muster')
->assertInertiaPath('data.mobile', '+49 176 55555')
->assertInertiaPath('data.email', 'max@muster.de')
->assertInertiaPath('data.website', 'https://example.com')
->assertInertiaPath('data.address', 'Musterstr 4')
->assertInertiaPath('data.place', 'Solingen')
->assertInertiaPath('data.zip', '12345')
->assertInertiaPath('data.iban', 'DE05')
->assertInertiaPath('data.bic', 'SOLSDE')
->assertInertiaPath('data.remember_weeks', 6);
$response = $this->get(route('api.settigs.list'));
$response->assertOk();
$this->assertInertiaHas([
'from_long' => 'DPSG Stamm Muster',
'from' => 'Stamm Muster',
'mobile' => '+49 176 55555',
'email' => 'max@muster.de',
'website' => 'https://example.com',
'address' => 'Musterstr 4',
'place' => 'Solingen',
'zip' => '12345',
'iban' => 'DE05',
'bic' => 'SOLSDE',
'remember_weeks' => 6
], $response, 'data');
}
public function testItReturnsTabs(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$this->get('/setting/bill')
->assertInertiaPath('setting_menu.1.title', 'Rechnung')
->assertInertiaPath('setting_menu.1.url', '/setting/bill')
->assertInertiaPath('setting_menu.1.is_active', true)
->assertInertiaPath('setting_menu.0.is_active', false);
$response = $this->get('/setting/bill');
/** @var array<int, array{url: string, title: string, is_active: bool}> */
$menus = $this->inertia($response, 'setting_menu');
$this->assertTrue(
collect($menus)
->pluck('url')
->contains('/setting/bill')
);
$settingMenu = collect($menus)->first(fn ($menu) => '/setting/bill' === $menu['url']);
$this->assertTrue($settingMenu['is_active']);
$this->assertEquals('Rechnung', $settingMenu['title']);
}
public function testItCanChangeSettings(): void