File tree 4 files changed +67
-11
lines changed
4 files changed +67
-11
lines changed Original file line number Diff line number Diff line change 8
8
'pattern ' => 'languages ' ,
9
9
'method ' => 'GET ' ,
10
10
'action ' => function () {
11
- return $ this ->kirby ()-> languages ();
11
+ return $ this ->languages ();
12
12
}
13
13
],
14
14
[
15
15
'pattern ' => 'languages ' ,
16
16
'method ' => 'POST ' ,
17
17
'action ' => function () {
18
- return $ this ->kirby ()-> languages ()->create ($ this ->requestBody ());
18
+ return $ this ->languages ()->create ($ this ->requestBody ());
19
19
}
20
20
],
21
21
[
22
22
'pattern ' => 'languages/(:any) ' ,
23
23
'method ' => 'GET ' ,
24
24
'action ' => function (string $ code ) {
25
- return $ this ->kirby ()-> languages ()->find ($ code );
25
+ return $ this ->languages ()->find ($ code );
26
26
}
27
27
],
28
28
[
29
29
'pattern ' => 'languages/(:any) ' ,
30
30
'method ' => 'PATCH ' ,
31
31
'action ' => function (string $ code ) {
32
- return $ this ->kirby ()-> languages ()->find ($ code )?->update($ this ->requestBody ());
32
+ return $ this ->languages ()->find ($ code )?->update($ this ->requestBody ());
33
33
}
34
34
],
35
35
[
36
36
'pattern ' => 'languages/(:any) ' ,
37
37
'method ' => 'DELETE ' ,
38
38
'action ' => function (string $ code ) {
39
- return $ this ->kirby ()-> languages ()->find ($ code )?->delete();
39
+ return $ this ->languages ()->find ($ code )?->delete();
40
40
}
41
41
]
42
42
];
Original file line number Diff line number Diff line change @@ -138,6 +138,14 @@ public function language(): string|null
138
138
$ this ->requestHeaders ('x-language ' );
139
139
}
140
140
141
+ /**
142
+ * Returns the languages collection
143
+ */
144
+ public function languages (): Languages
145
+ {
146
+ return $ this ->kirby ()->languages ()->filter ('isAccessible ' , true );
147
+ }
148
+
141
149
/**
142
150
* Returns the page object for the given id
143
151
*
@@ -225,9 +233,15 @@ public function session(array $options = []): Session
225
233
/**
226
234
* Returns the site object
227
235
*/
228
- public function site (): Site
236
+ public function site (): Site | null
229
237
{
230
- return $ this ->kirby ->site ();
238
+ $ site = $ this ->kirby ->site ();
239
+
240
+ if ($ site ->isAccessible () === true ) {
241
+ return $ site ;
242
+ }
243
+
244
+ return null ;
231
245
}
232
246
233
247
/**
@@ -255,6 +269,6 @@ public function user(string|null $id = null): User|null
255
269
*/
256
270
public function users (): Users
257
271
{
258
- return $ this ->kirby ->users ();
272
+ return $ this ->kirby ->users ()-> filter ( ' isAccessible ' , true ) ;
259
273
}
260
274
}
Original file line number Diff line number Diff line change @@ -52,7 +52,9 @@ public static function file(
52
52
*/
53
53
public static function language (string $ code ): Language |null
54
54
{
55
- if ($ language = App::instance ()->language ($ code )) {
55
+ $ language = App::instance ()->language ($ code );
56
+
57
+ if ($ language ?->isAccessible() === true ) {
56
58
return $ language ;
57
59
}
58
60
@@ -158,13 +160,23 @@ public static function user(string|null $id = null): User|null
158
160
$ kirby ->option ('api.allowImpersonation ' , false )
159
161
);
160
162
161
- return $ user ?? throw new NotFoundException (
163
+ if ($ user ?->isAccessible() === true ) {
164
+ return $ user ;
165
+ }
166
+
167
+ throw new NotFoundException (
162
168
key: 'user.undefined '
163
169
);
164
170
}
165
171
166
172
// get a specific user by id
167
- return $ kirby ->user ($ id ) ?? throw new NotFoundException (
173
+ $ user = $ kirby ->user ($ id );
174
+
175
+ if ($ user ?->isAccessible() === true ) {
176
+ return $ user ;
177
+ }
178
+
179
+ throw new NotFoundException (
168
180
key: 'user.notFound ' ,
169
181
data: ['name ' => $ id ]
170
182
);
Original file line number Diff line number Diff line change @@ -436,6 +436,36 @@ public function testUsers()
436
436
$ this ->assertSame ($ this ->app ->users (), $ this ->api ->users ());
437
437
}
438
438
439
+ public function testUsersWithoutPermissions ()
440
+ {
441
+ $ app = $ this ->app ->clone ([
442
+ 'users ' => [
443
+
444
+ ]
445
+ ]);
446
+ $ app->
impersonate (
'[email protected] ' );
447
+
448
+ $ this ->assertNotSame ($ app ->users (), $ app ->api ()->users ());
449
+ }
450
+
451
+ public function testUsersWithoutPermissionsDebugEnabled ()
452
+ {
453
+ $ app = $ this ->app ->clone ([
454
+ 'options ' => [
455
+ 'debug ' => true
456
+ ],
457
+ 'users ' => [
458
+
459
+ ]
460
+ ]);
461
+ $ app->
impersonate (
'[email protected] ' );
462
+
463
+ $ this ->expectException (AuthException::class);
464
+ $ this ->expectExceptionMessage ('You are not allowed to access the users ' );
465
+
466
+ $ app ->api ()->users ();
467
+ }
468
+
439
469
public function testFileGetRoute ()
440
470
{
441
471
// regular
You can’t perform that action at this time.
0 commit comments