-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: authorization using asterisk (*) only works one level #1224
Comments
Did you add the test group to the
This snippet seems from the |
No need. I'm not creating a new (user) group, just new permissions...
The superadmin uses * for one level only, you can try with more levels (like 'admin.settings.theme') and it won't work: public array $permissions = [
'admin.access' => 'Can access the sites admin area',
'admin.settings' => 'Can access the main site settings',
'admin.settings.theme' => 'Can change site theme', |
Hey!
You're right, I misunderstood it. Sorry! So, I spent a little bit of time on this issue, testing some examples and from what I gathered looking at the
I came up with a solution for this issue, if you want to test it on your side, you can find it here. After the patch, it should be fine.
Keep in mind that |
Hello @CosDiabos public array $permissions = [
'perm.lvl1a' => '',
'perm.lvl1a.p1' => '',
'perm.lvl1a.p2' => '',
'perm.lvl1b.p1' => '',
'perm.lvl1b.p2' => '',
'perm.lvl1c.lvl2a' => '',
'perm.lvl1c.lvl2b' => '',
'perm.lvl1c.lvl2a.p1' => '',
'perm.lvl1c.lvl2a.p2' => '',
'perm.lvl1c.lvl2b.p3' => '',
];
...
public array $matrix = [
'user' => [
'perm.lvl1c.*',
],
]; Now the following controller (for authenticated users): <?php
namespace App\Controllers;
class Home extends BaseController
{
public function authorizationTest(string $perm): string
{
return auth()->user()->can($perm) ? "You have permission $perm" : "You do <b>NOT</b> have permission $perm";
}
} Will return:
Also, setting 'user' => [
'perm.*',
], gives, (one example only):
|
Hello! Yes, my initial patch didn't took in consideration those higher permissions like 'perm.*', I failed to mention that. But it seems like you solved it yourself, hehe. I just updated my prev patch to handle all these type of cases and it's a basically the same approach as you had. |
PHP Version
8.3.13
CodeIgniter4 Version
4.5.5
Shield Version
1.1
Which operating systems have you tested for this bug?
Linux
Which server did you use?
fpm-fcgi
Database
SQLite3, MariaDB, Postgres
Did you customize Shield?
No
What happened?
Assigning permissions to a group using asterisk (*) does not work with multiple level properties:
(it works one level only, but, unfortunately, shield documentation does not mentions that lib limitation)
Steps to Reproduce
Add the above config AuthGroups config class. try to check for authorization withing a controller:
Expected Output
"You CAN test.permissions.one!"
Anything else?
I suspect this limitation is related to CI4 Settings library Known Limitations.
IMHO, if this limitation is settings library responsibility, it is very counterproductive for shield to use it.
The text was updated successfully, but these errors were encountered: