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

Parked client download #816

Merged
merged 11 commits into from
Jun 11, 2024
Merged

Parked client download #816

merged 11 commits into from
Jun 11, 2024

Conversation

eanders
Copy link
Contributor

@eanders eanders commented Jun 10, 2024

Please squash merge this PR

Description

This:

  1. Sets user, match, and reason on Unavailable as Candidate Fors (parking records) for existing records
  2. Adds setting of the above fields where appropriate in the app to maintain them going forward
  3. Adds a download feature to the Parked Clients page
  4. Expose user and reason on the Parked Clients page
  5. Various rubocop fixes

Type of change

  • New feature (adds functionality)

Checklist before requesting review

  • I have performed a self-review of my code
  • I have run the code that is being changed under ideal conditions, and it doesn't fail
  • My code includes comments and/or descriptive variable names to help other engineers understand the intent (or not applicable)
  • My code follows the style guidelines of this project (rubocop)
  • I have updated the documentation (or not applicable)
  • If it's not obvious how to test this change, I have provided testing instructions in this PR or the related issue

@eanders eanders requested a review from ttoomey June 10, 2024 19:37
@@ -368,85 +368,6 @@ def active_in_match?
active_matches.any?
end

def available_as_candidate_for_any_route?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was moved into the Availability concern, where similar methods already existed.

Comment on lines -13 to -25
# TODO: Disabled in the nightly processing, remove?
def self.ensure_availability
self.available.each(&:ensure_availability)
end

def ensure_availability
self.class.transaction do
unavailable_as_candidate_fors.destroy_all
unavailable_routes.each do |route|
self.make_unavailable_in match_route: route
end
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was unused code

@@ -216,11 +216,11 @@ def confidential?
# remove voucher
# remove self (opportunity)

def stop_matches_and_remove_entire_history_from_existance!
def stop_matches_and_remove_entire_history_from_existence!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This had a typo, but as far as I could tell isn't used anywhere, probably a manual mechanism for data cleanup?

Copy link
Contributor

@ttoomey ttoomey left a comment

Choose a reason for hiding this comment

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

The CAS models are new to me but I think I'm following along. Code looks good to me, thanks for the cleanups!

MatchRoutes::Base.active.each do |route|
matches = ClientOpportunityMatch.active.on_route(route).where(client_id: unavailable_client_ids).group_by(&:client_id)
UnavailableAsCandidateFor.for_route(route).where(client_id: matches.keys).find_each do |record|
record.update(reason: 'Active Match', user_id: record.versions&.first&.user_id, match_id: matches[record.client_id].first.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

is matches[record.client_id] always present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be. matches is generated using unavailable_client_ids so the client ids should be a subset of the overall parked clients (those on a particular route.) And every match and parked record will have a client_id

@@ -83,15 +80,13 @@ def pending

def confirmed
Notifications::MatchSuccessConfirmedDevelopmentOfficer.create_for_match! match
match.succeeded!
match.succeeded!(user: @dependencies.try(:[], :user))
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure but maybe it could be worth it to put this repeated code in a method on the base class?

#   match.succeeded!(user: user)

def user
  @dependencies.try(:[], :user)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that's cleaner for sure.

%tr
%td
= link_to_if can_view_all_clients?, client.last_name, client_path(client)
%td= link_to_if can_view_all_clients?, client.first_name, client_path(client)
%td= client.unavailable_as_candidate_fors.merge(UnavailableAsCandidateFor.for_route(@route))&.first&.expires_at&.to_date
%td= parked&.expires_at&.to_date
%td= parked&.user&.name_with_email
Copy link
Contributor

Choose a reason for hiding this comment

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

preload user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure we can, we're loading parked on line 36 as an N+1, so preloading the user would already be another query. Should be fine, these are paginated, and those queries should be quick.

app/models/concerns/availability.rb Outdated Show resolved Hide resolved
app/models/concerns/availability.rb Outdated Show resolved Hide resolved
app/models/concerns/availability.rb Outdated Show resolved Hide resolved
opportunity.update(available_candidate: true)
end
# Delete any non-active open matches
client_opportunity_matches.open.each(&:delete)
Copy link
Contributor

Choose a reason for hiding this comment

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

these are ClientOpportunityMatch records? It seems like calling delete rather than destroy could leave orphaned records since delete won't trigger callbacks

app/models/concerns/availability.rb Outdated Show resolved Hide resolved
end

def self.download_columns
Copy link
Contributor

Choose a reason for hiding this comment

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

This is #6133 right? Some differences here from the spec (missing Warehouse ID) but maybe that's okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warehouse ID is actually Remote ID but it needs to be paired with Remote Source because the clients come from multiple sources. So that should suffice.

@eanders eanders changed the base branch from release-58 to release-59 June 11, 2024 13:53
@eanders eanders merged commit fd08bd6 into release-59 Jun 11, 2024
16 checks passed
@eanders eanders deleted the ea/parked-download branch June 11, 2024 13:53
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.

2 participants