From d5f1ee757351f6a82dd28e722497cdc61855a4db Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Wed, 26 Jun 2013 18:49:11 -0700 Subject: [PATCH] CRM-11861 patch plus a variety of notice fixes in relatedContact form and postProcess. Added new setting - secondDegRelPermission to SettingsGetfields.php and fixed several syntax errors in that file due to unescaped single quotes. ---------------------------------------- * CRM-11861: Allow option for second-degree relation permissions http://issues.civicrm.org/jira/browse/CRM-11861 --- CRM/Admin/Form/Setting/Miscellaneous.php | 1 + CRM/Contact/BAO/Contact/Permission.php | 54 ++++++++++++++++++- CRM/Contact/BAO/Contact/Utils.php | 6 +-- CRM/Contact/Form/RelatedContact.php | 16 +++--- CRM/Core/BAO/Block.php | 2 +- CRM/Core/Config/Variables.php | 6 +++ api/v3/examples/SettingGetfields.php | 22 ++++++-- settings/Core.setting.php | 18 ++++++- .../CRM/Admin/Form/Setting/Miscellaneous.tpl | 6 +++ 9 files changed, 114 insertions(+), 17 deletions(-) diff --git a/CRM/Admin/Form/Setting/Miscellaneous.php b/CRM/Admin/Form/Setting/Miscellaneous.php index c0704eddce..a81c2b99c0 100644 --- a/CRM/Admin/Form/Setting/Miscellaneous.php +++ b/CRM/Admin/Form/Setting/Miscellaneous.php @@ -46,6 +46,7 @@ class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting { 'versionCheck' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, ); /** diff --git a/CRM/Contact/BAO/Contact/Permission.php b/CRM/Contact/BAO/Contact/Permission.php index d8a6e6cb94..424833e63d 100644 --- a/CRM/Contact/BAO/Contact/Permission.php +++ b/CRM/Contact/BAO/Contact/Permission.php @@ -245,6 +245,7 @@ AND $operationClause LIMIT 1"; */ static function relationship($selectedContactID, $contactID = NULL) { $session = CRM_Core_Session::singleton(); + $config = CRM_Core_Config::singleton(); if (!$contactID) { $contactID = $session->get('userID'); if (!$contactID) { @@ -255,7 +256,57 @@ AND $operationClause LIMIT 1"; return TRUE; } else { - $query = " + if ($config->secondDegRelPermissions) { + $query = " +SELECT firstdeg.id +FROM civicrm_relationship firstdeg +LEFT JOIN civicrm_relationship seconddegaa + on firstdeg.contact_id_a = seconddegaa.contact_id_b + and seconddegaa.is_permission_b_a = 1 + and firstdeg.is_permission_b_a = 1 + and seconddegaa.is_active = 1 +LEFT JOIN civicrm_relationship seconddegab + on firstdeg.contact_id_a = seconddegab.contact_id_a + and seconddegab.is_permission_a_b = 1 + and firstdeg.is_permission_b_a = 1 + and seconddegab.is_active = 1 +LEFT JOIN civicrm_relationship seconddegba + on firstdeg.contact_id_b = seconddegba.contact_id_b + and seconddegba.is_permission_b_a = 1 + and firstdeg.is_permission_a_b = 1 + and seconddegba.is_active = 1 +LEFT JOIN civicrm_relationship seconddegbb + on firstdeg.contact_id_b = seconddegbb.contact_id_a + and seconddegbb.is_permission_a_b = 1 + and firstdeg.is_permission_a_b = 1 + and seconddegbb.is_active = 1 +WHERE + ( + ( firstdeg.contact_id_a = %1 AND firstdeg.contact_id_b = %2 AND firstdeg.is_permission_a_b = 1 ) + OR ( firstdeg.contact_id_a = %2 AND firstdeg.contact_id_b = %1 AND firstdeg.is_permission_b_a = 1 ) + OR ( + firstdeg.contact_id_a = %1 AND seconddegba.contact_id_a = %2 + AND (seconddegba.contact_id_a NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)) + ) + OR ( + firstdeg.contact_id_a = %1 AND seconddegbb.contact_id_b = %2 + AND (seconddegbb.contact_id_b NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)) + ) + OR ( + firstdeg.contact_id_b = %1 AND seconddegab.contact_id_b = %2 + AND (seconddegab.contact_id_b NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)) + ) + OR ( + firstdeg.contact_id_b = %1 AND seconddegaa.contact_id_a = %2 AND (seconddegaa.contact_id_a NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)) + ) + ) + AND (firstdeg.contact_id_a NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)) + AND (firstdeg.contact_id_b NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)) + AND ( firstdeg.is_active = 1) + "; + } + else { + $query = " SELECT id FROM civicrm_relationship WHERE (( contact_id_a = %1 AND contact_id_b = %2 AND is_permission_a_b = 1 ) OR @@ -264,6 +315,7 @@ WHERE (( contact_id_a = %1 AND contact_id_b = %2 AND is_permission_a_b = 1 ) OR (contact_id_b NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)) AND ( civicrm_relationship.is_active = 1 ) "; + } $params = array(1 => array($contactID, 'Integer'), 2 => array($selectedContactID, 'Integer'), ); diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 9b6148896e..0dcbb17365 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -510,11 +510,7 @@ WHERE id={$contactId}; "; $form->assign('relatedOrganizationFound', TRUE); } - $isRequired = FALSE; - if (CRM_Utils_Array::value('is_for_organization', $form->_values) == 2) { - $isRequired = TRUE; - } - $form->add('text', 'organization_name', ts('Organization Name'), $attributes['organization_name'], $isRequired); + $form->add('text', 'organization_name', ts('Organization Name'), $attributes['organization_name'], TRUE); break; case 'Household': diff --git a/CRM/Contact/Form/RelatedContact.php b/CRM/Contact/Form/RelatedContact.php index a52d6b6761..2fc33c31a6 100644 --- a/CRM/Contact/Form/RelatedContact.php +++ b/CRM/Contact/Form/RelatedContact.php @@ -126,12 +126,16 @@ class CRM_Contact_Form_RelatedContact extends CRM_Core_Form { $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_defaults); - $countryID = CRM_Utils_Array::value('country_id', - $this->_defaults['address'][1] - ); - $stateID = CRM_Utils_Array::value('state_province_id', - $this->_defaults['address'][1] - ); + $countryID = ''; + $stateID = ''; + if (!empty($this->_defaults['address'][1])) { + $countryID = CRM_Utils_Array::value('country_id', + $this->_defaults['address'][1] + ); + $stateID = CRM_Utils_Array::value('state_province_id', + $this->_defaults['address'][1] + ); + } CRM_Contact_BAO_Contact_Utils::buildOnBehalfForm($this, $this->_contactType, $countryID, diff --git a/CRM/Core/BAO/Block.php b/CRM/Core/BAO/Block.php index f223308d6d..46f796b282 100644 --- a/CRM/Core/BAO/Block.php +++ b/CRM/Core/BAO/Block.php @@ -310,7 +310,7 @@ class CRM_Core_BAO_Block { if ($blockName == 'phone') { $phoneTypeBlockValue = CRM_Utils_Array::value('phoneTypeId', $blockValue); - if ($phoneTypeBlockValue == $value['phone_type_id']) { + if ($phoneTypeBlockValue == CRM_Utils_Array::value('phone_type_id', $value)) { $valueId = TRUE; } } diff --git a/CRM/Core/Config/Variables.php b/CRM/Core/Config/Variables.php index cec65cc7fe..469ff3d6b4 100644 --- a/CRM/Core/Config/Variables.php +++ b/CRM/Core/Config/Variables.php @@ -452,6 +452,12 @@ class CRM_Core_Config_Variables extends CRM_Core_Config_Defaults { * Path to wkhtmltopdf if available */ public $wkhtmltopdfPath = FALSE; + + /** + * Allow second-degree relations permission to edit contacts + */ + public $secondDegRelPermissions = FALSE; + /** * Allow second-degree relations permission to edit contacts diff --git a/api/v3/examples/SettingGetfields.php b/api/v3/examples/SettingGetfields.php index 5e84f1c12f..147b2e546e 100644 --- a/api/v3/examples/SettingGetfields.php +++ b/api/v3/examples/SettingGetfields.php @@ -705,6 +705,22 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl 'description' => 'If set, CiviCRM will use this setting as the base url.', 'help_text' => 'By default, CiviCRM will generate front-facing pages using the home page at http://wp/ as its base. If you want to use a different template for CiviCRM pages, set the path here.', ), + 'secondDegRelPermissions' => array( + 'group_name' => 'CiviCRM Preferences', + 'group' => 'core', + 'name' => 'secondDegRelPermissions', + 'prefetch' => 1, + 'config_only'=> 1, + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => 0, + 'add' => '4.3', + 'title' => 'Allow second-degree relationship permissions', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => "If enabled, contacts with the permission to edit a related contact will inherit that contact's permission to edit other related contacts", + 'help_text' => null, + ), 'debug_enabled' => array( 'group_name' => 'Developer Preferences', 'group' => 'developer', @@ -718,7 +734,7 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl 'title' => 'Enable Debugging', 'is_domain' => 1, 'is_contact' => 0, - 'description' => 'Set this value to Yes if you want to use one of CiviCRM's debugging tools. This feature should NOT be enabled for production sites', + 'description' => 'Set this value to Yes if you want to use one of CiviCRM\'s debugging tools. This feature should NOT be enabled for production sites', 'prefetch' => 1, 'help_text' => 'Do not turn this on on production sites', ), @@ -736,8 +752,8 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl 'is_contact' => 0, 'description' => 'Set this value to Yes if you want CiviCRM error/debugging messages to also appear in Drupal error logs', 'prefetch' => 1, - 'help_text' => 'Set this value to Yes if you want CiviCRM error/debugging messages the appear in your CMS' error log. -In the case of Drupal, this will cause all CiviCRM error messages to appear in the watchdog (assuming you have Drupal's watchdog enabled)', + 'help_text' => 'Set this value to Yes if you want CiviCRM error/debugging messages the appear in your CMS\' error log. +In the case of Drupal, this will cause all CiviCRM error messages to appear in the watchdog (assuming you have Drupal\'s watchdog enabled)', ), 'backtrace' => array( 'group_name' => 'Developer Preferences', diff --git a/settings/Core.setting.php b/settings/Core.setting.php index e6aa893444..db0e01c214 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -496,7 +496,7 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl 'html_type' => 'Text', 'default' => 7, 'add' => '4.3', - 'title' => 'Dashboard cache timeout', + 'title' => 'Checksum Lifespan', 'is_domain' => 1, 'is_contact' => 0, 'description' => null, @@ -576,4 +576,20 @@ When enabled, statistics about your CiviCRM installation are reported anonymousl 'description' => 'If set, CiviCRM will use this setting as the base url.', 'help_text' => 'By default, CiviCRM will generate front-facing pages using the home page at http://wp/ as its base. If you want to use a different template for CiviCRM pages, set the path here.', ), + 'secondDegRelPermissions' => array( + 'group_name' => 'CiviCRM Preferences', + 'group' => 'core', + 'name' => 'secondDegRelPermissions', + 'prefetch' => 1, + 'config_only'=> 1, + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => 0, + 'add' => '4.3', + 'title' => 'Allow second-degree relationship permissions', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => "If enabled, contacts with the permission to edit a related contact will inherit that contact's permission to edit other related contacts", + 'help_text' => null, + ), ); diff --git a/templates/CRM/Admin/Form/Setting/Miscellaneous.tpl b/templates/CRM/Admin/Form/Setting/Miscellaneous.tpl index 8e397e3ec3..2f5ae4d94c 100644 --- a/templates/CRM/Admin/Form/Setting/Miscellaneous.tpl +++ b/templates/CRM/Admin/Form/Setting/Miscellaneous.tpl @@ -93,6 +93,12 @@ {$form.maxFileSize.html}
{$maxFileSize_description} + + {$form.secondDegRelPermissions.label} + {$form.secondDegRelPermissions.html}
+

{ts}If enabled, contacts with the permission to edit a related contact will inherit that contact's permission to edit other related contacts.{/ts}

+ +

{ts}reCAPTCHA Keys{/ts}

-- 2.25.1