gornycreative Posted April 5, 2023 Share Posted April 5, 2023 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? 1 Link to comment Share on other sites More sharing options...
bernhard Posted April 5, 2023 Share Posted April 5, 2023 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? 1 Link to comment Share on other sites More sharing options...
gornycreative Posted April 6, 2023 Author Share Posted April 6, 2023 This did work. Does it make sense to add a boolean flag here to allow for the previous roles to be retained unless it is set? I'm looking at the setTemplateAccess and thinking why not add a similar boolean here? Just food for thought. Link to comment Share on other sites More sharing options...
bernhard Posted April 6, 2023 Share Posted April 6, 2023 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 More sharing options...
gornycreative Posted April 7, 2023 Author Share Posted April 7, 2023 On 4/6/2023 at 3:51 AM, bernhard said: we could have "permissions" and "permissions-" which will in the first case add all listed permissions and in the second remove non-listed ones. This would probably be helpful. Link to comment Share on other sites More sharing options...
bernhard Posted April 7, 2023 Share Posted April 7, 2023 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 1 Link to comment Share on other sites More sharing options...
gornycreative Posted April 7, 2023 Author Share Posted April 7, 2023 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now