[SOLVED] Shield getPermissions returns an empty array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34) +--- Thread: [SOLVED] Shield getPermissions returns an empty array (/showthread.php?tid=87457) |
[SOLVED] Shield getPermissions returns an empty array - grimpirate - 04-21-2023 I'm using the following spark command to create three default users for testing purposes: PHP Code: <?php PHP Code: print_r(auth()->user()->getPermissions()); Same issue as described in this post. RE: Shield getPermissions returns an empty array - datamweb - 04-21-2023 Permissions vary by Groups. Your command creates the user with the desired group. Therefore, you can use the following command to access the user group. PHP Code: print_r(auth()->user()->getGroups()); If you want to access permissions, you must first add permissions for each user. In this command, you have not added permission for the user, so an empty array is returned. see https://codeigniter4.github.io/shield/authorization/#addpermission RE: Shield getPermissions returns an empty array - grimpirate - 04-21-2023 It's my understanding that the AuthGroups configuration file provides a default set of permissions for the groups under the matrix property. So shouldn't those permissions be returned? RE: Shield getPermissions returns an empty array - datamweb - 04-21-2023 Using matrix is useful for checking access permissions with method can(). So if the user is in group superadmin and the permission is not registered in table auth_permissions_users for it. And you have AuthGroups.php settings as follows. PHP Code: You will get output yes. Even though the user is not registered for permissions(admin.access). PHP Code: At least that's my impression. And I don't know anything more than that. RE: Shield getPermissions returns an empty array - kenjis - 04-21-2023 Quote:getPermissions() That is, getPermissions() returns only user-level permissions. The $matrix defines group-level permissions. RE: Shield getPermissions returns an empty array - grimpirate - 04-22-2023 @datamweb and @kenjis thank you both very much for explaining the nuance, that wasn't immediately apparent to me when I read through the documentation. RE: [SOLVED] Shield getPermissions returns an empty array - kenjis - 04-26-2023 I sent a PR to improve the docs: https://github.com/codeigniter4/shield/pull/714 |