From 0961b00c3d3f4649785ba11fe0dd51e13e8d1dd7 Mon Sep 17 00:00:00 2001 From: webchick Date: Sat, 7 Jul 2012 13:47:03 -0700 Subject: Issue #1306424 by tim.plunkett, ankur, sun: Fixed URL path /admin/structure/trigger causes error. --- modules/trigger/trigger.admin.inc | 2 +- modules/trigger/trigger.module | 24 +++++++++++++++++++++++- modules/trigger/trigger.test | 29 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) (limited to 'modules/trigger') diff --git a/modules/trigger/trigger.admin.inc b/modules/trigger/trigger.admin.inc index 447d0dc07..5b607c85d 100644 --- a/modules/trigger/trigger.admin.inc +++ b/modules/trigger/trigger.admin.inc @@ -53,7 +53,7 @@ function trigger_assign($module_to_display = NULL) { * @ingroup forms */ function trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL) { - if (!($hook && $aid)) { + if (!isset($hook, $aid)) { drupal_goto('admin/structure/trigger'); } diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index 82d117272..aeb1211c9 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -65,13 +65,35 @@ function trigger_menu() { 'description' => 'Unassign an action from a trigger.', 'page callback' => 'drupal_get_form', 'page arguments' => array('trigger_unassign'), - 'access arguments' => array('administer actions'), + // Only accessible if there are any actions that can be unassigned. + 'access callback' => 'trigger_menu_unassign_access', + // Only output in the breadcrumb, not in menu trees. + 'type' => MENU_VISIBLE_IN_BREADCRUMB, 'file' => 'trigger.admin.inc', ); return $items; } +/** + * Access callback: Determines if triggers can be unassigned. + * + * @return bool + * TRUE if there are triggers that the user can unassign, FALSE otherwise. + * + * @see trigger_menu() + */ +function trigger_menu_unassign_access() { + if (!user_access('administer actions')) { + return FALSE; + } + $count = db_select('trigger_assignments') + ->countQuery() + ->execute() + ->fetchField(); + return $count > 0; +} + /** * Implements hook_trigger_info(). * diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test index 138de6281..829e1898b 100644 --- a/modules/trigger/trigger.test +++ b/modules/trigger/trigger.test @@ -740,3 +740,32 @@ class TriggerOrphanedActionsTestCase extends DrupalWebTestCase { $this->assertRaw(t('!post %title has been updated.', array('!post' => 'Basic page', '%title' => $edit["title"])), t('Make sure the Basic page can be updated with the missing trigger function.')); } } + +/** + * Tests the unassigning of triggers. + */ +class TriggerUnassignTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Trigger unassigning', + 'description' => 'Tests the unassigning of triggers.', + 'group' => 'Trigger', + ); + } + + function setUp() { + parent::setUp('trigger', 'trigger_test'); + $web_user = $this->drupalCreateUser(array('administer actions')); + $this->drupalLogin($web_user); + } + + /** + * Tests an attempt to unassign triggers when none are assigned. + */ + function testUnassignAccessDenied() { + $this->drupalGet('admin/structure/trigger/unassign'); + $this->assertResponse(403, 'If there are no actions available, return access denied.'); + } + +} -- cgit v1.2.3