Skip to content

OBPIH-7448 prevent creating a PO if logged into different org#5647

Merged
ewaterman merged 1 commit into
developfrom
bug/OBPIH-7448-PO-create-diff-org
Dec 3, 2025
Merged

OBPIH-7448 prevent creating a PO if logged into different org#5647
ewaterman merged 1 commit into
developfrom
bug/OBPIH-7448-PO-create-diff-org

Conversation

@ewaterman
Copy link
Copy Markdown
Member

✨ Description of Change

Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7448

Description: Prevent you from creating a PO with a destination party that is different than the currently logged in organization.


📷 Screenshots & Recordings (optional)

2025-12-01_14-51-35.mp4

@ewaterman ewaterman self-assigned this Dec 1, 2025
@github-actions github-actions Bot added type: bug Addresses unintended behaviours of the app domain: backend Changes or discussions relating to the backend server domain: l10n Changes or discussions relating to localization & Internationalization labels Dec 1, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 1, 2025

Codecov Report

❌ Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.72%. Comparing base (1bb7314) to head (3f74991).
⚠️ Report is 246 commits behind head on develop.

Files with missing lines Patch % Lines
...g/pih/warehouse/core/session/SessionManager.groovy 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             develop   #5647      +/-   ##
============================================
+ Coverage       9.12%   9.72%   +0.60%     
- Complexity      1170    1323     +153     
============================================
  Files            701     717      +16     
  Lines          45281   45785     +504     
  Branches       10851   10926      +75     
============================================
+ Hits            4131    4453     +322     
- Misses         40497   40642     +145     
- Partials         653     690      +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

}

Order saveOrder(Order order) {
if (order.destinationParty?.id != sessionManager.getCurrentLocation().organizationId) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Won't it be better to have a convenience method getCurrentOrganizationId method in the session manager to avoid breaking the law of demeter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wanted session manager to be a simple class for setting/getting objects to/from the session so I feel a bit weird about adding logic around operating on the objects themselves (even if it's just a simple getter).

I feel like we break that law constantly since we often need to fetch a domain, then use that domain to fetch their relationships, then operate on those relationship entities.

I don't know if I see much advantage of adding a getCurrentOrganizationId method but I hadn't heard of the law of demeter before so I haven't given it much thought before. I'm willing to be convinced otherwise.

}

Order saveOrder(Order order) {
if (order.destinationParty?.id != sessionManager.getCurrentLocation().organizationId) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm fine with the way you've done it, but I believe this could be also achievable in the Order's destinationParty validator

Copy link
Copy Markdown
Member Author

@ewaterman ewaterman Dec 3, 2025

Choose a reason for hiding this comment

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

hmm interesting idea. I'd be scared of that impacting other flows though since the Order domain is used everywhere. Maybe we want to always fail if the user is in a different org but that would probably require a lot more changes to support in other flows. I'm going to keep it this way for now but if we encounter the issue again, we can revisit.

It does still feel a little weird to be querying the session inside of a domain validator but maybe I just need to get over my idea that the validator should be only for simple validations on the domain/command fields itself. If we wanted to keep the logic out of the domain, we could always create XValidator components that can wire in whatever other components we need. So maybe I am okay with the idea.

Something like:

static constraints = {
    destinationParty(validator: { Party destinationParty, Order obj -> return OrderValidator.validateDestinationParty(...)})
}

and then OrderValidator can access the session manager and whatever other components we need.

@ewaterman ewaterman merged commit df06d38 into develop Dec 3, 2025
7 checks passed
@ewaterman ewaterman deleted the bug/OBPIH-7448-PO-create-diff-org branch December 3, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server domain: l10n Changes or discussions relating to localization & Internationalization type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants