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

Afform - Fix saving joined entities (email, address, phone, etc) #20264

Merged
merged 1 commit into from
May 13, 2021

Conversation

colemanw
Copy link
Member

Overview

Fixes saving emails, phones, websites, addresses, etc when the form is submitted by non-admin users.
https://lab.civicrm.org/dev/core/-/issues/2592

Before

Form fails to save email, etc. when submitted by anonymous users.

After

Works

Technical Details

The getSecureApi4() only really works for the main entity. Once that's validated we can disable permission checks to save related entities.

@civibot
Copy link

civibot bot commented May 10, 2021

(Standard links)

$api4($joinEntityName, 'replace', [
civicrm_api4($joinEntityName, 'replace', [
// Disable permission checks because the main entity has already been vetted
'checkPermissions' => FALSE,
Copy link
Contributor

Choose a reason for hiding this comment

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

So this seems to be the guts of the pr - what limits it to only address etc entities and not others?

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 only fire for af-join entitites which are like "sub-entities" of a Contact record (aside: in theory it could be possible to have a sub-entity of something else but so far it's just Contacts). And it only fires after the Contact has been saved, which would have thrown an exception if authentication failed. So at this point we already know that saving the Contact is allowed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@colemanw ok - but how do we ensure that when we extend the entities we don't accidentally expose more inappropriate sub entities - how are they defined? Presumably pro-actively?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also what if you are trying to update a joined case say from an activity but you don't have case permissions how would this work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes they have to be explicitly defined in code, e.g. afjoinAddressDefault.aff.json. And then they have to be explicitly added to the form by the form author.

Copy link
Member Author

@colemanw colemanw May 10, 2021

Choose a reason for hiding this comment

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

@seamuslee001 af-joins really are sub-entities. Other than email, phone, address, website, im, and multi-record custom fields, I don't expect there to be others to follow this pattern.

Activities and Cases are both full entities in their own right. We wouldn't use the af-join pattern with them. We'd probably use an EntityRef to link them, although we'd have to do something about bridging them through the ActivityContact table. But that's a separate issue to this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@colemanw I think that deals with my concerns on a technical level but I'm still nervous on a docs level - ie the concept of sub-entities & implications should be documented. I think the urgency of having a home for afform documentation is increasing (@MikeyMJCO @totten @seamuslee001 )

Copy link
Contributor

Choose a reason for hiding this comment

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

I've added https://lab.civicrm.org/documentation/docs/dev/-/merge_requests/913 to start to establish a docs location. It is very minimal but hopefully we could put something about how sub-entities are declared in there

@colemanw colemanw changed the base branch from master to 5.38 May 13, 2021 00:14
@civibot civibot bot added 5.38 and removed master labels May 13, 2021
@seamuslee001
Copy link
Contributor

Test fail unrelated, now that we have a docs PR I think the docs conversation can continue there, as this fixes a bug I'm going to merge it

@seamuslee001 seamuslee001 merged commit fbd8d65 into civicrm:5.38 May 13, 2021
@seamuslee001 seamuslee001 deleted the afformJoinSaveFix branch May 13, 2021 08:28
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.

3 participants