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

APIv4 - Add shorthand for setCheckPermissions() #17834

Merged
merged 1 commit into from
Jul 17, 2020

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Jul 14, 2020

Overview

This adds a much-requested shorthand for setting $checkPermissions in APIv4.

  • For api consumers, the change is backward compatible and does not require any updates to your code.
  • As with any API changes, any extensions taking advantage of the shorter syntax will need to update their core version dependency (in this case to 5.29).
  • For api authors, you will need to update the factory functions in any api classes that extend AbstractAction, BasicAction or DAOAction. Until you do so, a php warning will be generated about function signatures not matching.

Before

\Civi\Api4\Contact::get()
  ->setCheckPermissions(FALSE)
  ->execute();

After

\Civi\Api4\Contact::get(FALSE)
  ->execute();

Technical Details

This required updating every API factory method, so it's a big PR.

It's also going to generate on-screen PHP warnings for any extensions with built-from-scratch APIs (of which there are very few in existence and most if not all of them were written by me) until those function signatures get updated. I can take care of that shortly after this PR gets accepted. Extensions with regular DAO-based APIv4 entities are not affected if they just inherit all their factory functions from the base class.

Comments

Also updated the API Explorer:
image

@civibot
Copy link

civibot bot commented Jul 14, 2020

(Standard links)

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

This looks good to me @eileenmcnaughton

@eileenmcnaughton
Copy link
Contributor

I think we can still get away with making this change in that custom v4 apis haven't taken off and it helps usability a lot - but we need to think about communications around it - ie. email dev-list? release notes (@agh1 ) docs updates & change log

@colemanw
Copy link
Member Author

@eileenmcnaughton I've submitted https://lab.civicrm.org/extensions/api4example/-/merge_requests/1 and also updated the dev docs to prominently point to those examples. I can also send out an email once this is merged.

@eileenmcnaughton
Copy link
Contributor

@colemanw so it's still not clear to me what has changed from a consumer POV - what will break & how

@eileenmcnaughton
Copy link
Contributor

@colemanw
Copy link
Member Author

@eileenmcnaughton it's not going to break, just generate some annoying PHP warnings because the base class function takes 1 param ($checkPermissions) and your overridden class does not until you merge my PR.

I'm trying this out now with the patched Example extension + unpatched civicrm master, and PHP is fine with it. So warnings get generated if core is updated before extensions, but no warnings if extensions are updated before core.

So I can put out a dev email now asking extension maintainers to update any ad-hoc v4 APIs now & release before september 5th (which is when this will be released in core if we merge it now).

@eileenmcnaughton
Copy link
Contributor

@colemanw my inclination is to send the email out now & merge on Monday. I'm just not comfortable that we will have thought through all the implications of this. ( this is a breaking change although the case is that the impact of the breakage is minimal).

I think some screenshots of the warnings would help

@colemanw
Copy link
Member Author

@eileenmcnaughton actually now I'm not able to get php to generate any warnings from the example extension or from your extension. The only warnings I can generate is one from the contactLayout extension because it overrides a dao action. That's pretty unusual for an api; I really don't think this is going to affect much of anyone but I'll send out a notice to the dev list anyway.

@eileenmcnaughton
Copy link
Contributor

@colemanw ah that makes sense - OK happy to merge this then but yes do email the list

@eileenmcnaughton eileenmcnaughton merged commit ac9de90 into civicrm:master Jul 17, 2020
@eileenmcnaughton eileenmcnaughton deleted the api4perm branch July 17, 2020 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants