2

Using Drush 9, I am trying to automate the creation of a role and I need to assign permissions to it. I see that I can use drush role-add-perm to do the assignment itself, but I can't find a command to actually give me the permissions supplied by the enabled modules.

It looks like this was doable in older versions of Drush, but I'm not sure Drush 9 has equivalent commands.

Thanks!

1 Answer 1

5

You could use drush cim and create a yml for your role like for example

langcode: en
status: true
dependencies: {  }
id: myrole
label: 'My super Role'
weight: 1
is_admin: false
permissions: 
  - 'whatever 1'
  - 'whatever 2'

And if you don't know what perms your module brings, you could use that simple eval code with drush:

drush php-eval '$p = Drupal::service("user.permissions")->getPermissions(); foreach ($p as $k => $x) print $k." : ".$x["provider"]."\n";'
2
  • And you grep the possible permissions of moduleX from modules/custom/moduleX/moduleX.permissions.yml Sep 13, 2019 at 15:21
  • This will be nice to be provided out-the-box by Drush, the same as it's done with roles.
    – d70rr3s
    Sep 7, 2022 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.