codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
351 stars 123 forks source link

Can't configure AuthGroups in different namespace #1072

Closed krishna-gujjjar closed 4 months ago

krishna-gujjjar commented 4 months ago

PHP Version

8.3.0

CodeIgniter4 Version

4.4.6

Shield Version

1.0.2

Which operating systems have you tested for this bug?

macOS

Which server did you use?

apache

Database

MySQL 5.7.39

Did you customize Shield?

No

What happened?

Can't get the authGroups permissions defined in the /modules/Auth/Config/AuthGroups.

when i request a list of permissions using setting('AuthGroups.permissions'), i expected all the permissions array but i get default permission array defined in AuthGroup.

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',
];

Steps to Reproduce

I am using codeigniter4/shield as Auth modules.

I have /modules/Auth/Config/AuthGroups with some of dummy permission. this is the core config for my all base auth group configuration.

namespace Modules\Auth\Config;

// other stuffs
use CodeIgniter\Shield\Config\AuthGroups as ShieldAuthGroups;

class AuthGroups extends ShieldAuthGroups
{
    // other stuffs
    public array $permissions = [
        'admin.access'        => 'Can access the sites admin area',
        'admin.settings'      => 'Can access the main site settings',
        'groups.settings'     => 'Can access the groups settings',
        'groups.edit'         => 'Can edit existing user groups',
        'users.list'          => 'Can view a list of users in the system',
        'users.manage-admins' => 'Can manage other admins',
        'users.view'          => 'Can view user details',
        'users.create'        => 'Can create new non-admin users',
        'users.edit'          => 'Can edit existing non-admin users',
        'users.delete'        => 'Can delete existing non-admin users',
        'users.settings'      => 'Can manage User settings in admin area',
        'beta.access'         => 'Can access beta-level features',
        'site.viewOffline'    => 'Can view the site even when in "offline" mode',
        'widgets.settings'    => 'Can view the settings for site Widgets',
        'consent.settings'    => 'Can view the settings for the Consent module',
        'recycler.view'       => 'Can view the Recycler area',
        'logs.view'           => 'Can view the logs',
        'logs.manage'         => 'Can manage the logs',
        'me.edit'             => 'Can edit user\'s own settings',
        'me.security'         => 'Can change user\'s own password',
    ];
    // other stuffs
}

i have another config class called /modules/Languages/Config/AuthGroups. this is the auth group config where i only defined the language modules related auth group & permissions.

namespace Modules\Languages\Config;

// other stuffs
use Modules\Auth\Config\AuthGroups as ConfigAuthGroups;

class AuthGroups extends ConfigAuthGroups
{
    protected array $permissions = [
        'languages.access'       => 'Can access the Languages Files Management Module',
        'languages.view'         => 'Can view all language files',
        'languages.view_single'  => 'Can view individual language files',
        'languages.create'       => 'Can create new language files',
        'languages.edit'         => 'Can edit existing language files',
        'languages.edit_content' => 'Can edit translations within a language file',
        'languages.edit_meta'    => 'Can edit metadata of a language file (e.g., name, locale)',
        'languages.delete'       => 'Can delete language files',
        'languages.manage'       => 'Can manage all aspects of language files (create, edit, delete)',
        'languages.upload'       => 'Can upload language files',
        'languages.download'     => 'Can download language files',
        'languages.import'       => 'Can import translations from an external source',
        'languages.export'       => 'Can export translations to an external source',
        'languages.approve'      => 'Can approve or reject changes made to a language file (for workflows)',

    ];
}

Steps

// other stuffs use CodeIgniter\Shield\Config\AuthGroups as ShieldAuthGroups;

class AuthGroups extends ShieldAuthGroups { // other stuffs public array $permissions = [ 'admin.access' => 'Can access the sites admin area', 'admin.settings' => 'Can access the main site settings', 'groups.settings' => 'Can access the groups settings', 'groups.edit' => 'Can edit existing user groups', 'users.list' => 'Can view a list of users in the system', 'users.manage-admins' => 'Can manage other admins', 'users.view' => 'Can view user details', 'users.create' => 'Can create new non-admin users', 'users.edit' => 'Can edit existing non-admin users', 'users.delete' => 'Can delete existing non-admin users', 'users.settings' => 'Can manage User settings in admin area', 'beta.access' => 'Can access beta-level features', 'site.viewOffline' => 'Can view the site even when in "offline" mode', 'widgets.settings' => 'Can view the settings for site Widgets', 'consent.settings' => 'Can view the settings for the Consent module', 'recycler.view' => 'Can view the Recycler area', 'logs.view' => 'Can view the logs', 'logs.manage' => 'Can manage the logs', 'me.edit' => 'Can edit user\'s own settings', 'me.security' => 'Can change user\'s own password', ]; // other stuffs }


the methodology is inspired by [Bonfire 2 Auth Module](https://github.com/lonnieezell/Bonfire2/blob/develop/src/Auth/Config/AuthGroups.php)

### Expected Output

```php
[
    'admin.access'           => 'Can access the sites admin area',
    'admin.settings'         => 'Can access the main site settings',
    'groups.settings'        => 'Can access the groups settings',
    'groups.edit'            => 'Can edit existing user groups',
    'users.list'             => 'Can view a list of users in the system',
    'users.manage-admins'    => 'Can manage other admins',
    'users.view'             => 'Can view user details',
    'users.create'           => 'Can create new non-admin users',
    'users.edit'             => 'Can edit existing non-admin users',
    'users.delete'           => 'Can delete existing non-admin users',
    'users.settings'         => 'Can manage User settings in admin area',
    'beta.access'            => 'Can access beta-level features',
    'site.viewOffline'       => 'Can view the site even when in "offline" mode',
    'widgets.settings'       => 'Can view the settings for site Widgets',
    'consent.settings'       => 'Can view the settings for the Consent module',
    'recycler.view'          => 'Can view the Recycler area',
    'logs.view'              => 'Can view the logs',
    'logs.manage'            => 'Can manage the logs',
    'me.edit'                => 'Can edit user\'s own settings',
    'me.security'            => 'Can change user\'s own password',
    'languages.access'       => 'Can access the Languages Files Management Module',
    'languages.view'         => 'Can view all language files',
    'languages.view_single'  => 'Can view individual language files',
    'languages.create'       => 'Can create new language files',
    'languages.edit'         => 'Can edit existing language files',
    'languages.edit_content' => 'Can edit translations within a language file',
    'languages.edit_meta'    => 'Can edit metadata of a language file (e.g., name, locale)',
    'languages.delete'       => 'Can delete language files',
    'languages.manage'       => 'Can manage all aspects of language files (create, edit, delete)',
    'languages.upload'       => 'Can upload language files',
    'languages.download'     => 'Can download language files',
    'languages.import'       => 'Can import translations from an external source',
    'languages.export'       => 'Can export translations to an external source',
    'languages.approve'      => 'Can approve or reject changes made to a language file (for workflows)',
];

Anything else?

If i am doing something wrong, please correct me.