From a572646e0649a933ee064563bb78ac5ec661ed42 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 13 Aug 2021 18:49:47 +1200 Subject: [PATCH] Move financial acl setting to the extension --- ext/financialacls/financialacls.php | 10 +++++++++ .../settings/financialacls.setting.php | 22 +++++++++++++++++++ settings/Contribute.setting.php | 16 -------------- .../CRMTraits/Financial/FinancialACLTrait.php | 8 +------ 4 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 ext/financialacls/settings/financialacls.setting.php diff --git a/ext/financialacls/financialacls.php b/ext/financialacls/financialacls.php index a0d9454068..c36fcdc0ac 100644 --- a/ext/financialacls/financialacls.php +++ b/ext/financialacls/financialacls.php @@ -393,6 +393,16 @@ function financialacls_is_acl_limiting_enabled(): bool { return (bool) Civi::settings()->get('acl_financial_type'); } +/** + * Clear the statics cache when the setting is enabled or disabled. + * + * Note the setting will eventually disappear in favour of whether + * the extension is enabled or disabled. + */ +function financialacls_toggle() { + unset(\Civi::$statics['CRM_Financial_BAO_FinancialType']); +} + // --- Functions below this ship commented out. Uncomment as required. --- /** diff --git a/ext/financialacls/settings/financialacls.setting.php b/ext/financialacls/settings/financialacls.setting.php new file mode 100644 index 0000000000..e6ba889d5c --- /dev/null +++ b/ext/financialacls/settings/financialacls.setting.php @@ -0,0 +1,22 @@ + [ + 'group_name' => 'Contribute Preferences', + 'group' => 'contribute', + 'name' => 'acl_financial_type', + 'type' => 'Boolean', + 'html_type' => 'checkbox', + 'quick_form_type' => 'Element', + 'default' => 0, + 'add' => '4.7', + 'title' => ts('Enable Access Control by Financial Type'), + 'is_domain' => 1, + 'is_contact' => 0, + 'help_text' => NULL, + 'help' => ['id' => 'acl_financial_type'], + 'settings_pages' => ['contribute' => ['weight' => 30]], + 'on_change' => [ + 'financialacls_toggle', + ], + ], +]; diff --git a/settings/Contribute.setting.php b/settings/Contribute.setting.php index 28874f830c..fca6aee40e 100644 --- a/settings/Contribute.setting.php +++ b/settings/Contribute.setting.php @@ -145,22 +145,6 @@ return [ 'is_contact' => 0, 'pseudoconstant' => ['callback' => 'CRM_Core_SelectValues::taxDisplayOptions'], ], - 'acl_financial_type' => [ - 'group_name' => 'Contribute Preferences', - 'group' => 'contribute', - 'name' => 'acl_financial_type', - 'type' => 'Boolean', - 'html_type' => 'checkbox', - 'quick_form_type' => 'Element', - 'default' => 0, - 'add' => '4.7', - 'title' => ts('Enable Access Control by Financial Type'), - 'is_domain' => 1, - 'is_contact' => 0, - 'help_text' => NULL, - 'help' => ['id' => 'acl_financial_type'], - 'settings_pages' => ['contribute' => ['weight' => 30]], - ], 'deferred_revenue_enabled' => [ 'group_name' => 'Contribute Preferences', 'group' => 'contribute', diff --git a/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php b/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php index 678abb6d06..28e6647afb 100644 --- a/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php +++ b/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php @@ -20,24 +20,18 @@ trait CRMTraits_Financial_FinancialACLTrait { * Enable financial ACLs. */ protected function enableFinancialACLs() { - $contributeSettings = Civi::settings()->get('contribution_invoice_settings'); $this->callAPISuccess('Setting', 'create', [ - 'contribution_invoice_settings' => array_merge($contributeSettings, ['acl_financial_type' => TRUE]), 'acl_financial_type' => TRUE, ]); - unset(\Civi::$statics['CRM_Financial_BAO_FinancialType']); } /** * Disable financial ACLs. */ - protected function disableFinancialACLs() { - $contributeSettings = Civi::settings()->get('contribution_invoice_settings'); + protected function disableFinancialACLs(): void { $this->callAPISuccess('Setting', 'create', [ - 'contribution_invoice_settings' => array_merge($contributeSettings, ['acl_financial_type' => FALSE]), 'acl_financial_type' => FALSE, ]); - unset(\Civi::$statics['CRM_Financial_BAO_FinancialType']); } /** -- 2.25.1