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 FinancialItem API #20499

Merged
merged 1 commit into from
Jun 6, 2021

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Jun 4, 2021

Overview

Add permissions for financial_item entity

Before

No permission declared for financial_item

After

Financial Item got permissions, and prevent create/update action.
Screenshot 2021-06-04 at 12 08 19 PM

Comments

This is a follow-up to #20433.

ping @colemanw @eileenmcnaughton @totten

@civibot
Copy link

civibot bot commented Jun 4, 2021

(Standard links)

@civibot civibot bot added the master label Jun 4, 2021
@monishdeb monishdeb force-pushed the add_permission_fi_api4 branch 2 times, most recently from beee51b to ae8ee11 Compare June 4, 2021 06:48
@monishdeb monishdeb force-pushed the add_permission_fi_api4 branch 2 times, most recently from e189d94 to ee73f13 Compare June 4, 2021 07:11
@colemanw
Copy link
Member

colemanw commented Jun 4, 2021

So FinancialItems are never allowed to be created or updated?

@totten totten changed the title Add permissions for financial_item entity dev/core#2486 - Use read-only permissions for FinancialItem API Jun 4, 2021
@totten
Copy link
Member

totten commented Jun 4, 2021

(For posterity: this PR+discussion is an offshoot from https://chat.civicrm.org/civicrm/pl/ey1myeenuj813qcxoi8hjwqhdh)

@colemanw Correct. I understand these to be special-purpose logging-tables. Here's a description of the financial entities from @JoeMurray: https://civicrm.stackexchange.com/questions/28197/what-is-a-line-item-and-what-is-a-financial-item-and-how-are-those-two-linked-t with a notable excerpt:

An important principle of accounting is that books should be auditable. One part of that is to retain records about all of the changes that have been made on items. So if a purchase is made with pay later selected, and two partial payments are made, the number of things purchased is changed, a refund is made, etc., then all of these are tracked in the financial tables in CiviCRM. Entries in civicrm_financial_item and civicrm_financial_trxn tables are intended to never be edited or deleted.

@eileenmcnaughton
Copy link
Contributor

I'm fine with this - but I would note that we call the apiv3 version of this api from internal code - we have traditionally encouraged api use in internal code for readability & consistency reasons

@totten
Copy link
Member

totten commented Jun 6, 2021

@eileenmcnaughton Yeah, it seems to me that (in this approach) you should be able to call APIv4 FinancialItem::create() internally as well -- just pass checkPermissions=>FALSE. A purer approach might remove the FinancialItem::create() and FinancialItem::update() API implementations completely, which would make it impossible. Here, it's more like, "This can only be called internally."

@eileenmcnaughton
Copy link
Contributor

@totten OK that's great - ie we mostly use checkPermissions = FALSE once we are deep in the BAO

@eileenmcnaughton
Copy link
Contributor

@totten I don't have any concerns about this based on the above - go ahead & merge if this makes sense to you

1 similar comment
@eileenmcnaughton
Copy link
Contributor

@totten I don't have any concerns about this based on the above - go ahead & merge if this makes sense to you

@totten
Copy link
Member

totten commented Jun 6, 2021

r-run: I used these commands (before and after the patch):

cv ev -U admin 'civicrm_api4("FinancialItem","create",["checkPermissions"=>TRUE]);'
cv ev -U admin 'civicrm_api4("FinancialItem","create",["checkPermissions"=>FALSE]);'

As expected, the patch introduces an authorization-failure if you enable permissions -- and it still allows the call if you skip permissions.

Merging.

@totten totten merged commit cc7f6de into civicrm:master Jun 6, 2021
@seamuslee001 seamuslee001 deleted the add_permission_fi_api4 branch June 7, 2021 00:35
@monishdeb
Copy link
Member Author

monishdeb commented Jun 7, 2021

Thanks @totten for merging this.

@eileenmcnaughton should I make similar change to LineItem and EntityFinancialTrxn ?

@eileenmcnaughton
Copy link
Contributor

@monishdeb yeah - probably - I think there might be others too

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