Creating new permissions dynamically #478
Unanswered
KipchirchirIan
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Hi, didn't test it but I think you you should use Settings methods |
Beta Was this translation helpful? Give feedback.
2 replies
-
For Qn 1: A solution that seems like a hack or a roundabout way of doing it would be: $newPermissions = [
'users.verify' => 'Can verify users',
];
// 1. Retrieve all permissions
$existingPermissions = setting()->get('AuthGroups.permissions');
// 2. Merge the two arrays containing existing permissions and new permissions
$permissions = array_merge($existingPermissions, $newPermissions);
// 3. Reset the new permissions again
setting()->set('AuthGroups.permissions', $permissions); I'll appreciate any feedback or other solutions on this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Qn 1: How do I create new permissions dynamically without adding it directly in the
AuthGroups.php
file?I have tried several ways e.g.
I have looked into Bonfire project as answered in discussion #448 and it helped me a lot with other areas however, I found very little info to do with permissions.
NOTE: Example 1 works but it overwrites whatever I had added before when I run it the 2nd time.
Qn 2: For some reason, I am unable to add permissions that are listed in the
AuthGroups.php
file to the currently logged in user and I getCodeIgniter\Shield\Authorization\AuthorizationException
when I try it. See the code below:This works when I create permissions with Example 1 code above and I add the newly created permission to the user.
I guess I am missing something in the 2 problems above or I'm just exhausted. I'll appreciate if anyone helps me point them out.
Edit:
Sorry, had to mention some people to get answers. Cc @lonnieezell @kenjis @MGatner
Codeigniter 4 version: 4.2.7
Codeigniter 4 shield version: dev-develop
Beta Was this translation helpful? Give feedback.
All reactions