-
Notifications
You must be signed in to change notification settings - Fork 18
Prevent orphaned CE referrals when deleting enrollments #6000
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
Draft
gigxz
wants to merge
5
commits into
stable
Choose a base branch
from
gig/8539-ce-delete-source-enrollment-handling
base: stable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7aa1785
Cleanup related referrals when an Enrollment is destroyed
gigxz 881d78d
Schema update
gigxz d63941e
Merge branch 'release-189' into gig/8539-ce-delete-source-enrollment-…
gigxz 4872bb8
update msg
gigxz 013f1bf
Merge branch 'release-190' into gig/8539-ce-delete-source-enrollment-…
gigxz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,9 @@ class Hmis::Hud::Enrollment < Hmis::Hud::Base | |
|
|
||
| accepts_nested_attributes_for :move_in_addresses, allow_destroy: true | ||
|
|
||
| before_destroy :check_active_outgoing_direct_referrals | ||
| before_destroy :nullify_outgoing_waitlist_referrals | ||
| before_destroy :destroy_outgoing_direct_referrals | ||
| before_validation :set_hud_project_id_from_project_pk_unless_wip, if: :project_pk_changed? | ||
| def set_hud_project_id_from_project_pk_unless_wip | ||
| return unless project_id | ||
|
|
@@ -538,6 +541,26 @@ def build_synthetic_intake_assessment | |
| assessment | ||
| end | ||
|
|
||
| # Prevents deletion of an enrollment that has active outgoing direct referrals. | ||
| private def check_active_outgoing_direct_referrals | ||
| return unless outgoing_ce_referrals.originated_from_direct_send.active.exists? | ||
|
|
||
| raise ActiveRecord::DeleteRestrictionError, 'active outgoing direct referrals' | ||
| end | ||
|
|
||
| # Nullifies source_enrollment_id on waitlist-based referrals when enrollment is deleted. | ||
| # Waitlist-based referrals can exist without as source enrollment since they're already resolved. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs ticket: support changing/adding source enrollment to referral |
||
| private def nullify_outgoing_waitlist_referrals | ||
| outgoing_ce_referrals.originated_from_waitlist.each { |referral| referral.update!(source_enrollment_id: nil) } | ||
| end | ||
|
|
||
| # Destroys all direct send referrals when enrollment is deleted. | ||
| # Direct send referrals require the source enrollment to identify which project sent them. | ||
| # Without the source enrollment, they would "float" and not appear on the source project's outgoing referrals list. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not as compelling, revisit this one.. its more about the target project no? |
||
| private def destroy_outgoing_direct_referrals | ||
| outgoing_ce_referrals.originated_from_direct_send.each(&:destroy!) | ||
| end | ||
|
|
||
| # When submitting a new_client_enrollment form, we validate the client too, with the same validation contexts | ||
| private def client_is_valid | ||
| return unless client.present? | ||
|
|
||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To do - add handling for destroying target enrollment