From 37375016dc27c2b4e9f0f3357e46545b08113f42 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 28 Jul 2015 19:04:43 +0530 Subject: [PATCH] CRM-16915 - Filter Profile selector in Configure Event - Registration tab for non-admin users --- CRM/Core/DAO/permissions.php | 2 +- CRM/Core/Form.php | 3 ++- CRM/Event/Form/ManageEvent/Registration.php | 14 +++++++++----- CRM/UF/Page/ProfileEditor.php | 20 ++++++++++++++------ js/jquery/jquery.crmProfileSelector.js | 9 +++++++-- js/model/crm.uf.js | 10 +++++++++- 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/CRM/Core/DAO/permissions.php b/CRM/Core/DAO/permissions.php index a93074565e..98b3cb6c46 100644 --- a/CRM/Core/DAO/permissions.php +++ b/CRM/Core/DAO/permissions.php @@ -495,7 +495,7 @@ function _civicrm_api3_permissions($entity, $action, &$params) { ), ), ); - $permissions['uf_field'] = $permissions['uf_group']; + $permissions['uf_field'] = $permissions['uf_join'] = $permissions['uf_group']; $permissions['uf_field']['delete'] = array( 'access CiviCRM', array( diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index bfd99ab311..9b36db582d 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1115,7 +1115,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * @param bool $default * //CRM-15427. */ - public function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities, $default = FALSE) { + public function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities, $default = FALSE, $usedFor = NULL) { // Output widget // FIXME: Instead of adhoc serialization, use a single json_encode() CRM_UF_Page_ProfileEditor::registerProfileScripts(); @@ -1127,6 +1127,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 'data-entities' => json_encode($entities), //CRM-15427 'data-default' => $default, + 'data-usedfor' => json_encode($usedFor), )); } diff --git a/CRM/Event/Form/ManageEvent/Registration.php b/CRM/Event/Form/ManageEvent/Registration.php index 3a24bb1d96..19a6641c7e 100644 --- a/CRM/Event/Form/ManageEvent/Registration.php +++ b/CRM/Event/Form/ManageEvent/Registration.php @@ -328,11 +328,11 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent extract(self::getProfileSelectorTypes()); //CRM-15427 - $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); - $form->addProfileSelector('custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); + $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); + $form->addProfileSelector('custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); - $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); - $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); + $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); + $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); } /** @@ -353,7 +353,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent extract((is_null($configs)) ? self::getProfileSelectorTypes() : $configs); $element = $prefix . "custom_post_id_multiple[$count]"; $label .= '
' . ts('(bottom of page)'); - $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); + $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); } /** @@ -367,6 +367,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent 'allowCoreTypes' => array(), 'allowSubTypes' => array(), 'profileEntities' => array(), + 'usedFor' => array(), ); $configs['allowCoreTypes'] = array_merge(array( @@ -374,6 +375,9 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent 'Individual', ), CRM_Contact_BAO_ContactType::subTypes('Individual')); $configs['allowCoreTypes'][] = 'Participant'; + if (CRM_Core_Permission::check('manage event profiles') && !CRM_Core_Permission::check('administer CiviCRM')) { + $configs['usedFor'][] = 'CiviEvent'; + } //CRM-15427 $id = CRM_Utils_Request::retrieve('id', 'Integer'); if ($id) { diff --git a/CRM/UF/Page/ProfileEditor.php b/CRM/UF/Page/ProfileEditor.php index 4a3709832d..a7bd90bb46 100644 --- a/CRM/UF/Page/ProfileEditor.php +++ b/CRM/UF/Page/ProfileEditor.php @@ -20,18 +20,26 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page { CRM_Core_Resources::singleton() ->addSettingsFactory(function () { + $ufGroups = civicrm_api3('UFGroup', 'get', array( + 'sequential' => 1, + 'is_active' => 1, + 'rowCount' => 1000, // FIXME + )); + if (CRM_Core_Permission::check('manage event profiles') && !CRM_Core_Permission::check('administer CiviCRM')) { + foreach ($ufGroups['values'] as $key => $value) { + $ufJoin = CRM_Core_BAO_UFGroup::getUFJoinRecord($value['id']); + if (in_array('CiviEvent', $ufJoin)) { + $ufGroups['values'][$key]['module'] = 'CiviEvent'; + } + } + } return array( 'PseudoConstant' => array( 'locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'websiteType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'), 'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), ), - 'initialProfileList' => civicrm_api('UFGroup', 'get', array( - 'version' => 3, - 'sequential' => 1, - 'is_active' => 1, - 'rowCount' => 1000, // FIXME - )), + 'initialProfileList' => $ufGroups, 'contactSubTypes' => CRM_Contact_BAO_ContactType::subTypes(), 'profilePreviewKey' => CRM_Core_Key::get('CRM_UF_Form_Inline_Preview', TRUE), ); diff --git a/js/jquery/jquery.crmProfileSelector.js b/js/jquery/jquery.crmProfileSelector.js index b46dd499dc..ab6d7f55c4 100644 --- a/js/jquery/jquery.crmProfileSelector.js +++ b/js/jquery/jquery.crmProfileSelector.js @@ -29,10 +29,14 @@ $select = $(this).hide().addClass('rendered'); var validTypesId = []; + var usedByFilter = null; if (options.groupTypeFilter) { matchingUfGroups = ufGroupCollection.subcollection({ filter: function(ufGroupModel) { - return ufGroupModel.checkGroupType(options.groupTypeFilter, options.allowAllSubtypes); + if(!$.isEmptyObject(options.usedByFilter)) { + usedByFilter = options.usedByFilter; + } + return ufGroupModel.checkGroupType(options.groupTypeFilter, options.allowAllSubtypes, usedByFilter); } }); } else { @@ -85,7 +89,8 @@ groupTypeFilter: $(this).data('groupType'), entities: $(this).data('entities'), //CRM-15427 - allowAllSubtypes: $(this).data('default') + allowAllSubtypes: $(this).data('default'), + usedByFilter: $(this).data('usedfor') }); }); }); diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index 99d456e539..d275f116d6 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -698,12 +698,16 @@ * @return {Boolean} */ //CRM-15427 - checkGroupType: function(validTypesExpr, allowAllSubtypes) { + checkGroupType: function(validTypesExpr, allowAllSubtypes, usedByFilter) { var allMatched = true; allowAllSubtypes = allowAllSubtypes || false; + usedByFilter = usedByFilter || null; if (_.isEmpty(this.get('group_type'))) { return true; } + if (usedByFilter && _.isEmpty(this.get('module'))) { + return false; + } var actualTypes = CRM.UF.parseTypeList(this.get('group_type')); var validTypes = CRM.UF.parseTypeList(validTypesExpr); @@ -715,6 +719,10 @@ } }); + if (usedByFilter && this.get('module') != usedByFilter) { + allMatched = false; + } + //CRM-15427 allow all subtypes if (!$.isEmptyObject(validTypes.subTypes) && !allowAllSubtypes) { // Every actual.subType is a valid.subType -- 2.25.1