Skip to content

Reject party/role combinations the party does not hold (OFBIZ-12370, OFBIZ-12372, OFBIZ-12373) - #1727

Open
karthikchundi-commits wants to merge 1 commit into
apache:trunkfrom
karthikchundi-commits:fix/party-role-validation-invoice-billing-finaccount
Open

Reject party/role combinations the party does not hold (OFBIZ-12370, OFBIZ-12372, OFBIZ-12373)#1727
karthikchundi-commits wants to merge 1 commit into
apache:trunkfrom
karthikchundi-commits:fix/party-role-validation-invoice-billing-finaccount

Conversation

@karthikchundi-commits

Copy link
Copy Markdown
Contributor

Jira tickets

Purpose and Description

Follow-up to #1692 (OFBIZ-12374), which fixed the same family of bug for TaxAuthority. These three tickets are a different flavor of it: unlike TaxAuthority, the roleTypeId on InvoiceRole/BillingAccountRole/FinAccountRole is a free-choice dropdown over every RoleType, not a single fixed role, so the "role-scoped LookupXxx form" pattern used for TaxAuthority/Supplier/GovernmentAgency doesn't directly generalize here - there's no single roleTypeId to hardcode into a lookup form.

Instead:

  • createInvoiceRole: no existing safety net. Submitting a party/role combination where the party doesn't already hold that role hits the InvoiceRole/PartyRole foreign key constraint and surfaces a raw SQL error to the user.
  • createBillingAccountRole / createFinAccountRole: an unconditional ensurePartyRole eca on invoke silently fabricates a PartyRole record for whatever roleTypeId was submitted, regardless of whether it's a sensible role for that party. No FK error, but a spurious PartyRole gets created with no real-world basis - this matches the "PartyRole created" wording in both ticket titles.

This turns out to be an existing, established OFBiz pattern for exactly this failure mode - createWorkEffortAndPartyAssign (WorkEffortServicesScript.groovy) already does a PartyRole existence check up front and returns the PartyRoleAssociationRequired error message ("Party id: X should be in role: Y") if it's missing. This PR generalizes that same check into a small reusable service rather than duplicating it three times inline:

  • checkPartyRoleExists (new service, applications/party/servicedef/services.xml + PartySimpleMethods.xml, mirroring the existing ensureNaPartyRole helper right next to it): looks up PartyRole by (partyId, roleTypeId); if missing, fails with the existing PartyRoleAssociationRequired label (same one createWorkEffortAndPartyAssign uses), including the RoleType's description for a readable message.
  • Wired as an in-validate eca on createInvoiceRole, createBillingAccountRole, and createFinAccountRole (applications/accounting/servicedef/secas.xml). Since in-validate runs before invoke, an invalid combination is rejected before the existing ensurePartyRole invoke-event ecas ever run - so those ecas are left untouched and only become reachable for combinations that are already valid (where they're a harmless no-op, since the PartyRole already exists).

Testing

  • AutoAcctgInvoiceTests.testCreateInvoiceRoleRejectsPartyWithoutRole and AutoAcctgFinAccountTests.testCreateFinAccountRoleRejectsPartyWithoutRole: new negative-case regression tests added alongside the existing positive-case tests in each file, asserting the CARRIER role (which DEMO_COMPANY does not hold, per AccountingTestsData.xml) is now rejected.
  • AutoAcctgBillingAccountTests (new file + new auto-accounting-billingaccount-tests entry in accountingtests.xml): BillingAccountRole had no existing test coverage at all, so this adds a small suite covering create-BillingAccount, a valid role assignment (INTERNAL_ORGANIZATIO, which DEMO_COMPANY does hold), and the same negative case - also asserting no spurious PartyRole gets created for the rejected combination.
  • Confirmed the existing testCreateInvoiceRole / testCreateFinAccountRole positive-case tests still pass under the new validation without changes, since their DEMO_COMPANY + INTERNAL_ORGANIZATIO combination is already seeded as a real PartyRole in AccountingTestsData.xml.
  • Verified applications/accounting/servicedef/secas.xml, applications/party/servicedef/services.xml, and applications/party/minilang/party/PartySimpleMethods.xml against their actual XSD schemas (service-eca.xsd, services.xsd, simple-methods.xsd) with xmllint --schema - all validate cleanly.
  • Ran gradle compileTestGroovy for the whole tree (JDK 21) - compiles clean, including the new/changed test files.
  • I don't have a running OFBiz instance with a live database in this environment, so I could not execute the Groovy test suite itself end-to-end (only compile it) - I'd appreciate a CI run / maintainer review of the actual test execution in addition to the fix.

Notes / scope

createBudgetRole has the identical unconditional ensurePartyRole invoke-eca pattern as BillingAccountRole/FinAccountRole (same silent-fabrication issue), but it isn't covered by any of these three tickets, so I left it untouched to keep this PR scoped to OFBIZ-12370/12372/12373. Happy to follow up there too if useful.

Checklist

  • My code follows the code style of this project
  • I have updated the documentation accordingly (n/a - no user-facing docs for this internal validation)
  • I have read the CONTRIBUTING document
  • I have added tests to cover my changes

…OFBIZ-12372, OFBIZ-12373)

InvoiceRole, BillingAccountRole, and FinAccountRole all let a user submit
any partyId + roleTypeId combination with no validation that the party
actually holds that role. For InvoiceRole this hits the InvoiceRole/
PartyRole foreign key constraint and surfaces a raw SQL error. For
BillingAccountRole and FinAccountRole, an unconditional ensurePartyRole
eca instead silently fabricates a PartyRole record for the submitted
roleTypeId, regardless of whether it makes sense for that party.

Adds a small, reusable checkPartyRoleExists service (party component,
mirroring the existing ensureNaPartyRole helper) that looks up PartyRole
by (partyId, roleTypeId) and, if missing, fails with the same
PartyRoleAssociationRequired message already used for this exact class of
bug in createWorkEffortAndPartyAssign. Wires it as an in-validate eca on
createInvoiceRole, createBillingAccountRole, and createFinAccountRole, so
invalid combinations are rejected before the existing invoke-event
ensurePartyRole ecas ever run.

Adds regression tests: a negative case per ticket proving the
party/role combination is now rejected (and, for BillingAccountRole/
FinAccountRole, that no PartyRole is fabricated), plus a new
AutoAcctgBillingAccountTests suite since BillingAccountRole had no
existing test coverage.

Signed-off-by: Karth <karthik.chundi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant