Welcome Guest, Not a member yet? Register   Sign In
CI4 Shield, Users, Groups, Permissions managment
#1
Question 

Hi
I want to make an admin panel like Users managment ( list/add/edit/update/delete ) and same for Groups and Permissions. As i saw from Shield docs there is no solution for this, only assign groups and permission from Shield functions.

Shield\Config\AuthGroups config class
PHP Code:
public array $groups = [
    'superadmin' => [
        'title'      => 'Super Admin',
        'description' => 'Optional description of the group.',
    ],
]; 
same as permissions 
PHP Code:
public array $permissions = [
    'admin.access'        => 'Can access the sites admin area',
    'admin.settings'      => 'Can access the main site settings',
    'users.manage-admins' => 'Can manage other admins',
    'users.create'        => 'Can create new non-admin users',
    'users.edit'          => 'Can edit existing non-admin users',
    'users.delete'        => 'Can delete existing non-admin users',
    'beta.access'        => 'Can access beta-level features'
]; 
Barrier with this kind of groups and permission i get into is that i will have system for maange Employees, Vehicles, Users, WebsiteSettings, and many other controllers. So this means i would need to add each controller.method to the file and permissions, but i want to make this dynamic so lets say Admin can create groups and permissions and save in database.

Is that means if i don't use config based permission and groups i cannot use a Shield and hes functions to check if user have permission to access controller/method ?
Reply
#2

I do not know Shield, but you can use the constructor in the configs and call something DB::getGroups()/File::readGroups() to update the $this->groups. No, it's dangerous.
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

You can use the settings service to save your changes in the database.
Reply
#4

Settings

In place of the CodeIgniter config() helper, Shield uses the official Settings library.
This provides a way to save any Config class values to the database if you want to modify them,
but falls back on the standard Config class if nothing is found in the database.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(03-13-2025, 09:23 AM)InsiteFX Wrote: Settings

In place of the CodeIgniter config() helper, Shield uses the official Settings library.
This provides a way to save any Config class values to the database if you want to modify them,
but falls back on the standard Config class if nothing is found in the database.

Ok i managed to install Settings library from here https://github.com/codeigniter4/settings...me-ov-file and managed to add setting to database using service. Values are saved in database like array same as in config AuthGroups. 

PHP Code:
service('settings')->set('AuthGroups.permissions'$permissions);

service('settings')->set('AuthGroups.groups'$groups); 

To get values or update value i know i can use database query builder or update through service. Now my question is do i check for permissions and groups like i did before
PHP Code:
if (auth()->user()->inGroup('admin''superadmin')) 
, or do i need to get setting from database, and do i need to make some extra configuration in order to read settings from database, like modify some files or delete permission and groups array values from AuthGroups file ? 


This is and image from database table settings 

[Image: Screenshot-1.jpg]
Reply
#6

Check this post:
https://forum.codeigniter.com/showthread.php?tid=91779
Reply
#7

Thanks @JustJohnQ and @InsiteFX for right instructions to solve this issues.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB