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

greg.1.anderson’s picture

StatusFileSize
new4.51 KB

Slight improvement: print nothing in pm-enabled if there are no permissions defined in the module.

moshe weitzman’s picture

Status: Needs review » Needs work

In 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)

greg.1.anderson’s picture

StatusFileSize
new4.98 KB

You 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.

jonhattan’s picture

I think it's more practical to print the url admin/people/permissions#module-modulename if the module provide permissions. In this trend, would be nice to also print the url to configure the module ("configure" key in .info).

greg.1.anderson’s picture

I don't think that Drush should print URLs at pm-enable time; it would be okay to put this information in pm-info, though.

greg.1.anderson’s picture

Created #1649598: Bring drush_role into Drush core for bringing drush_role into Drush core.

greg.1.anderson’s picture

Status: Needs work » Needs review
StatusFileSize
new4.35 KB

Re-rolled now that drush_role is in core.

moshe weitzman’s picture

I'm undecided about this. I'd love some input about how suitable it is for core to print this out by default.

greg.1.anderson’s picture

StatusFileSize
new9.99 KB

I 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.

greg.1.anderson’s picture

Version: » 7.x-5.8
StatusFileSize
new11.2 KB

Slight 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.

greg.1.anderson’s picture

No 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.

 --- a/commands/pm/pm.drush.inc
+++ b/commands/pm/pm.drush.inc
@@ -892,9 +892,14 @@ function drush_pm_enable() {
   // Inform the user of final status.
   $result_extensions = drush_get_named_extensions_list($extensions);
   $problem_extensions = array();
+  $role = drush_role_get_class();
   foreach ($result_extensions as $name => $extension) {
     if ($extension->status) {
       drush_log(dt('!extension was enabled successfully.', array('!extension' => $extension->name)), 'ok');
+      $perms = $role->getModulePerms($extension->name);
+      if (!empty($perms)) {
+        drush_print(dt('!extension defines the following permissions: !perms', array('!extension' => $extension->name, '!perms' => implode(', ', $perms))));
+      }
     }
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

It works on D6/D7/D8? If so, lets commit the whole patch. Thanks!

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Yep, works for all three supported versions of Drupal. Committed; thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.