From 396719585c971616dc5097f99729e5237a90c37d Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 23 Dec 2014 13:29:28 +0100 Subject: [PATCH] Issue #2393577 by vladan.me, Berdir: Access issue with default settings set to disabled --- core/modules/contact/src/Access/ContactPageAccess.php | 10 ++++++---- core/modules/contact/src/Tests/ContactPersonalTest.php | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/modules/contact/src/Access/ContactPageAccess.php b/core/modules/contact/src/Access/ContactPageAccess.php index b0574da99d..e1a52945cb 100644 --- a/core/modules/contact/src/Access/ContactPageAccess.php +++ b/core/modules/contact/src/Access/ContactPageAccess.php @@ -83,11 +83,13 @@ public function access(UserInterface $user, AccountInterface $account) { return $access; } - // If the requested user has disabled their contact form, do not allow users - // to contact them. + // Load preference of the requested user. $account_data = $this->userData->get('contact', $contact_account->id(), 'enabled'); - if (isset($account_data) && empty($account_data)) { - return $access; + if (isset($account_data)) { + // Forbid access if the requested user has disabled their contact form. + if (empty($account_data)) { + return $access; + } } // If the requested user did not save a preference yet, deny access if the // configured default is disabled. diff --git a/core/modules/contact/src/Tests/ContactPersonalTest.php b/core/modules/contact/src/Tests/ContactPersonalTest.php index b92ad85e77..1b5efd801d 100644 --- a/core/modules/contact/src/Tests/ContactPersonalTest.php +++ b/core/modules/contact/src/Tests/ContactPersonalTest.php @@ -185,6 +185,15 @@ function testPersonalContactAccess() { $this->drupalPostForm(NULL, array('contact' => TRUE), t('Save')); $this->assertFieldChecked('edit-contact--2'); $this->assertTrue(\Drupal::service('user.data')->get('contact', $this->webUser->id(), 'enabled'), 'Personal contact form enabled'); + + // Test with disabled global default contact form in combination with a user + // that has the contact form enabled. + \Drupal::config('contact.settings')->set('user_default_enabled', FALSE)->save(); + $this->contactUser = $this->drupalCreateUser(); + \Drupal::service('user.data')->set('contact', $this->contactUser->id(), 'enabled', 1); + + $this->drupalGet('user/' . $this->contactUser->id() . '/contact'); + $this->assertResponse(200); } /** -- GitLab