Add initialize action
This commit is contained in:
parent
a1205a8173
commit
03b7f0ba64
|
@ -5,18 +5,23 @@ namespace App\Initialize\Actions;
|
||||||
use App\Initialize\InitializeJob;
|
use App\Initialize\InitializeJob;
|
||||||
use App\Setting\NamiSettings;
|
use App\Setting\NamiSettings;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Lorisleiva\Actions\ActionRequest;
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
|
|
||||||
class InitializeAction
|
class InitializeAction
|
||||||
{
|
{
|
||||||
use AsAction;
|
use AsAction;
|
||||||
|
|
||||||
public function handle(int $mglnr, string $password, int $groupId)
|
public function handle(int $mglnr, string $password, int $groupId): void
|
||||||
{
|
{
|
||||||
InitializeJob::dispatch();
|
InitializeJob::dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -26,8 +31,24 @@ class InitializeAction
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function getValidationAttributes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'group_id' => 'Gruppierungsnr',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function asController(ActionRequest $request, NamiSettings $settings): RedirectResponse
|
public function asController(ActionRequest $request, NamiSettings $settings): RedirectResponse
|
||||||
{
|
{
|
||||||
|
$api = Nami::login($request->input('mglnr'), $request->input('password'));
|
||||||
|
|
||||||
|
if (!$api->hasGroup($request->input('group_id'))) {
|
||||||
|
throw ValidationException::withMessages(['nami' => 'Gruppierung nicht gefunden.']);
|
||||||
|
}
|
||||||
|
|
||||||
$settings->mglnr = $request->input('mglnr');
|
$settings->mglnr = $request->input('mglnr');
|
||||||
$settings->password = $request->input('password');
|
$settings->password = $request->input('password');
|
||||||
$settings->default_group_id = $request->input('group_id');
|
$settings->default_group_id = $request->input('group_id');
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2c285801947dcbb2f262d4239662229d7f7c7e89
|
Subproject commit 6676b91cda3c0f426612768e5ae22396241cc488
|
|
@ -1,7 +1,42 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="p-6">
|
<div class="p-6 grid h-full items-center justify-center">
|
||||||
<div class="text-lg">Deine App wurde noch nicht initialisiert. Nami-Daten jetzt übernehmen?</div>
|
<div class="rounded border-primary-700 border border-solid p-6">
|
||||||
<a class="btn btn-primary mt-6 inline-block" href="#" @click.prevent="$inertia.post('/initialize', { preserveState: true, replace: false })">Jetzt initialisieren</a>
|
<div class="text-lg text-gray-200 text-sm">
|
||||||
|
Willkommen bei ScoutRobot.<br />
|
||||||
|
Bitte gib deine Zugangsdaten ein,<br />
|
||||||
|
um eine erste Synchronisation durchzuführen.
|
||||||
|
</div>
|
||||||
|
<form @submit.prevent="submit" class="grid gap-3 mt-5">
|
||||||
|
<f-text v-model="values.mglnr" label="Mitgliedsnummer" name="mglnr" id="mglnr"></f-text>
|
||||||
|
<f-text
|
||||||
|
v-model="values.password"
|
||||||
|
type="password"
|
||||||
|
label="Passwort"
|
||||||
|
name="password"
|
||||||
|
id="password"
|
||||||
|
></f-text>
|
||||||
|
<f-text v-model="values.group_id" label="Gruppierungsnummer" name="group_id" id="group_id"></f-text>
|
||||||
|
<button type="submit" class="btn w-full btn-primary mt-6 inline-block">Jetzt initialisieren</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data: function () {
|
||||||
|
return {
|
||||||
|
values: {
|
||||||
|
mglnr: '',
|
||||||
|
password: '',
|
||||||
|
group_id: '',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
submit() {
|
||||||
|
this.$inertia.post('/initialize', this.values);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
|
@ -175,7 +175,7 @@ return [
|
||||||
'time' => 'Uhrzeit',
|
'time' => 'Uhrzeit',
|
||||||
'available' => 'verfügbar',
|
'available' => 'verfügbar',
|
||||||
'size' => 'Größe',
|
'size' => 'Größe',
|
||||||
'mglnr' => 'Mitgliesnummer',
|
'mglnr' => 'Mitgliedsnummer',
|
||||||
'groupid' => 'Gruppierungsnummer',
|
'groupid' => 'Gruppierungsnummer',
|
||||||
'firstname' => 'Vorname',
|
'firstname' => 'Vorname',
|
||||||
'lastname' => 'Nachname',
|
'lastname' => 'Nachname',
|
||||||
|
|
|
@ -20,6 +20,7 @@ use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Queue;
|
use Illuminate\Support\Facades\Queue;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use Zoomyboy\LaravelNami\Authentication\Auth;
|
||||||
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
||||||
use Zoomyboy\LaravelNami\Fakes\GroupFake;
|
use Zoomyboy\LaravelNami\Fakes\GroupFake;
|
||||||
use Zoomyboy\LaravelNami\Fakes\SearchFake;
|
use Zoomyboy\LaravelNami\Fakes\SearchFake;
|
||||||
|
@ -76,6 +77,8 @@ class InitializeTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->withoutExceptionHandling()->login();
|
$this->withoutExceptionHandling()->login();
|
||||||
InitializeAction::partialMock()->shouldReceive('handle')->with(12345, 'secret', 185)->once()->andReturn(true);
|
InitializeAction::partialMock()->shouldReceive('handle')->with(12345, 'secret', 185)->once()->andReturn(true);
|
||||||
|
Auth::success(12345, 'secret');
|
||||||
|
app(GroupFake::class)->fetches(null, [185 => ['name' => 'testgroup']]);
|
||||||
|
|
||||||
$response = $this->post('/initialize', [
|
$response = $this->post('/initialize', [
|
||||||
'group_id' => 185,
|
'group_id' => 185,
|
||||||
|
@ -102,6 +105,39 @@ class InitializeTest extends TestCase
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertErrors(['password' => 'Passwort ist erforderlich.'], $response);
|
$this->assertErrors(['password' => 'Passwort ist erforderlich.'], $response);
|
||||||
|
$this->assertErrors(['mglnr' => 'Mitgliedsnummer ist erforderlich.'], $response);
|
||||||
|
$this->assertErrors(['group_id' => 'Gruppierungsnr ist erforderlich.'], $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItValidatesLogin(): void
|
||||||
|
{
|
||||||
|
$this->login();
|
||||||
|
Auth::fails(12345, 'secret');
|
||||||
|
InitializeAction::partialMock()->shouldReceive('handle')->never();
|
||||||
|
|
||||||
|
$response = $this->post('/initialize', [
|
||||||
|
'group_id' => 12345,
|
||||||
|
'password' => 'secret',
|
||||||
|
'mglnr' => 100102,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertErrors(['nami' => 'NaMi Login fehlgeschlagen.'], $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItValidatesGroupExistance(): void
|
||||||
|
{
|
||||||
|
$this->login();
|
||||||
|
InitializeAction::partialMock()->shouldReceive('handle')->never();
|
||||||
|
Auth::success(12345, 'secret');
|
||||||
|
app(GroupFake::class)->fetches(null, []);
|
||||||
|
|
||||||
|
$response = $this->post('/initialize', [
|
||||||
|
'group_id' => 185,
|
||||||
|
'password' => 'secret',
|
||||||
|
'mglnr' => 12345,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertErrors(['nami' => 'Gruppierung nicht gefunden.'], $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItFiresJobWhenRunningInitializer(): void
|
public function testItFiresJobWhenRunningInitializer(): void
|
||||||
|
|
Loading…
Reference in New Issue