Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#2752 Use acl, not blanket permissions on FinancialAccount, FinancialType, EntityFinancialAccount #21181

Merged
merged 1 commit into from
Dec 31, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Aug 19, 2021

Overview

Use acl, not blanket permissions on FinancialAccount, FinancialType, EntityFinancialAccount

https://lab.civicrm.org/dev/core/-/issues/2752

Before

API get calls for the FinancialAccount, FinancialType and EntityFinancialAccount entities fail due to the minimum permission being 'Administer CiviCRM'

After

If the contact has access CiviContribute permission that is enough for 'get'. However, the api results will be filtered by their permitted financial types. In the case of financial type this is a direct filter but in the case of financial account I have interpretted this as a filter on the associated income account

Technical Details

@seamuslee001 this is part of the issue I was pinging you about. I think this part is probably straight forward - it's the payments (the important part) that isn't so I'll leave out of scope for this PR

Comments

@civibot
Copy link

civibot bot commented Aug 19, 2021

(Standard links)

@civibot civibot bot added the master label Aug 19, 2021
@eileenmcnaughton eileenmcnaughton changed the title Use acl, not blanket permissions on FinancialAccount, FinancialType, … Use acl, not blanket permissions on FinancialAccount, FinancialType, EntityFinancialAccount Aug 19, 2021
@eileenmcnaughton eileenmcnaughton changed the title Use acl, not blanket permissions on FinancialAccount, FinancialType, EntityFinancialAccount dev/core#2752 Use acl, not blanket permissions on FinancialAccount, FinancialType, EntityFinancialAccount Aug 19, 2021
@@ -1137,6 +1137,9 @@ public static function getEntityActionPermissions() {
$permissions['line_item'] = $permissions['contribution'];

$permissions['financial_item'] = $permissions['contribution'];
$permissions['financial_type']['get'] = $permissions['contribution']['get'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial test runs suggest that maybe we want the permissions of contribution.get OR 'Administer CiviCRM' (or 'Administer CiviCRM Data' which is implicit in Administer CiviCRM)

  • since I guess lines like this suggest that we need to be careful not to reduce access
    if (array_key_exists('CiviContribute', CRM_Core_Component::getEnabledComponents())) {
    return CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
    }

I just added error handling - but not 100% sure if that is enough forgiveness

if (array_key_exists('CiviContribute', CRM_Core_Component::getEnabledComponents())) {
return CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
// if check_permission has been passed in (not Null) then restrict.
return CRM_Financial_BAO_FinancialType::getIncomeFinancialType($props['check_permissions'] ?? TRUE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note I updated the v3 api to always set $props['check_permissions'] - the ?? will default to true if NULL but not if set to false

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 @colemanw @monishdeb this is passing now but I'm still trying to get my head around it.

I guess before this change

  • only someone with administer civicrm could do a get on FinancialType, FinancialAccount, EntityFinancialAccess with checkPermissions = TRUE
  • even with checkPermissions = TRUE not all financial types were returned for those users if financial acls are enabled

That is not consistent with our model - our model is that checkPermissions = FALSE means 'don't check permissions at all' and checkPermissions = true means 'apply both entity level and acl level permissions'

So with this change the requirement for the get is reduced to 'access CiviContribute' in order to make data available in search kit (eg. FinancialType.is_deductible) but it means that when calls to the altered entities are made with checkPermissions = FALSE then all rows will be returned (regardless of permission to that financial type).

I implemented the permissions for CRM_Financial_BAO_FinancialType::getIncomeFinancialType - largely in order to add tests & put the logic through it's paces. Most of the places the function is called from are configuration screens and I think it is reasonable to assume people on those screens have 'access CiviContribute' and that it is appropriate to call with checkPermissions = FALSE. In 2 places it is called in buildOptions and I altered that to pass permissions through - but it assumes 'unset' is TRUE. I think for apiv3 we can rely on it being set - but beyond that? I'm not sure. I'm now starting to lean towards thinking it would be safer to assume unset is FALSE

I don't have to convert getIncomeFinancialType but I feel like doing that actually helps us consolidate and flush out the questions.....

image

So my 2 biggest doubts right now are

  1. should checkPermissions 'assume' FALSE if not set in buildOptions (Event and contribution) and
  2. should the default permission be access CiviContribute or should it be ('access CiviContribute' || 'adminster CiviCRM')

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 did you get another chance to think about this ? I'm hoping to get this merged before the rc is cut

@colemanw
Copy link
Member

I'm going to merge this based on code review, solid test coverage, and the fact that it's been used in production for 6 months by WMF.

@colemanw colemanw merged commit 1cca348 into civicrm:master Dec 31, 2021
@colemanw colemanw deleted the perm3 branch December 31, 2021 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants