Skip to content

Commit

Permalink
Merge pull request #21120 from eileenmcnaughton/acl_setting
Browse files Browse the repository at this point in the history
Move financial acl setting to the extension
  • Loading branch information
colemanw authored Aug 30, 2021
2 parents 27bf657 + a572646 commit 3753c95
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
10 changes: 10 additions & 0 deletions ext/financialacls/financialacls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. ---

/**
Expand Down
22 changes: 22 additions & 0 deletions ext/financialacls/settings/financialacls.setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
return [
'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]],
'on_change' => [
'financialacls_toggle',
],
],
];
16 changes: 0 additions & 16 deletions settings/Contribute.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,6 @@
'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',
Expand Down
8 changes: 1 addition & 7 deletions tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down

0 comments on commit 3753c95

Please sign in to comment.