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

[CAPT-1915] Improve admin allocations #3411

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 53 additions & 22 deletions app/controllers/admin/allocations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,74 @@ def deallocate
end

def bulk_allocate
claims = Claim.where(assigned_to: nil).includes(:decisions, eligibility: [:claim_school, :current_school]).awaiting_decision.order(:submitted_at).limit(params[:allocate_claim_count])
claims = Claim
.where(assigned_to: nil)
.includes(:decisions, eligibility: [:claim_school, :current_school])
.awaiting_decision
.order(:submitted_at)
.limit(params[:allocate_claim_count])
claims = claims.by_policy(filtered_policy) if filtered_policy

redirect_to admin_claims_path, notice: I18n.t("admin.allocations.bulk_allocate.info", allocate_to_policy: params[:allocate_to_policy].titleize, dfe_user: @team_member.full_name.titleize) and return if claims.size.zero?

ClaimAllocator.new(claim_ids: claims.map(&:id), admin_user_id: params[:allocate_to_team_member]).call
allocate_to_policy = params[:allocate_to_policy].nil? ? "" : params[:allocate_to_policy].titleize
if claims.size.zero?
redirect_to admin_claims_path,
notice: I18n.t(
"admin.allocations.bulk_allocate.info",
allocate_to_policy: policy_name,
dfe_user: @team_member.full_name.titleize
) and return
end

redirect_to request.referrer, notice: I18n.t("admin.allocations.bulk_allocate.success", quantity: claims.size, pluralized_or_singular_claim: "claim".pluralize(claims.size), allocate_to_policy: allocate_to_policy, dfe_user: @team_member.full_name.titleize)
ClaimAllocator.new(
claim_ids: claims.map(&:id),
admin_user_id: params[:allocate_to_team_member]
).call

redirect_to request.referrer,
notice: I18n.t(
"admin.allocations.bulk_allocate.success",
quantity: claims.size,
pluralized_or_singular_claim: "claim".pluralize(claims.size),
allocate_to_policy: policy_name,
dfe_user: @team_member.full_name.titleize
)
end

def bulk_deallocate
claims = Claim.where(assigned_to_id: @team_member.id)
claims = claims.by_policy(filtered_policy) if filtered_policy

if filtered_policy
claims = claims.by_policy(filtered_policy) if filtered_policy

redirect_to admin_claims_path, notice: I18n.t("admin.allocations.bulk_deallocate.info", allocate_to_policy: params[:allocate_to_policy].titleize, dfe_user: @team_member.full_name.titleize) and return if claims.size.zero?

ClaimDeallocator.new(claim_ids: claims.ids, admin_user_id: @team_member.id).call

redirect_to admin_claims_path, notice: I18n.t("admin.allocations.bulk_deallocate.success", allocate_to_policy: params[:allocate_to_policy].titleize, dfe_user: @team_member.full_name.titleize) and return
else
redirect_to admin_claims_path, notice: I18n.t("admin.allocations.bulk_deallocate.info", allocate_to_policy: "", dfe_user: @team_member.full_name.titleize) and return if claims.size.zero?

ClaimDeallocator.new(claim_ids: claims.ids, admin_user_id: params[:allocate_to_team_member]).call

redirect_to admin_claims_path, notice: I18n.t("admin.allocations.bulk_deallocate.success", allocate_to_policy: "", dfe_user: @team_member.full_name.titleize) and return
if claims.size.zero?
redirect_to admin_claims_path,
notice: I18n.t(
"admin.allocations.bulk_deallocate.info",
allocate_to_policy: policy_name,
dfe_user: @team_member.full_name.titleize
) and return
end

ClaimDeallocator.new(
claim_ids: claims.ids,
admin_user_id: @team_member.id
).call

redirect_to admin_claims_path,
notice: I18n.t(
"admin.allocations.bulk_deallocate.success",
allocate_to_policy: policy_name,
dfe_user: @team_member.full_name.titleize
) and return
end

helper_method :filtered_policy

private

def load_target_claim
@claim = Claim.find(params[:id])
end

def load_team_member
@team_member = DfeSignIn::User.find params[:allocate_to_team_member]
@team_member = DfeSignIn::User.find(params[:allocate_to_team_member])
end

def filtered_policy
Expand All @@ -77,7 +106,9 @@ def team_member_id
end

def policy_name
params[:allocate_to_policy]
if filtered_policy.present?
filtered_policy.short_name
end
end

def user_confirmed?
Expand Down
14 changes: 8 additions & 6 deletions app/views/admin/allocations/bulk_deallocate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
<%= t("admin.allocations.bulk_deallocate.confirmation",
allocate_to_policy: policy_name&.titleize,
allocate_to_policy: policy_name,
dfe_user: @team_member.full_name.titleize) %>
</h1>

<%= form_with url: admin_bulk_deallocate_path, method: :patch do |f| %>
<%= form_with url: admin_bulk_deallocate_path, method: :patch, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.hidden_field :allocate_to_team_member, value: team_member_id %>
<%= f.hidden_field :allocate_to_policy, value: policy_name %>
<%= f.hidden_field :user_confirmation, value: 'yes' %>
<%= f.hidden_field :allocate_to_policy, value: filtered_policy&.policy_type %>
<%= f.hidden_field :user_confirmation, value: "yes" %>

<%= f.submit "Unassign", class: "govuk-button govuk-button--warning" %>
<%= link_to "Cancel", admin_claims_path, class: "govuk-button govuk-button--secondary govuk-!-margin-left-1", role: "button", data: { module: "govuk-button" } %>
<div class="govuk-button-group">
<%= f.govuk_submit "Unassign", warning: true %>
<%= govuk_button_link_to "Cancel", admin_claims_path, secondary: true %>
</div>
<% end %>
</div>
</div>
8 changes: 4 additions & 4 deletions spec/features/admin/admin_claim_allocation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@
select "Early-Career Payments", from: "allocate_to_policy"
click_on "Unallocate"

expect(page).to have_text "Are you sure you want to unassign Early Career Payments claims from Frank Yee?"
expect(page).to have_text "Are you sure you want to unassign Early-Career Payments claims from Frank Yee?"

click_on "Unassign"

within(".govuk-flash__notice") do
expect(page).to have_text I18n.t("admin.allocations.bulk_deallocate.success", allocate_to_policy: "Early Career Payments", dfe_user: frank.full_name)
expect(page).to have_text I18n.t("admin.allocations.bulk_deallocate.success", allocate_to_policy: "Early-Career Payments", dfe_user: frank.full_name)
end

student_loan_claims.each do |claim|
Expand Down Expand Up @@ -416,12 +416,12 @@
select "Early-Career Payments", from: "allocate_to_policy"
click_on "Unallocate"

expect(page).to have_text "Are you sure you want to unassign Early Career Payments claims from Abdul Rafiq?"
expect(page).to have_text "Are you sure you want to unassign Early-Career Payments claims from Abdul Rafiq?"

click_on "Unassign"

within(".govuk-flash__notice") do
expect(page).to have_text I18n.t("admin.allocations.bulk_deallocate.info", allocate_to_policy: "Early Career Payments", dfe_user: abdul.full_name)
expect(page).to have_text I18n.t("admin.allocations.bulk_deallocate.info", allocate_to_policy: "Early-Career Payments", dfe_user: abdul.full_name)
end

student_loan_claims.each do |claim|
Expand Down