Skip to content

Commit

Permalink
Move permission checks from Query & BAO to financialacl extension
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 13, 2022
1 parent 26b3fea commit 43c606e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 35 deletions.
29 changes: 1 addition & 28 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1157,34 +1157,7 @@ protected static function disconnectPledgePaymentsIfCancelled(int $pledgePayment
}

/**
* @inheritDoc
*/
public function addSelectWhereClause() {
$whereClauses = parent::addSelectWhereClause();
if ($whereClauses !== []) {
// In this case permisssions have been applied & we assume the
// financialaclreport is applying these
// https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport/blob/master/financialaclreport.php#L107
return $whereClauses;
}

if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
return $whereClauses;
}
$types = CRM_Financial_BAO_FinancialType::getAllEnabledAvailableFinancialTypes();
if (empty($types)) {
$whereClauses['financial_type_id'] = 'IN (0)';
}
else {
$whereClauses['financial_type_id'] = [
'IN (' . implode(',', array_keys($types)) . ')',
];
}
return $whereClauses;
}

/**
* @param null $status
* @param string $status
* @param null $startDate
* @param null $endDate
*
Expand Down
6 changes: 1 addition & 5 deletions CRM/Financial/BAO/FinancialType.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,7 @@ public static function buildPermissionedClause(string $component): string {
return '';
}
if ($component === 'contribution') {
$types = array_keys(self::getAllEnabledAvailableFinancialTypes());
if (empty($types)) {
$types = [0];
}
$clauses[] = ' civicrm_contribution.financial_type_id IN (' . implode(',', $types) . ')';
$clauses = CRM_Contribute_BAO_Contribution::getSelectWhereClause();
}
if ($component === 'membership') {
self::getAvailableMembershipTypes($types, CRM_Core_Action::VIEW);
Expand Down
1 change: 1 addition & 0 deletions ext/financialacls/financialacls.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function financialacls_civicrm_selectWhereClause($entity, &$clauses) {
case 'LineItem':
case 'MembershipType':
case 'ContributionRecur':
case 'Contribution':
$clauses['financial_type_id'] = _financialacls_civicrm_get_type_clause();
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public function testBuildPermissionedClause(): void {
'view contributions of type Member Dues',
]);
$whereClause = \CRM_Financial_BAO_FinancialType::buildPermissionedClause('contribution');
$this->assertEquals(' civicrm_contribution.financial_type_id IN (1,2)', $whereClause);
$this->assertEquals('(`civicrm_contribution`.`financial_type_id` IS NULL OR (`civicrm_contribution`.`financial_type_id` IN (1,2)))', $whereClause);
$this->setPermissions([
'view contributions of type Donation',
'view contributions of type Member Dues',
'view contributions of type Event Fee',
]);

$whereClause = \CRM_Financial_BAO_FinancialType::buildPermissionedClause('contribution');
$this->assertEquals(' civicrm_contribution.financial_type_id IN (1,4,2)', $whereClause);
$this->assertEquals('(`civicrm_contribution`.`financial_type_id` IS NULL OR (`civicrm_contribution`.`financial_type_id` IN (1,4,2)))', $whereClause);
}

}

0 comments on commit 43c606e

Please sign in to comment.