From 8caad0ce87005b1aa305a21bb8db247aeab7086f Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 7 Oct 2017 11:57:02 +1300 Subject: [PATCH] CRM-21272 (preliminary tidy up) move definition of isUserRegistrationPermitted to CMS classes --- CRM/Core/BAO/CMSUser.php | 17 +++-------------- CRM/Utils/System/Base.php | 9 +++++++++ CRM/Utils/System/Drupal8.php | 10 ++++++++++ CRM/Utils/System/DrupalBase.php | 10 ++++++++++ CRM/Utils/System/Joomla.php | 11 +++++++++++ CRM/Utils/System/WordPress.php | 10 ++++++++++ 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/CRM/Core/BAO/CMSUser.php b/CRM/Core/BAO/CMSUser.php index 141ba941ed..3b23a1f746 100644 --- a/CRM/Core/BAO/CMSUser.php +++ b/CRM/Core/BAO/CMSUser.php @@ -91,18 +91,8 @@ class CRM_Core_BAO_CMSUser { $isJoomla = ucfirst($config->userFramework) == 'Joomla' ? TRUE : FALSE; $isWordPress = $config->userFramework == 'WordPress' ? TRUE : FALSE; - //if CMS is configured for not to allow creating new CMS user, - //don't build the form,Fixed for CRM-4036 - if ($isJoomla) { - $userParams = JComponentHelper::getParams('com_users'); - if (!$userParams->get('allowUserRegistration')) { - return FALSE; - } - } - elseif ($isDrupal && !variable_get('user_register', TRUE)) { - return FALSE; - } - elseif ($isWordPress && !get_option('users_can_register')) { + if (!$config->userSystem->isUserRegistrationPermitted()) { + // Do not build form if CMS is not configured to allow creating users. return FALSE; } @@ -111,8 +101,7 @@ class CRM_Core_BAO_CMSUser { } // $cms is true when there is email(primary location) is set in the profile field. - $session = CRM_Core_Session::singleton(); - $userID = $session->get('userID'); + $userID = CRM_Core_Session::singleton()->get('userID'); $showUserRegistration = FALSE; if ($action) { $showUserRegistration = TRUE; diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 2191ede2ad..af93951275 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -395,6 +395,15 @@ abstract class CRM_Utils_System_Base { return FALSE; } + /** + * Check if user registration is permitted. + * + * @return bool + */ + public function isUserRegistrationPermitted() { + return FALSE; + } + /** * Get user login URL for hosting CMS (method declared in each CMS system class) * diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 22a5faee22..9053629842 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -526,6 +526,16 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { return \Drupal::currentUser()->isAuthenticated(); } + /** + * @inheritDoc + */ + public function isUserRegistrationPermitted() { + if (\Drupal::config('user.settings')->get('register') == 'admin_only') { + return FALSE; + } + return TRUE; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index cd0ca13c51..848c446b35 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -414,6 +414,16 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { return defined('VERSION') ? VERSION : 'Unknown'; } + /** + * @inheritDoc + */ + public function isUserRegistrationPermitted() { + if (!variable_get('user_register', TRUE)) { + return FALSE; + } + return TRUE; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index 5d7b826457..2ce306e306 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -578,6 +578,17 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { return ($user->guest) ? FALSE : TRUE; } + /** + * @inheritDoc + */ + public function isUserRegistrationPermitted() { + $userParams = JComponentHelper::getParams('com_users'); + if (!$userParams->get('allowUserRegistration')) { + return FALSE; + } + return TRUE; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 579f647d28..b3ce465567 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -609,6 +609,16 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { return $isloggedIn; } + /** + * @inheritDoc + */ + public function isUserRegistrationPermitted() { + if (!get_option('users_can_register')) { + return FALSE; + } + return TRUE; + } + /** * @return mixed */ -- 2.25.1