From 05135e7ec35cb92f41e5fd542c78a3860d0d8414 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 28 Apr 2022 23:52:30 +0200 Subject: [PATCH] Redirect to conflict page when member needs update --- app/Member/MemberController.php | 11 ++++++++++- packages/laravel-nami | 2 +- tests/Feature/Member/UpdateTest.php | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/Member/MemberController.php b/app/Member/MemberController.php index c270c8f9..4326daa8 100644 --- a/app/Member/MemberController.php +++ b/app/Member/MemberController.php @@ -16,6 +16,7 @@ use App\Setting\GeneralSettings; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Inertia\Response; +use Zoomyboy\LaravelNami\NamiException; class MemberController extends Controller { @@ -109,7 +110,15 @@ class MemberController extends Controller public function update(Member $member, MemberRequest $request): RedirectResponse { - $request->persistUpdate($member); + try { + $request->persistUpdate($member); + } catch (NamiException $e) { + if ($e->isConflict()) { + return redirect()->route('member.edit', ['member' => $member, 'conflict' => '1']); + } else { + throw $e; + } + } return redirect()->route('member.index'); } diff --git a/packages/laravel-nami b/packages/laravel-nami index 1ebb229f..c604f082 160000 --- a/packages/laravel-nami +++ b/packages/laravel-nami @@ -1 +1 @@ -Subproject commit 1ebb229fbc333de378667a240a67c4fbe3fc23ff +Subproject commit c604f082e26c547e277aa1615edf725008fed43a diff --git a/tests/Feature/Member/UpdateTest.php b/tests/Feature/Member/UpdateTest.php index b33dca2d..68d10f19 100644 --- a/tests/Feature/Member/UpdateTest.php +++ b/tests/Feature/Member/UpdateTest.php @@ -62,6 +62,20 @@ class UpdateTest extends TestCase ); } + public function testItChecksVersion(): void + { + $this->login()->loginNami(); + $member = $this->member(); + $member->update(['version' => 43]); + $this->fakeRequest(); + + $response = $this + ->from("/member/{$member->id}") + ->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::'])); + + $response->assertRedirect("/member/{$member->id}/edit?conflict=1"); + } + public function testItUpdatesVersion(): void { $this->withoutExceptionHandling()->login()->loginNami(); @@ -125,6 +139,10 @@ class UpdateTest extends TestCase return Http::response('{ "success": true, "data": {"missingkey": "missingvalue", "kontoverbindung": {"a": "b"} } }', 200); } + if ($request->url() === app(FakeBackend::class)->singleMemberUrl(10, 135) && 'PUT' === $request->method() && 43 === $request['version']) { + return Http::response('{ "success": false, "message": "Update nicht möglich. Der Datensatz wurde zwischenzeitlich verändert." }', 200); + } + if ($request->url() === app(FakeBackend::class)->singleMemberUrl(10, 135) && 'PUT' === $request->method()) { return Http::response('{ "success": true, "data": { "version": 44 } }', 200); }