? trigger_hook_access-324183-13.patch
? trigger_hook_access-324183-8.patch
? sites/default/files
? sites/default/settings.php
Index: modules/trigger/trigger.api.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.api.php,v
retrieving revision 1.4
diff -u -p -r1.4 trigger.api.php
--- modules/trigger/trigger.api.php	29 May 2009 19:15:08 -0000	1.4
+++ modules/trigger/trigger.api.php	17 Aug 2009 03:28:13 -0000
@@ -122,6 +122,11 @@ function hook_action_info_alter(&$action
  *       - Inside of that array are a list of arrays keyed by hook operation.
  *         - Each of those arrays have a key of 'runs when' and a value which is
  *           an English description of the hook.
+ *     - access callback: string that will replace the default access callback
+ *       for the menu item that is created.  Default is user_access()
+ *     - access arguments: array that will replace the default access arguments
+ *       for the menu item that is created.  Default is outermost key, i.e. 
+ *       the module name.
  *
  * For example, the node_hook_info implementation has 'node' as the outermost
  * key, as that's the module it's in. Next it has 'node' as the next key,
Index: modules/trigger/trigger.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.module,v
retrieving revision 1.42
diff -u -p -r1.42 trigger.module
--- modules/trigger/trigger.module	12 Aug 2009 12:36:05 -0000	1.42
+++ modules/trigger/trigger.module	17 Aug 2009 03:28:13 -0000
@@ -92,7 +92,8 @@ function trigger_menu() {
     if (in_array($module, array('node', 'comment', 'user', 'system', 'taxonomy'))) {
       continue;
     }
-    $info = db_select('system')
+    $info = db_select('system', 's')
+      ->fields('s', array('info'))
       ->condition('name', $module)
       ->execute()
       ->fetchField();
@@ -102,7 +103,8 @@ function trigger_menu() {
       'title' => $nice_name,
       'page callback' => 'trigger_assign',
       'page arguments' => array($module),
-      'access arguments' => array($module),
+      'access arguments' => isset($hook['access arguments']) ? $hook['access arguments'] : array($module),
+      'access callback' => isset($hook['access callback']) ? $hook['access callback'] : 'trigger_access_check',
       'type' => MENU_LOCAL_TASK,
     );
   }
@@ -163,8 +165,11 @@ function trigger_forms() {
   $hooks = module_invoke_all('hook_info');
   foreach ($hooks as $module => $info) {
     foreach ($hooks[$module] as $hook => $ops) {
-      foreach ($ops as $op => $description) {
-        $forms['trigger_' . $hook . '_' . $op . '_assign_form'] = array('callback' => 'trigger_assign_form');
+      // Ensure that the hook/op is not the menu items.
+      if (!in_array($hook, array('access callback', 'access arguments'))) {
+        foreach ($ops as $op => $description) {
+          $forms['trigger_' . $hook . '_' . $op . '_assign_form'] = array('callback' => 'trigger_assign_form');
+        }
       }
     }
   }
Index: modules/trigger/trigger.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.test,v
retrieving revision 1.15
diff -u -p -r1.15 trigger.test
--- modules/trigger/trigger.test	28 Jul 2009 19:18:08 -0000	1.15
+++ modules/trigger/trigger.test	17 Aug 2009 03:28:13 -0000
@@ -137,11 +137,11 @@ class TriggerCronTestCase extends Drupal
     // Create an administrative user.
     $test_user = $this->drupalCreateUser(array('administer actions'));
     $this->drupalLogin($test_user);
- 
+
     // Assign a non-configurable action to the cron run trigger.
     $edit = array('aid' => md5('trigger_test_system_cron_action'));
     $this->drupalPost('admin/structure/trigger/cron', $edit, t('Assign'));
- 
+
     // Assign a configurable action to the cron trigger.
     $hash = md5('trigger_test_system_cron_conf_action');
     $action_description = $this->randomName();
@@ -152,7 +152,7 @@ class TriggerCronTestCase extends Drupal
     $this->drupalPost('admin/settings/actions/configure/' . $hash, $edit, t('Save'));
     $edit = array('aid' => md5('1'));
     $this->drupalPost('admin/structure/trigger/cron', $edit, t('Assign'));
- 
+
     // Add a second configurable action to the cron trigger.
     $action_description = $this->randomName();
     $edit = array(
@@ -162,16 +162,73 @@ class TriggerCronTestCase extends Drupal
     $this->drupalPost('admin/settings/actions/configure/' . $hash, $edit, t('Save'));
     $edit = array('aid' => md5('2'));
     $this->drupalPost('admin/structure/trigger/cron', $edit, t('Assign'));
- 
+
     // Force a cron run.
     drupal_cron_run();
- 
+
     // Make sure the non-configurable action has fired.
     $action_run = variable_get('trigger_test_system_cron_action', FALSE);
     $this->assertTrue($action_run, t('Check that the cron run triggered the test action.'));
- 
+
     // Make sure that both configurable actions have fired.
     $action_run = variable_get('trigger_test_system_cron_conf_action', 0) == 2;
     $this->assertTrue($action_run, t('Check that the cron run triggered both complex actions.'));
   }
 }
+
+/**
+ * Test cron trigger.
+ */
+class TriggerPermissionTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Trigger permission page',
+      'description' => 'Various test to test permissions access to trigger administration pages.' ,
+      'group' => 'Trigger',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('trigger', 'trigger_test');
+  }
+
+  /**
+   * Test assigning access callbacks in hook_hook_info().
+   * for priviledged users
+   *
+   * This test ensures that if a module implements hook_hook_info()
+   * that any access arguments are respected properly for priviledged users.
+   */
+  function testTriggerPermissionPriviledged() {
+    // Create an administrative user.
+    $admin_user = $this->drupalCreateUser(array('trigger test permission'));
+
+    // Login priviledged user
+    $this->drupalLogin($admin_user);
+
+    // Test whether the user can access correct page
+    $path = 'admin/structure/trigger/trigger_test';
+    $this->drupalGet($path);
+    $this->assertResponse(200, t('Ensure that the privileged user can access %path.', array('%path' => $path)));
+  }
+
+  /**
+   * Test assigning access callbacks in hook_hook_info().
+   * for un-priviledged users
+   *
+   * This test ensures that if a module implements hook_hook_info()
+   * that any access arguments are respected properly for un-priviledged users.
+   */
+  function testTriggerPermissionUnpriviledged() {
+    // Create an unpriviledged user.
+    $reg_user = $this->drupalCreateUser();
+
+    // Login priviledged user
+    $this->drupalLogin($reg_user);
+
+    // Test whether the user can access correct page
+    $path = 'admin/structure/trigger/trigger_test';
+    $this->drupalGet($path);
+    $this->assertResponse(403, t('Ensure that the privileged user cannot access %path.', array('%path' => $path)));
+  }
+}
Index: modules/trigger/tests/trigger_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/tests/trigger_test.module,v
retrieving revision 1.2
diff -u -p -r1.2 trigger_test.module
--- modules/trigger/tests/trigger_test.module	31 May 2009 03:12:19 -0000	1.2
+++ modules/trigger/tests/trigger_test.module	17 Aug 2009 03:28:13 -0000
@@ -32,6 +32,44 @@ function trigger_test_action_info() {
 }
 
 /**
+ * Implementation of hook_hook_info().
+ */
+function trigger_test_hook_info() {
+  // Register a trigger point for testing permissions
+  return array(
+    'trigger_test' => array(
+      'trigger_test' => array(
+        'test_permission' => array(
+          'runs when' => t('Testing permissions.'),
+        ),
+      ),
+      'access callback' => 'trigger_test_permission_menu_callback',
+      'access arguments' => array(),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_permission().
+ */
+function trigger_test_permission() {
+  return array(
+    'trigger test permission' =>  array(
+      'title' => t('Trigger test permission'),
+      'description' => t('Permissions for testing trigger administration permissions.'),
+    ),
+  );
+}
+
+/**
+ * Menu access callback as ran through hook_hook_info().
+ */
+function trigger_test_permission_menu_callback() {
+  // Check if current user has access to the specific permissions.
+  return user_access('trigger test permission');
+}
+
+/**
  * Action fired during the "cron run" trigger test.
  */
 function trigger_test_system_cron_action() {
