Skip to content

Commit f3a4b75

Browse files
committed
Merge branch 'release/5.0.0'
2 parents f84fa0a + 080798d commit f3a4b75

File tree

4 files changed

+50
-40
lines changed

4 files changed

+50
-40
lines changed

Diff for: 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.0] - 2024-11-29
9+
10+
### Added
11+
12+
- **BREAKING**: [#21](https://github.com/laravel-json-api/core/pull/21) The `Authorizer` contract now allows all methods
13+
to return a `bool` or an Illuminate authorization response.
14+
815
## [4.3.1] - 2024-11-29
916

1017
### Fixed

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"require": {
2626
"php": "^8.2",
2727
"ext-json": "*",
28+
"illuminate/auth": "^11.33",
2829
"illuminate/contracts": "^11.0",
2930
"illuminate/http": "^11.0",
3031
"illuminate/support": "^11.0"
@@ -45,7 +46,7 @@
4546
},
4647
"extra": {
4748
"branch-alias": {
48-
"dev-develop": "4.x-dev"
49+
"dev-develop": "5.x-dev"
4950
}
5051
},
5152
"minimum-stability": "stable",

Diff for: src/Contracts/Auth/Authorizer.php

+21-20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace LaravelJsonApi\Contracts\Auth;
1313

14+
use Illuminate\Auth\Access\Response;
1415
use Illuminate\Http\Request;
1516

1617
interface Authorizer
@@ -20,93 +21,93 @@ interface Authorizer
2021
*
2122
* @param Request $request
2223
* @param string $modelClass
23-
* @return bool
24+
* @return bool|Response
2425
*/
25-
public function index(Request $request, string $modelClass): bool;
26+
public function index(Request $request, string $modelClass): bool|Response;
2627

2728
/**
2829
* Authorize the store controller action.
2930
*
3031
* @param Request $request
3132
* @param string $modelClass
32-
* @return bool
33+
* @return bool|Response
3334
*/
34-
public function store(Request $request, string $modelClass): bool;
35+
public function store(Request $request, string $modelClass): bool|Response;
3536

3637
/**
3738
* Authorize the show controller action.
3839
*
3940
* @param Request $request
4041
* @param object $model
41-
* @return bool
42+
* @return bool|Response
4243
*/
43-
public function show(Request $request, object $model): bool;
44+
public function show(Request $request, object $model): bool|Response;
4445

4546
/**
4647
* Authorize the update controller action.
4748
*
4849
* @param object $model
4950
* @param Request $request
50-
* @return bool
51+
* @return bool|Response
5152
*/
52-
public function update(Request $request, object $model): bool;
53+
public function update(Request $request, object $model): bool|Response;
5354

5455
/**
5556
* Authorize the destroy controller action.
5657
*
5758
* @param Request $request
5859
* @param object $model
59-
* @return bool
60+
* @return bool|Response
6061
*/
61-
public function destroy(Request $request, object $model): bool;
62+
public function destroy(Request $request, object $model): bool|Response;
6263

6364
/**
6465
* Authorize the show-related controller action.
6566
*
6667
* @param Request $request
6768
* @param object $model
6869
* @param string $fieldName
69-
* @return bool
70+
* @return bool|Response
7071
*/
71-
public function showRelated(Request $request, object $model, string $fieldName): bool;
72+
public function showRelated(Request $request, object $model, string $fieldName): bool|Response;
7273

7374
/**
7475
* Authorize the show-relationship controller action.
7576
*
7677
* @param Request $request
7778
* @param object $model
7879
* @param string $fieldName
79-
* @return bool
80+
* @return bool|Response
8081
*/
81-
public function showRelationship(Request $request, object $model, string $fieldName): bool;
82+
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response;
8283

8384
/**
8485
* Authorize the update-relationship controller action.
8586
*
8687
* @param Request $request
8788
* @param object $model
8889
* @param string $fieldName
89-
* @return bool
90+
* @return bool|Response
9091
*/
91-
public function updateRelationship(Request $request, object $model, string $fieldName): bool;
92+
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response;
9293

9394
/**
9495
* Authorize the attach-relationship controller action.
9596
*
9697
* @param Request $request
9798
* @param object $model
9899
* @param string $fieldName
99-
* @return bool
100+
* @return bool|Response
100101
*/
101-
public function attachRelationship(Request $request, object $model, string $fieldName): bool;
102+
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response;
102103

103104
/**
104105
* Authorize the detach-relationship controller action.
105106
*
106107
* @param Request $request
107108
* @param object $model
108109
* @param string $fieldName
109-
* @return bool
110+
* @return bool|Response
110111
*/
111-
public function detachRelationship(Request $request, object $model, string $fieldName): bool;
112+
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response;
112113
}

Diff for: src/Core/Auth/Authorizer.php

+20-19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace LaravelJsonApi\Core\Auth;
1313

1414
use Illuminate\Contracts\Auth\Access\Gate;
15+
use Illuminate\Auth\Access\Response;
1516
use Illuminate\Http\Request;
1617
use LaravelJsonApi\Contracts\Auth\Authorizer as AuthorizerContract;
1718
use LaravelJsonApi\Contracts\Schema\Schema;
@@ -47,10 +48,10 @@ public function __construct(Gate $gate, JsonApiService $service)
4748
/**
4849
* @inheritDoc
4950
*/
50-
public function index(Request $request, string $modelClass): bool
51+
public function index(Request $request, string $modelClass): bool|Response
5152
{
5253
if ($this->mustAuthorize()) {
53-
return $this->gate->check(
54+
return $this->gate->inspect(
5455
'viewAny',
5556
$modelClass
5657
);
@@ -62,10 +63,10 @@ public function index(Request $request, string $modelClass): bool
6263
/**
6364
* @inheritDoc
6465
*/
65-
public function store(Request $request, string $modelClass): bool
66+
public function store(Request $request, string $modelClass): bool|Response
6667
{
6768
if ($this->mustAuthorize()) {
68-
return $this->gate->check(
69+
return $this->gate->inspect(
6970
'create',
7071
$modelClass
7172
);
@@ -77,10 +78,10 @@ public function store(Request $request, string $modelClass): bool
7778
/**
7879
* @inheritDoc
7980
*/
80-
public function show(Request $request, object $model): bool
81+
public function show(Request $request, object $model): bool|Response
8182
{
8283
if ($this->mustAuthorize()) {
83-
return $this->gate->check(
84+
return $this->gate->inspect(
8485
'view',
8586
$model
8687
);
@@ -92,10 +93,10 @@ public function show(Request $request, object $model): bool
9293
/**
9394
* @inheritDoc
9495
*/
95-
public function update(Request $request, object $model): bool
96+
public function update(Request $request, object $model): bool|Response
9697
{
9798
if ($this->mustAuthorize()) {
98-
return $this->gate->check(
99+
return $this->gate->inspect(
99100
'update',
100101
$model
101102
);
@@ -107,10 +108,10 @@ public function update(Request $request, object $model): bool
107108
/**
108109
* @inheritDoc
109110
*/
110-
public function destroy(Request $request, object $model): bool
111+
public function destroy(Request $request, object $model): bool|Response
111112
{
112113
if ($this->mustAuthorize()) {
113-
return $this->gate->check(
114+
return $this->gate->inspect(
114115
'delete',
115116
$model
116117
);
@@ -122,10 +123,10 @@ public function destroy(Request $request, object $model): bool
122123
/**
123124
* @inheritDoc
124125
*/
125-
public function showRelated(Request $request, object $model, string $fieldName): bool
126+
public function showRelated(Request $request, object $model, string $fieldName): bool|Response
126127
{
127128
if ($this->mustAuthorize()) {
128-
return $this->gate->check(
129+
return $this->gate->inspect(
129130
'view' . Str::classify($fieldName),
130131
$model
131132
);
@@ -137,18 +138,18 @@ public function showRelated(Request $request, object $model, string $fieldName):
137138
/**
138139
* @inheritDoc
139140
*/
140-
public function showRelationship(Request $request, object $model, string $fieldName): bool
141+
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response
141142
{
142143
return $this->showRelated($request, $model, $fieldName);
143144
}
144145

145146
/**
146147
* @inheritDoc
147148
*/
148-
public function updateRelationship(Request $request, object $model, string $fieldName): bool
149+
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response
149150
{
150151
if ($this->mustAuthorize()) {
151-
return $this->gate->check(
152+
return $this->gate->inspect(
152153
'update' . Str::classify($fieldName),
153154
[$model, $this->createRelation($request, $fieldName)]
154155
);
@@ -160,10 +161,10 @@ public function updateRelationship(Request $request, object $model, string $fiel
160161
/**
161162
* @inheritDoc
162163
*/
163-
public function attachRelationship(Request $request, object $model, string $fieldName): bool
164+
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response
164165
{
165166
if ($this->mustAuthorize()) {
166-
return $this->gate->check(
167+
return $this->gate->inspect(
167168
'attach' . Str::classify($fieldName),
168169
[$model, $this->createRelation($request, $fieldName)]
169170
);
@@ -175,10 +176,10 @@ public function attachRelationship(Request $request, object $model, string $fiel
175176
/**
176177
* @inheritDoc
177178
*/
178-
public function detachRelationship(Request $request, object $model, string $fieldName): bool
179+
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response
179180
{
180181
if ($this->mustAuthorize()) {
181-
return $this->gate->check(
182+
return $this->gate->inspect(
182183
'detach' . Str::classify($fieldName),
183184
[$model, $this->createRelation($request, $fieldName)]
184185
);

0 commit comments

Comments
 (0)