Skip to content

Commit

Permalink
Add Policy#task_available?
Browse files Browse the repository at this point in the history
Some policies will have conditions around when a task is available. This
commit adds a new method to the base policy `task_available?` which can
be overwritten by sub policies. We also update the tasks views to show a
policy specific message when the task is not available.
  • Loading branch information
rjlynch committed Nov 8, 2024
1 parent 46254ad commit 9a031aa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/models/base_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ def decision_deadline_date(claim)
def award_amount_column
"award_amount"
end

def task_available?(task)
true
end
end
13 changes: 8 additions & 5 deletions app/views/admin/tasks/employment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
<div class="govuk-grid-column-two-thirds">
<% if @task.persisted? %>
<%= render "task_outcome", task: @task, notes: @notes %>
<% elsif @claim.policy.task_available?(@task) %>
<%= render "form", task_name: "employment", claim: @claim %>
<% else %>
<% if @task.employment_task_available? %>
<%= render "form", task_name: "employment", claim: @claim %>
<% else %>
<%= govuk_inset_text(text: "This task will be available from #{l(@claim.eligibility.employment_task_available_at)}") %>
<% end %>
<%= govuk_inset_text(
text: I18n.t(
"#{@claim.policy.to_s.underscore}.admin.task_questions.#{@task.name}.unavailable",
employment_task_available_at: l(@claim.eligibility.employment_task_available_at)
)
) %>
<% end %>

<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
Expand Down
12 changes: 10 additions & 2 deletions app/views/admin/tasks/matching_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-l"><%= @current_task_name.humanize %></h2>

<%= render("admin/claims/claims_with_matching_details", {matching_claims: @matching_claims, claim: @claim, show_caption: false}) %>
<% if @claim.policy.task_available?(@task) %>
<%= render("admin/claims/claims_with_matching_details", {matching_claims: @matching_claims, claim: @claim, show_caption: false}) %>
<% end %>
</div>

<div class="govuk-grid-column-two-thirds">
<% if @task.persisted? %>
<%= render "task_outcome", task: @task %>
<% else %>
<% elsif @claim.policy.task_available?(@task) %>
<%= render "form", task_name: "matching_details", claim: @claim %>
<% else %>
<%= govuk_inset_text(
text: I18n.t(
"#{@claim.policy.to_s.underscore}.admin.task_questions.#{@task.name}.unavailable",
)
) %>
<% end %>

<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/admin/tasks/payroll_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<% if !@task.passed.nil? %>
<%= render "task_outcome", task: @task, notes: @notes do %>
<% end %>
<% else %>
<% elsif @claim.policy.task_available?(@task) %>
<%= form_with model: [:admin, @claim, @claim.tasks.where(name: "payroll_details").first_or_initialize] do |f| %>
<div class="govuk-form-group">
<fieldset class="govuk-fieldset govuk-!-margin-bottom-6">
Expand Down Expand Up @@ -75,6 +75,12 @@
<%= f.submit "Save and continue", class: "govuk-button", data: {module: "govuk-button"} %>
</div>
<% end %>
<% else %>
<%= govuk_inset_text(
text: I18n.t(
"#{@claim.policy.to_s.underscore}.admin.task_questions.#{@task.name}.unavailable",
)
) %>
<% end %>

<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/admin/tasks/payroll_gender.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<% if @task.persisted? %>
<%= render "task_outcome", task: @task %>
<% else %>
<% elsif @claim.policy.task_available?(@task) %>
<div class="govuk-form-group">
<%= form_with url: admin_claim_payroll_gender_tasks_path(@claim), scope: :claim do |f| %>
<fieldset class="govuk-fieldset govuk-!-margin-bottom-6">
Expand Down Expand Up @@ -46,6 +46,12 @@
<%= f.submit "Save and continue", class: "govuk-button", data: {module: "govuk-button"} %>
<% end %>
</div>
<% else %>
<%= govuk_inset_text(
text: I18n.t(
"#{@claim.policy.to_s.underscore}.admin.task_questions.#{@task.name}.unavailable",
)
) %>
<% end %>

<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/admin/tasks/student_loan_plan.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="govuk-grid-column-two-thirds">
<% if @task.persisted? %>
<%= render "task_outcome", task: @task %>
<% else %>
<% elsif @claim.policy.task_available?(@task) %>
<%= render "admin/tasks/notes", notes: @notes, display_description: false %>
<div class="govuk-inset-text task-outcome">
<p class="govuk-body">
Expand All @@ -27,6 +27,12 @@
No matching entry has been found in the Student Loan Company data yet.
</p>
</div>
<% else %>
<%= govuk_inset_text(
text: I18n.t(
"#{@claim.policy.to_s.underscore}.admin.task_questions.#{@task.name}.unavailable",
)
) %>
<% end %>

<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
Expand Down

0 comments on commit 9a031aa

Please sign in to comment.