Skip to content

Commit

Permalink
Merge branch 'release/5.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Dec 2, 2024
2 parents f21276a + fd0bf65 commit 44fdbb8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

## [5.0.1] - 2025-12-02

### Fixed

- [#301](https://github.com/laravel-json-api/laravel/pull/301) Do not override response status when authorization
exception is thrown.

## [5.0.0] - 2025-12-01

### Changed
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Requests/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ protected function passesAuthorization()
}

} catch (AuthorizationException $ex) {
$this->failIfUnauthenticated();
if (!$ex->hasStatus()) {
$this->failIfUnauthenticated();
}
throw $ex;
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions tests/dummy/app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function updatePhone(User $user, User $other): bool
/**
* Determine if the user can delete the other user.
*
* @param User $user
* @param ?User $user
* @param User $other
* @return bool|Response
*/
public function delete(User $user, User $other)
public function delete(?User $user, User $other)
{
return $user->is($other) ? true : Response::denyAsNotFound('not found message');
return $user?->is($other) ? true : Response::denyAsNotFound('not found message');
}

}
23 changes: 17 additions & 6 deletions tests/dummy/tests/Api/V1/Users/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,34 @@

class DeleteTest extends TestCase
{

public function test(): void
{
$user = User::factory()->createOne();

$expected = $this->serializer
->user($user);
$response = $this
->actingAs(User::factory()->createOne())
->jsonApi('users')
->delete(url('/api/v1/users', $expected['id']));
->delete(url('/api/v1/users', $user));

$response->assertNotFound()
->assertHasError(404, [
$response->assertNotFound()->assertErrorStatus([
'detail' => 'not found message',
'status' => '404',
'title' => 'Not Found',
]);
}

public function testUnauthenticated(): void
{
$user = User::factory()->createOne();

$response = $this
->jsonApi('users')
->delete(url('/api/v1/users', $user));

$response->assertNotFound()->assertErrorStatus([
'detail' => 'not found message',
'status' => '404',
'title' => 'Not Found',
]);
}
}

0 comments on commit 44fdbb8

Please sign in to comment.