1
+ <?php
2
+ /*
3
+ * Copyright 2024 Cloud Creativity Limited
4
+ *
5
+ * Use of this source code is governed by an MIT-style
6
+ * license that can be found in the LICENSE file or at
7
+ * https://opensource.org/licenses/MIT.
8
+ */
9
+
10
+ namespace LaravelJsonApi \Contracts \Auth ;
11
+
12
+ use Illuminate \Auth \Access \AuthorizationException ;
13
+ use Illuminate \Auth \AuthenticationException ;
14
+ use Illuminate \Http \Request ;
15
+ use LaravelJsonApi \Core \Document \ErrorList ;
16
+ use Symfony \Component \HttpKernel \Exception \HttpExceptionInterface ;
17
+
18
+ interface ResourceAuthorizer
19
+ {
20
+ /**
21
+ * Authorize a JSON:API index query.
22
+ *
23
+ * @param Request|null $request
24
+ * @return ErrorList|null
25
+ * @throws AuthenticationException
26
+ * @throws AuthorizationException
27
+ * @throws HttpExceptionInterface
28
+ */
29
+ public function index (?Request $ request ): ?ErrorList ;
30
+
31
+ /**
32
+ * Authorize a JSON:API index query or fail.
33
+ *
34
+ * @param Request|null $request
35
+ * @return void
36
+ * @throws AuthenticationException
37
+ * @throws AuthorizationException
38
+ * @throws HttpExceptionInterface
39
+ */
40
+ public function indexOrFail (?Request $ request ): void ;
41
+
42
+ /**
43
+ * Authorize a JSON:API store operation.
44
+ *
45
+ * @param Request|null $request
46
+ * @return ErrorList|null
47
+ * @throws AuthorizationException
48
+ * @throws AuthenticationException
49
+ * @throws HttpExceptionInterface
50
+ */
51
+ public function store (?Request $ request ): ?ErrorList ;
52
+
53
+ /**
54
+ * Authorize a JSON:API store operation or fail.
55
+ *
56
+ * @param Request|null $request
57
+ * @return void
58
+ * @throws AuthorizationException
59
+ * @throws AuthenticationException
60
+ * @throws HttpExceptionInterface
61
+ */
62
+ public function storeOrFail (?Request $ request ): void ;
63
+
64
+ /**
65
+ * Authorize a JSON:API show query.
66
+ *
67
+ * @param Request|null $request
68
+ * @param object $model
69
+ * @return ErrorList|null
70
+ * @throws AuthorizationException
71
+ * @throws AuthenticationException
72
+ * @throws HttpExceptionInterface
73
+ */
74
+ public function show (?Request $ request , object $ model ): ?ErrorList ;
75
+
76
+ /**
77
+ * Authorize a JSON:API show query, or fail.
78
+ *
79
+ * @param Request|null $request
80
+ * @param object $model
81
+ * @return void
82
+ * @throws AuthorizationException
83
+ * @throws AuthenticationException
84
+ * @throws HttpExceptionInterface
85
+ */
86
+ public function showOrFail (?Request $ request , object $ model ): void ;
87
+
88
+ /**
89
+ * Authorize a JSON:API update command.
90
+ *
91
+ * @param Request|null $request
92
+ * @param object $model
93
+ * @return ErrorList|null
94
+ * @throws AuthorizationException
95
+ * @throws AuthenticationException
96
+ * @throws HttpExceptionInterface
97
+ */
98
+ public function update (?Request $ request , object $ model ): ?ErrorList ;
99
+
100
+ /**
101
+ * Authorize a JSON:API update command, or fail.
102
+ *
103
+ * @param Request|null $request
104
+ * @param object $model
105
+ * @return void
106
+ * @throws AuthorizationException
107
+ * @throws AuthenticationException
108
+ * @throws HttpExceptionInterface
109
+ */
110
+ public function updateOrFail (?Request $ request , object $ model ): void ;
111
+
112
+ /**
113
+ * Authorize a JSON:API destroy command.
114
+ *
115
+ * @param Request|null $request
116
+ * @param object $model
117
+ * @return ErrorList|null
118
+ * @throws AuthorizationException
119
+ * @throws AuthenticationException
120
+ * @throws HttpExceptionInterface
121
+ */
122
+ public function destroy (?Request $ request , object $ model ): ?ErrorList ;
123
+
124
+ /**
125
+ * Authorize a JSON:API destroy command, or fail.
126
+ *
127
+ * @param Request|null $request
128
+ * @param object $model
129
+ * @return void
130
+ * @throws AuthorizationException
131
+ * @throws AuthenticationException
132
+ * @throws HttpExceptionInterface
133
+ */
134
+ public function destroyOrFail (?Request $ request , object $ model ): void ;
135
+
136
+ /**
137
+ * Authorize a JSON:API show related query.
138
+ *
139
+ * @param Request|null $request
140
+ * @param object $model
141
+ * @param string $fieldName
142
+ * @return ErrorList|null
143
+ * @throws AuthorizationException
144
+ * @throws AuthenticationException
145
+ * @throws HttpExceptionInterface
146
+ */
147
+ public function showRelated (?Request $ request , object $ model , string $ fieldName ): ?ErrorList ;
148
+
149
+ /**
150
+ * Authorize a JSON:API show related query, or fail.
151
+ *
152
+ * @param Request|null $request
153
+ * @param object $model
154
+ * @param string $fieldName
155
+ * @return void
156
+ * @throws AuthorizationException
157
+ * @throws AuthenticationException
158
+ * @throws HttpExceptionInterface
159
+ */
160
+ public function showRelatedOrFail (?Request $ request , object $ model , string $ fieldName ): void ;
161
+
162
+ /**
163
+ * Authorize a JSON:API show relationship query.
164
+ *
165
+ * @param Request|null $request
166
+ * @param object $model
167
+ * @param string $fieldName
168
+ * @return ErrorList|null
169
+ * @throws AuthorizationException
170
+ * @throws AuthenticationException
171
+ * @throws HttpExceptionInterface
172
+ */
173
+ public function showRelationship (?Request $ request , object $ model , string $ fieldName ): ?ErrorList ;
174
+
175
+ /**
176
+ * Authorize a JSON:API show relationship query, or fail.
177
+ *
178
+ * @param Request|null $request
179
+ * @param object $model
180
+ * @param string $fieldName
181
+ * @return void
182
+ * @throws AuthorizationException
183
+ * @throws AuthenticationException
184
+ * @throws HttpExceptionInterface
185
+ */
186
+ public function showRelationshipOrFail (?Request $ request , object $ model , string $ fieldName ): void ;
187
+
188
+ /**
189
+ * Authorize a JSON:API update relationship command.
190
+ *
191
+ * @param Request|null $request
192
+ * @param object $model
193
+ * @param string $fieldName
194
+ * @return ErrorList|null
195
+ * @throws AuthorizationException
196
+ * @throws AuthenticationException
197
+ * @throws HttpExceptionInterface
198
+ */
199
+ public function updateRelationship (?Request $ request , object $ model , string $ fieldName ): ?ErrorList ;
200
+
201
+ /**
202
+ * Authorize a JSON:API update relationship command, or fail.
203
+ *
204
+ * @param Request|null $request
205
+ * @param object $model
206
+ * @param string $fieldName
207
+ * @return void
208
+ * @throws AuthorizationException
209
+ * @throws AuthenticationException
210
+ * @throws HttpExceptionInterface
211
+ */
212
+ public function updateRelationshipOrFail (?Request $ request , object $ model , string $ fieldName ): void ;
213
+
214
+ /**
215
+ * Authorize a JSON:API attach relationship command.
216
+ *
217
+ * @param Request|null $request
218
+ * @param object $model
219
+ * @param string $fieldName
220
+ * @return ErrorList|null
221
+ * @throws AuthorizationException
222
+ * @throws AuthenticationException
223
+ * @throws HttpExceptionInterface
224
+ */
225
+ public function attachRelationship (?Request $ request , object $ model , string $ fieldName ): ?ErrorList ;
226
+
227
+ /**
228
+ * Authorize a JSON:API attach relationship command, or fail.
229
+ *
230
+ * @param Request|null $request
231
+ * @param object $model
232
+ * @param string $fieldName
233
+ * @return void
234
+ * @throws AuthorizationException
235
+ * @throws AuthenticationException
236
+ * @throws HttpExceptionInterface
237
+ */
238
+ public function attachRelationshipOrFail (?Request $ request , object $ model , string $ fieldName ): void ;
239
+
240
+ /**
241
+ * Authorize a JSON:API detach relationship command.
242
+ *
243
+ * @param Request|null $request
244
+ * @param object $model
245
+ * @param string $fieldName
246
+ * @return ErrorList|null
247
+ * @throws AuthorizationException
248
+ * @throws AuthenticationException
249
+ * @throws HttpExceptionInterface
250
+ */
251
+ public function detachRelationship (?Request $ request , object $ model , string $ fieldName ): ?ErrorList ;
252
+
253
+ /**
254
+ * Authorize a JSON:API detach relationship command, or fail.
255
+ *
256
+ * @param Request|null $request
257
+ * @param object $model
258
+ * @param string $fieldName
259
+ * @return void
260
+ * @throws AuthorizationException
261
+ * @throws AuthenticationException
262
+ * @throws HttpExceptionInterface
263
+ */
264
+ public function detachRelationshipOrFail (?Request $ request , object $ model , string $ fieldName ): void ;
265
+ }
0 commit comments