It is a common aspect of many Drupal modules that certain key functionality is absolutely invisible if the appropriate permissions are not set for the active user. This is by design, and highly desirable behavior, and yet, even after years of using Drupal, I occasionally end up scratching my head for a few minutes after enabling a module because I have forgotten about an incredibly obvious permission. This patch helps to inform or remind the user about permissions available in a module by listing them when the module is enabled.
For example:
$ drush @geni.dev en devel -y
The following extensions will be enabled: devel
Do you really want to continue? (y/n): y
devel was enabled successfully. [ok]
devel defines the following permissions: access devel information, [ok]
execute php code, switch users, display source code
This information is also added to the output of drush pm-info:
Extension : devel
Project : devel
Type : module
Title : Devel
Description : Various blocks, pages, and functions for developers.
Version : 6.x-1.26
Package : Development
Core : 6.x
PHP : 4.3.5
Status : enabled
Path : sites/all/modules/devel
Schema version : 6003
Requires : menu
Required by : project_issue_generate
Permissions Defined : access devel information, execute php code, switch
users, display source code
Comments
Comment #1
greg.1.anderson commentedSlight improvement: print nothing in pm-enabled if there are no permissions defined in the module.
Comment #2
moshe weitzman commentedIn Drupal 7, permissions have machine names that are different from labels. We should show machine names IMO. Further, I think this only makes sense of we finally do #1260992: D7 support and move that into core Drush. I support that.
Do you think we should fork a new process in drush_pm_enable() or just call $perm_fn directly there. Would be a little faster, and should be accurate since module_enable() clears all the needed caches.
Needs unit test.
"Permissions Defined" should only be initial case (lowercase the D)
Comment #3
greg.1.anderson commentedYou are right, it is not necessary to re-bootstrap the site to get an accurate list of permissions after enabling a module.
Here is an improved patch that supports D7, and does not incorrectly report "no permissions defined" for disabled modules. Since it is not possible to call hook_perm / hook_permission unless the module is enabled, pm-info merely omits the "Permissions defined" display when the module is not enabled. I didn't think it was a good idea to try to include the right file or "fake-enable" the module just to get this info.
I agree that it would be a good idea to bring drush_role into core. This patch also still needs unit tests.
Comment #4
jonhattanI think it's more practical to print the url
admin/people/permissions#module-modulenameif the module provide permissions. In this trend, would be nice to also print the url to configure the module ("configure" key in .info).Comment #5
greg.1.anderson commentedI don't think that Drush should print URLs at pm-enable time; it would be okay to put this information in pm-info, though.
Comment #6
greg.1.anderson commentedCreated #1649598: Bring drush_role into Drush core for bringing drush_role into Drush core.
Comment #7
greg.1.anderson commentedRe-rolled now that drush_role is in core.
Comment #8
moshe weitzman commentedI'm undecided about this. I'd love some input about how suitable it is for core to print this out by default.
Comment #9
greg.1.anderson commentedI can give you my impression. If you are enabling a module where you have memorized the permissions it defines, or don't care what the permissions are, then the extra output is fairly minimal, and easily ignored. A more useful case, though, is when enabling a new module, Drush will now immediately inform you of the permissions available to be set. This allows you to easily follow up with something like
drush rap editor 'new permission'. It's more efficient to set permissions up front like this than to put it off until the test phase, so I think this is a win.Here's a new patch with tests. Note that this also includes a test for pmi, and therefore also includes --pipe output for pmi. I re-factored some of the core-status output code into drush_format so that I could re-use it here.
Comment #10
greg.1.anderson commentedSlight refinement of drush_format. The difference between #9 and #10 is negligible for this patch, but will be important for a follow-up patch that I'll be submitting after this one is put to bed.
Comment #11
greg.1.anderson commentedNo feedback; shall we go ahead and commit #10, either with or without the bit that actually outputs the permission names after pm-enable (per your preference)? Even without the main functionality of the patch, the other improvements, such permissions listed in pm-info, and unit test for pm-info, should go in.
Here is the part that would be removed if output after pm-enable is not desired.
Comment #12
moshe weitzman commentedIt works on D6/D7/D8? If so, lets commit the whole patch. Thanks!
Comment #13
greg.1.anderson commentedYep, works for all three supported versions of Drupal. Committed; thanks.