Skip to content

Commit 44fdbb8

Browse files
committed
Merge branch 'release/5.0.1'
2 parents f21276a + fd0bf65 commit 44fdbb8

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. This projec
55

66
## Unreleased
77

8+
## [5.0.1] - 2025-12-02
9+
10+
### Fixed
11+
12+
- [#301](https://github.com/laravel-json-api/laravel/pull/301) Do not override response status when authorization
13+
exception is thrown.
14+
815
## [5.0.0] - 2025-12-01
916

1017
### Changed

src/Http/Requests/FormRequest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ protected function passesAuthorization()
254254
}
255255

256256
} catch (AuthorizationException $ex) {
257-
$this->failIfUnauthenticated();
257+
if (!$ex->hasStatus()) {
258+
$this->failIfUnauthenticated();
259+
}
258260
throw $ex;
259261
}
260262
return true;

tests/dummy/app/Policies/UserPolicy.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public function updatePhone(User $user, User $other): bool
5555
/**
5656
* Determine if the user can delete the other user.
5757
*
58-
* @param User $user
58+
* @param ?User $user
5959
* @param User $other
6060
* @return bool|Response
6161
*/
62-
public function delete(User $user, User $other)
62+
public function delete(?User $user, User $other)
6363
{
64-
return $user->is($other) ? true : Response::denyAsNotFound('not found message');
64+
return $user?->is($other) ? true : Response::denyAsNotFound('not found message');
6565
}
6666

6767
}

tests/dummy/tests/Api/V1/Users/DeleteTest.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,34 @@
1616

1717
class DeleteTest extends TestCase
1818
{
19-
2019
public function test(): void
2120
{
2221
$user = User::factory()->createOne();
2322

24-
$expected = $this->serializer
25-
->user($user);
2623
$response = $this
2724
->actingAs(User::factory()->createOne())
2825
->jsonApi('users')
29-
->delete(url('/api/v1/users', $expected['id']));
26+
->delete(url('/api/v1/users', $user));
3027

31-
$response->assertNotFound()
32-
->assertHasError(404, [
28+
$response->assertNotFound()->assertErrorStatus([
3329
'detail' => 'not found message',
3430
'status' => '404',
3531
'title' => 'Not Found',
3632
]);
3733
}
34+
35+
public function testUnauthenticated(): void
36+
{
37+
$user = User::factory()->createOne();
38+
39+
$response = $this
40+
->jsonApi('users')
41+
->delete(url('/api/v1/users', $user));
42+
43+
$response->assertNotFound()->assertErrorStatus([
44+
'detail' => 'not found message',
45+
'status' => '404',
46+
'title' => 'Not Found',
47+
]);
48+
}
3849
}

0 commit comments

Comments
 (0)