Skip to content

Commit 0ba8263

Browse files
committed
docs: add how to properly upgrade for $permission_denied&$group_denied
1 parent a327eae commit 0ba8263

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

UPGRADING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ following steps will be done.
2525
$this->helpers = array_merge($this->helpers, ['setting']);
2626
```
2727

28+
#### Config\Auth
29+
30+
The following items have been added. Copy the properties in **src/Config/Auth.php**.
31+
32+
- `$permission_denied` and `$group_denied` are added to `Config\Auth::$redirects`.
33+
- `permissionDeniedRedirect()` and `groupDeniedRedirect()` are added.
34+
35+
#### Fix Custom Filter If extends `AbstractAuthFilter`
36+
If you have written a custom filter that extends `AbstractAuthFilter`. Now you need to add and implement method `redirectToDeniedUrl()` to your custom filter.
37+
The following example is related to the above explanation for **group** filter.
38+
```php
39+
/**
40+
* If there is no necessary access to the group,
41+
* it will redirect the user to the set URL with an error message.
42+
*/
43+
protected function redirectToDeniedUrl(): RedirectResponse
44+
{
45+
return redirect()->to(config('Auth')->groupDeniedRedirect())
46+
->with('error', lang('Auth.notEnoughPrivilege'));
47+
}
48+
```
49+
2850
## Version 1.0.0-beta.6 to 1.0.0-beta.7
2951

3052
### The minimum CodeIgniter version

src/Filters/GroupFilter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace CodeIgniter\Shield\Filters;
66

77
use CodeIgniter\HTTP\RedirectResponse;
8-
use CodeIgniter\Shield\Config\Auth;
98

109
/**
1110
* Group Authorization Filter.
@@ -27,7 +26,7 @@ protected function isAuthorized(array $arguments): bool
2726
*/
2827
protected function redirectToDeniedUrl(): RedirectResponse
2928
{
30-
return redirect()->to(config(Auth::class)->groupDeniedRedirect())
29+
return redirect()->to(config('Auth')->groupDeniedRedirect())
3130
->with('error', lang('Auth.notEnoughPrivilege'));
3231
}
3332
}

src/Filters/PermissionFilter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace CodeIgniter\Shield\Filters;
66

77
use CodeIgniter\HTTP\RedirectResponse;
8-
use CodeIgniter\Shield\Config\Auth;
98

109
/**
1110
* Permission Authorization Filter.
@@ -33,7 +32,7 @@ protected function isAuthorized(array $arguments): bool
3332
*/
3433
protected function redirectToDeniedUrl(): RedirectResponse
3534
{
36-
return redirect()->to(config(Auth::class)->permissionDeniedRedirect())
35+
return redirect()->to(config('Auth')->permissionDeniedRedirect())
3736
->with('error', lang('Auth.notEnoughPrivilege'));
3837
}
3938
}

tests/Authentication/Filters/GroupFilterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Tests\Authentication\Filters;
66

7-
use CodeIgniter\Shield\Config\Auth;
87
use CodeIgniter\Shield\Entities\User;
98
use CodeIgniter\Shield\Filters\GroupFilter;
109
use CodeIgniter\Shield\Models\UserModel;
@@ -70,7 +69,7 @@ public function testFilterIncorrectGroupNoPrevious(): void
7069
->get('protected-route');
7170

7271
// Should redirect to home page since previous_url is not set
73-
$result->assertRedirectTo(config(Auth::class)->groupDeniedRedirect());
72+
$result->assertRedirectTo(config('Auth')->groupDeniedRedirect());
7473
// Should have error message
7574
$result->assertSessionHas('error', lang('Auth.notEnoughPrivilege'));
7675
}

tests/Authentication/Filters/PermissionFilterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Tests\Authentication\Filters;
66

7-
use CodeIgniter\Shield\Config\Auth;
87
use CodeIgniter\Shield\Entities\User;
98
use CodeIgniter\Shield\Filters\PermissionFilter;
109
use CodeIgniter\Shield\Models\UserModel;
@@ -70,7 +69,7 @@ public function testFilterIncorrectGroupNoPrevious(): void
7069
->get('protected-route');
7170

7271
// Should redirect to home page since previous_url is not set
73-
$result->assertRedirectTo(config(Auth::class)->permissionDeniedRedirect());
72+
$result->assertRedirectTo(config('Auth')->permissionDeniedRedirect());
7473
// Should have error message
7574
$result->assertSessionHas('error', lang('Auth.notEnoughPrivilege'));
7675
}

0 commit comments

Comments
 (0)