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#2486 - Use read-only permissions for LineItem, EntityFinancialTrxn and FinancialTrxn APIv4 #20550

Closed
wants to merge 2 commits into from

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Jun 8, 2021

Overview

Added read-only permissions for LineItem, EntityFinancialTrxn and FinancialTrxn API

Before

CRUD actions are available for financial entities in APIv4

After

Added read-only permissions for LineItem, EntityFinancialTrxn and FinancialTrxn APIv4

Technical Details

The changes only affect APIv4 not APIv3 in order to ensure no breakage in internal code/extensions

Comments

This is a followup to #20499

ping @colemanw @eileenmcnaughton @JoeMurray @totten

@civibot
Copy link

civibot bot commented Jun 8, 2021

(Standard links)

@civibot civibot bot added the master label Jun 8, 2021
@eileenmcnaughton eileenmcnaughton changed the title dev/core#2486 - Use read-only permissions for LineItem, EntityFinancialTrxn and Payment APIv4 dev/core#2486 - Use read-only permissions for LineItem, EntityFinancialTrxn and FinancialTrxn APIv4 Jun 8, 2021
@@ -1167,6 +1167,8 @@ public static function getEntityActionPermissions() {
];
$permissions['contribution_recur'] = $permissions['payment'];

$permissions['entity_financial_trxn'] = $permissions['payment'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm When we have a payment api (which we don't yet in v4) we will be permitting create.payment fairly widely - it's the financial_trxn we will limit ability to do a create on

Copy link
Member Author

@monishdeb monishdeb Jun 8, 2021

Choose a reason for hiding this comment

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

yeah, and payment API would be one of those abstract entity which got its own set of CRUD and in terms of permission it has to rely on one of the financial entity (here FinancialTrxn). Recently I am working on another abstract entity - Attachment (PR #20494) which could be useful for implementing (financial) abstract entities like Payment, Order etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

@monishdeb yeah so if we add a Payment.create api it will probably have quite open permissions (make online contributions, access CiviContribute) whereas the others will be quite narrow - does that align with what you are doing here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This will affect the api3 and API4(check_permissions = FALSE) and currently the declared payment's permission is declared as:

// Payment permissions
    $permissions['payment'] = [
      'get' => [
        'access CiviCRM',
        'access CiviContribute',
      ],
      'delete' => [
        'access CiviCRM',
        'access CiviContribute',
        'delete in CiviContribute',
      ],
      'cancel' => [
        'access CiviCRM',
        'access CiviContribute',
        'edit contributions',
      ],
      'create' => [
        'access CiviCRM',
        'access CiviContribute',
        'edit contributions',
      ],
      'default' => [
        'access CiviCRM',
        'access CiviContribute',
        'edit contributions',
      ],
    ];
    ```
 And this set of permissions are copied over to contribution_recur and now to entity_financial_trxn 

Copy link
Contributor

Choose a reason for hiding this comment

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

@colemanw we should ideally wrap this up pre fork too - but I'm struggling to get my head around what is right. This seems to be INCREASING who can write directly to financial entities by giving the the same permissions as 'payment' ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@monishdeb on re-reading - the ONLY line in this PR I have an issue with is

 $permissions['entity_financial_trxn'] = $permissions['payment'];

as it is the only line that is loosening rather than tightening - do tests fail if we remove it?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, tests (on api3 and api4) won't be affected but APIv4 class need to updated to

class EntityFinancialTrxn extends Generic\DAOEntity {  
use Generic\Traits\EntityBridge;
...
public static function permissions() {    
- $permissions = \CRM_Core_Permission::getEntityActionPermissions()['entity_financial_trxn'] ?? []; 
+ $permissions = \CRM_Core_Permission::getEntityActionPermissions()['default'] ?? [];     
...

@monishdeb monishdeb force-pushed the readonly_entities branch from ad7c877 to 104a968 Compare June 8, 2021 07:58
@colemanw
Copy link
Member

colemanw commented Jun 9, 2021

If the goal is to remove create, update, delete, save and replace as api actions on these entities, why not do that?
The entity class can extend AbstractEntity instead of DAOEntity and only implement get and getFields.
Then we don't need to do anything with permissions.

@JoeMurray
Copy link
Contributor

If the goal is to remove create, update, delete, save and replace as api actions on these entities, why not do that?
The entity class can extend AbstractEntity instead of DAOEntity and only implement get and getFields.
Then we don't need to do anything with permissions.

That sounds promising.

@colemanw
Copy link
Member

colemanw commented Jun 9, 2021

An example of another read-only entity that does this is RelationshipCache.

@eileenmcnaughton
Copy link
Contributor

@colemanw @JoeMurray my underlying preference is to have these apis but have the higher permission level on them ie

Payment.create = api that should be readily usable
FinancialTrxn.create etc = really handy to have the api for internal BAO use but would want to make it as invisible as possible outside the BAO layer. For v3 we 'just have these apis'

@JoeMurray
Copy link
Contributor

My main concern is to not expose pieces of internal financial API methods that change the data. They should be internal methods because they are intimately enmeshed with other ones in ways that are easy to mess up and that have significant bad consequences. I don't have strong views on how this is done.

@eileenmcnaughton
Copy link
Contributor

Note that they already ARE exposed via v3 api - we would have to make the entities create methods protected if we wanted to block people using them - at the end of the day developers do what they will do - we need to document what is supported & not let the risk of them doing something be a blocker (their responsibility)

@JoeMurray
Copy link
Contributor

I would be happier to see them protected, putting a bit of an inconvenience between extension developers and their use. But I'm not going to insist. Is there a way to flag them as not recommended in unit test documentation and even APIv4 explorer??

@colemanw
Copy link
Member

I think #20609 will resolve all the points we covered here in the discussion

@colemanw colemanw closed this Jun 15, 2021
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.

4 participants