Jump to content

Roles, permissions, access creation


gornycreative
 Share

Recommended Posts

Hi @bernhard I'm trying to include custom roles, permissions and access via the migrate() method array setup.

Looking at the source this *seems* like it should work, but for some reason I get an error:

Method RockMigrations::setRolePermissions does not exist or is not callable in this context

$rm->migrate([
    "roles" => [
        'copy_editor' => [
            'permissions' => [
                'page-view',
                'page-edit',
                'page-delete',
                'page-edit-front',
                'page-edit-recent',
                'page-move',
                'page-sort',
                'comments-manager',
                'profile-edit',
            ],
            'access' => [
                'home' => [
                    'view',
                ],
            ],
        ],
        'layout_editor' => [
            'permissions' => [
                'page-view',
                'page-edit',
                'page-delete',
                'page-edit-recent',
                'page-move',
                'page-sort',
                'page-template',
                'logs-view',
                'profile-edit',
            ],
            'access' => [
                'home' => [
                    'view',
                    'edit',
                ],
            ],
        ],
    ],
]);

// I include fields and templates and other things later - I will likely move roles AFTER templates once this is working.

Is there something I am missing here?

  • Like 1
Link to comment
Share on other sites

22 minutes ago, gornycreative said:

Is there something I am missing here?

I guess you are not missing anything but RockMigrations is missing the "setRolePermissions" method.

I've done some aggressive cleanup when transitioning from RM1 to RM2 to make sure that RM2 does only have methods we really need to have.

Could you please copy https://github.com/baumrock/RockMigrations1/blob/1ee9f9eb4afaf83529bcedf443b31dd63a5403c8/RockMigrations1.module.php#L2135-L2145 over to RockMigrations.module.php and let me know if that solves the issue?

  • Thanks 1
Link to comment
Share on other sites

Hi @gornycreative did you read the docblock?

Quote

* Set permissions for given role
* This will remove all permissions that are not listed in the array!
* If you just want to add permissions use addPermissionsToRole()

Does that solve your need?

In general RM has the convention that SET means set, which will wipe old settings. Or at least I tried to have that convention. setTemplateFields works differently and has that parameter that you are suggesting.

For fields in migrate() we also have the "fields-" key (with minus sign), that makes setTemplateFields remove fields that are not listed in the array.

Similar to that we could have "permissions" and "permissions-" which will in the first case add all listed permissions and in the second remove non-listed ones.

Link to comment
Share on other sites

Hey @gornycreative I've just pushed that do the dev branch and it will be available in the next release of RockMigrations.

I have added "permissions-" and "access-" keys to the migrate() method.

On 4/6/2023 at 10:51 AM, bernhard said:

In general RM has the convention that SET means set, which will wipe old settings. Or at least I tried to have that convention. setTemplateFields works differently and has that parameter that you are suggesting.

I have to correct myself here. Actually the default is that RM keeps existing values! That's in line with how it works in general. It only add's things or overwrites them but it does not remove anything unless you tell it to.

Could you please grab the dev branch and let me know if everything works as expected? https://github.com/baumrock/RockMigrations/tree/dev

  • Like 1
Link to comment
Share on other sites

5 hours ago, bernhard said:

Actually the default is that RM keeps existing values! That's in line with how it works in general. It only add's things or overwrites them but it does not remove anything unless you tell it to.

This is what I remember you saying in the 'adding RM to existing products' video but I know as this is a work in progress things could have changed.

I'm in the middle of applying gebeer's Repeater Matrix migration methods to something I am working on but when I am done I will take a look at the dev branch and try some things.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...