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
Conversation
…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>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
InvoiceRole/PartyRoleforeign key constraint and surfaces a raw SQL error to the user.ensurePartyRoleeca oninvokesilently fabricates aPartyRolerecord 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 aPartyRoleexistence check up front and returns thePartyRoleAssociationRequirederror 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 existingensureNaPartyRolehelper right next to it): looks upPartyRoleby(partyId, roleTypeId); if missing, fails with the existingPartyRoleAssociationRequiredlabel (same onecreateWorkEffortAndPartyAssignuses), including the RoleType's description for a readable message.in-validateeca oncreateInvoiceRole,createBillingAccountRole, andcreateFinAccountRole(applications/accounting/servicedef/secas.xml). Sincein-validateruns beforeinvoke, an invalid combination is rejected before the existingensurePartyRoleinvoke-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.testCreateInvoiceRoleRejectsPartyWithoutRoleandAutoAcctgFinAccountTests.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, perAccountingTestsData.xml) is now rejected.AutoAcctgBillingAccountTests(new file + newauto-accounting-billingaccount-testsentry inaccountingtests.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 spuriousPartyRolegets created for the rejected combination.testCreateInvoiceRole/testCreateFinAccountRolepositive-case tests still pass under the new validation without changes, since theirDEMO_COMPANY+INTERNAL_ORGANIZATIOcombination is already seeded as a realPartyRoleinAccountingTestsData.xml.applications/accounting/servicedef/secas.xml,applications/party/servicedef/services.xml, andapplications/party/minilang/party/PartySimpleMethods.xmlagainst their actual XSD schemas (service-eca.xsd,services.xsd,simple-methods.xsd) withxmllint --schema- all validate cleanly.gradle compileTestGroovyfor the whole tree (JDK 21) - compiles clean, including the new/changed test files.Notes / scope
createBudgetRolehas the identical unconditionalensurePartyRoleinvoke-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