Redirect to conflict page when member needs update

This commit is contained in:
philipp lang 2022-04-28 23:52:30 +02:00
parent 70363ab185
commit 05135e7ec3
3 changed files with 29 additions and 2 deletions

View File

@ -16,6 +16,7 @@ use App\Setting\GeneralSettings;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Inertia\Response; use Inertia\Response;
use Zoomyboy\LaravelNami\NamiException;
class MemberController extends Controller class MemberController extends Controller
{ {
@ -109,7 +110,15 @@ class MemberController extends Controller
public function update(Member $member, MemberRequest $request): RedirectResponse 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'); return redirect()->route('member.index');
} }

@ -1 +1 @@
Subproject commit 1ebb229fbc333de378667a240a67c4fbe3fc23ff Subproject commit c604f082e26c547e277aa1615edf725008fed43a

View File

@ -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 public function testItUpdatesVersion(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();
@ -125,6 +139,10 @@ class UpdateTest extends TestCase
return Http::response('{ "success": true, "data": {"missingkey": "missingvalue", "kontoverbindung": {"a": "b"} } }', 200); 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()) { if ($request->url() === app(FakeBackend::class)->singleMemberUrl(10, 135) && 'PUT' === $request->method()) {
return Http::response('{ "success": true, "data": { "version": 44 } }', 200); return Http::response('{ "success": true, "data": { "version": 44 } }', 200);
} }