diff --git a/linkchecker.install b/linkchecker.install
index 7cb7249..3195152 100644
--- a/linkchecker.install
+++ b/linkchecker.install
@@ -11,6 +11,13 @@
function linkchecker_install() {
$linkchecker_default_impersonate_user = user_load(1);
variable_set('linkchecker_impersonate_user', $linkchecker_default_impersonate_user->name);
+ $linkchecker_default_permissions = array(
+ 'see contextual messages',
+ );
+ $roles = user_roles(TRUE);
+ foreach ($roles as $key => $value) {
+ user_role_grant_permissions($key, $linkchecker_default_permissions);
+ }
}
/**
@@ -454,6 +461,20 @@ function linkchecker_update_7011() {
}
}
+/**
+ * Issue #1886890: Grant new permission to see broken link messages on node edit forms.
+ */
+function linkchecker_update_7012() {
+ $linkchecker_default_permissions = array(
+ 'see contextual messages',
+ );
+ $roles = user_roles(TRUE);
+ foreach ($roles as $key => $value) {
+ user_role_grant_permissions($key, $linkchecker_default_permissions);
+ }
+ return t('Added permission to see broken link messages in context on edit forms.');
+}
+
if (!function_exists('array_replace')) {
/**
diff --git a/linkchecker.module b/linkchecker.module
index 4a84f87..8780fec 100644
--- a/linkchecker.module
+++ b/linkchecker.module
@@ -73,6 +73,10 @@ function linkchecker_permission() {
'title' => t('Edit link settings'),
'description' => t('Allows users to edit broken link settings.'),
),
+ 'see contextual messages' => array(
+ 'title' => t('See broken link messages in context'),
+ 'description' => t('Allows users to see messages about broken links on the node, block, and comment edit pages.'),
+ ),
);
}
@@ -818,7 +822,7 @@ function _linkchecker_status_handling(&$response, $link) {
*/
function linkchecker_node_prepare($node) {
// Node edit tab is viewed.
- if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit' && isset($node->nid)) {
+ if (user_access('see contextual messages') && arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit' && isset($node->nid)) {
// Show a message on node edit page if a link check failed once or more.
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
$links = db_query('SELECT ll.* FROM {linkchecker_node} ln INNER JOIN {linkchecker_link} ll ON ln.lid = ll.lid WHERE ln.nid = :nid AND ll.fail_count > :fail_count AND ll.status = :status AND ll.code NOT IN (:codes)', array(':nid' => $node->nid, ':fail_count' => 0, ':status' => 1, ':codes' => $ignore_response_codes));
@@ -921,7 +925,7 @@ function linkchecker_form_alter(&$form, &$form_state, $form_id) {
case 'block_admin_configure':
// When displaying the form, show the broken links warning.
- if (empty($form_state['input']) && is_numeric(arg(5))) {
+ if (user_access('see contextual messages') && empty($form_state['input']) && is_numeric(arg(5))) {
// Show a message on custom block edit page if a link check failed once
// or more often.
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
@@ -950,7 +954,7 @@ function linkchecker_form_alter(&$form, &$form_state, $form_id) {
function linkchecker_form_comment_form_alter(&$form, &$form_state, $form_id) {
// When displaying the form as 'view' or 'preview', show the broken links
// warning.
- if ((empty($form_state['input']) || (isset($form_state['input']['op']) && $form_state['input']['op'] == t('Preview'))) && arg(0) == 'comment' && is_numeric(arg(1)) && arg(2) == 'edit') {
+ if (user_access('see contextual messages') && (empty($form_state['input']) || (isset($form_state['input']['op']) && $form_state['input']['op'] == t('Preview'))) && arg(0) == 'comment' && is_numeric(arg(1)) && arg(2) == 'edit') {
// Show a message on comment edit page if a link check failed once or
// more often.
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
diff --git a/linkchecker.test b/linkchecker.test
index 81ecaff..d2f546c 100644
--- a/linkchecker.test
+++ b/linkchecker.test
@@ -381,6 +381,8 @@ EOT;
class LinkCheckerInterfaceTest extends DrupalWebTestCase {
+ public $contextPermission = TRUE;
+
public static function getInfo() {
return array(
'name' => t('Link checker interface tests'),
@@ -412,6 +414,8 @@ class LinkCheckerInterfaceTest extends DrupalWebTestCase {
'create url aliases',
// Content filter permissions.
filter_permission_name($full_html_format),
+ // Broken link messages in context permissions.
+ 'see contextual messages',
);
$user = $this->drupalCreateUser($permissions);
@@ -480,14 +484,24 @@ class LinkCheckerInterfaceTest extends DrupalWebTestCase {
$status = '301';
$this->setLinkAsBroken($url1, $status, $fail_count);
$this->drupalGet('node/' . $node->nid . '/edit');
- $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed once found.'));
+ if($this->contextPermission) {
+ $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed once found.'));
+ }
+ else {
+ $this->assertNoRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed once text hidden based on permissions.'));
+ }
// Set link as failed multiple times.
$fail_count = 4;
$status = '404';
$this->setLinkAsBroken($url1, $status, $fail_count);
$this->drupalGet('node/' . $node->nid . '/edit');
- $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed multiple times found.'));
+ if($this->contextPermission) {
+ $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed multiple times found.'));
+ }
+ else {
+ $this->assertNoRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed multiple times text hidden based on permissions.'));
+ }
}
public function testLinkCheckerCreateBlockWithBrokenLinks() {
@@ -530,14 +544,24 @@ class LinkCheckerInterfaceTest extends DrupalWebTestCase {
$status = '301';
$this->setLinkAsBroken($url1, $status, $fail_count);
$this->drupalGet('admin/structure/block/manage/block/' . $bid . '/configure');
- $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed once found.'));
+ if($this->contextPermission) {
+ $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed once found.'));
+ }
+ else {
+ $this->assertNoRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed once text hidden based on permissions.'));
+ }
// Set link as failed multiple times.
$fail_count = 4;
$status = '404';
$this->setLinkAsBroken($url1, $status, $fail_count);
$this->drupalGet('admin/structure/block/manage/block/' . $bid . '/configure');
- $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed multiple times found.'));
+ if($this->contextPermission) {
+ $this->assertRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed multiple times found.'));
+ }
+ else {
+ $this->assertNoRaw(format_plural($fail_count, 'Link check of @url failed once (status code: @code).', 'Link check of @url failed @count times (status code: @code).', array('@url' => $url1, '@code' => $status)), t('Link check failed multiple times text hidden based on permissions.'));
+ }
}
/**
@@ -575,6 +599,52 @@ class LinkCheckerInterfaceTest extends DrupalWebTestCase {
}
}
+
+class LinkCheckerPermissionTest extends LinkCheckerInterfaceTest {
+
+ public $contextPermission = FALSE;
+
+ public static function getInfo() {
+ return array(
+ 'name' => t('Link checker permission tests'),
+ 'description' => t('Test the contextual links permission.'),
+ 'group' => 'Link checker',
+ );
+ }
+
+ public function setUp() {
+ DrupalWebTestCase::setUp('block', 'linkchecker', 'path');
+ // @todo: Add comment interface test.
+ // parent::setUp('block', 'comment', 'linkchecker', 'path');
+
+ $full_html_format = filter_format_load('full_html');
+ $permissions = array(
+ // Block permissions.
+ 'administer blocks',
+ // Comment permissions.
+ 'administer comments',
+ 'access comments',
+ 'post comments',
+ 'skip comment approval',
+ 'edit own comments',
+ // Node permissions.
+ 'create page content',
+ 'edit own page content',
+ // Path aliase permissions.
+ 'administer url aliases',
+ 'create url aliases',
+ // Content filter permissions.
+ filter_permission_name($full_html_format),
+ );
+
+ $user = $this->drupalCreateUser($permissions);
+ $this->drupalLogin($user);
+ // make sure authenticated user cannot see contextual messages
+ user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array('see contextual messages'));
+ }
+}
+
+
/**
* Test case for impersonating users.
*