diff --git a/app/components/application_form_overview/component.rb b/app/components/application_form_overview/component.rb
index 236329fbc4..c78731ec21 100644
--- a/app/components/application_form_overview/component.rb
+++ b/app/components/application_form_overview/component.rb
@@ -2,9 +2,10 @@
module ApplicationFormOverview
class Component < ViewComponent::Base
- def initialize(application_form, highlight_email: false)
+ def initialize(application_form, current_staff:, highlight_email: false)
super
@application_form = application_form
+ @current_staff = current_staff
@highlight_email = highlight_email
end
@@ -15,6 +16,7 @@ def title
def summary_rows
application_form_summary_rows(
application_form,
+ current_staff:,
include_name: true,
highlight_email:,
) +
@@ -27,9 +29,7 @@ def summary_rows
text:
govuk_link_to(
I18n.t("application_form.overview.view_timeline"),
- assessor_interface_application_form_timeline_events_path(
- application_form,
- ),
+ [:assessor_interface, application_form, :timeline_events],
),
},
},
@@ -38,7 +38,7 @@ def summary_rows
private
- attr_reader :application_form, :highlight_email
+ attr_reader :application_form, :current_staff, :highlight_email
delegate :application_form_summary_rows, to: :helpers
end
diff --git a/app/components/application_form_search_result/component.rb b/app/components/application_form_search_result/component.rb
index 70265380db..2862a547d6 100644
--- a/app/components/application_form_search_result/component.rb
+++ b/app/components/application_form_search_result/component.rb
@@ -1,8 +1,11 @@
+# frozen_string_literal: true
+
module ApplicationFormSearchResult
class Component < ViewComponent::Base
- def initialize(application_form:)
+ def initialize(application_form, current_staff:)
super
@application_form = application_form
+ @current_staff = current_staff
end
def full_name
@@ -16,6 +19,7 @@ def href
def summary_rows
application_form_summary_rows(
application_form,
+ current_staff:,
include_name: false,
include_reviewer: application_form.reviewer.present?,
class_context: "app-search-result__item",
@@ -24,7 +28,7 @@ def summary_rows
private
- attr_reader :application_form
+ attr_reader :application_form, :current_staff
delegate :application_form_full_name, to: :helpers
delegate :application_form_summary_rows, to: :helpers
diff --git a/app/helpers/application_form_helper.rb b/app/helpers/application_form_helper.rb
index f2556b0d33..fbbf085e56 100644
--- a/app/helpers/application_form_helper.rb
+++ b/app/helpers/application_form_helper.rb
@@ -12,6 +12,7 @@ def application_form_full_name(application_form)
def application_form_summary_rows(
application_form,
+ current_staff:,
include_name:,
include_reviewer: true,
highlight_email: false,
@@ -27,6 +28,17 @@ def application_form_summary_rows(
value: {
text: application_form_full_name(application_form),
},
+ actions: [
+ if AssessorInterface::ApplicationFormPolicy.new(
+ current_staff,
+ application_form,
+ ).edit?
+ {
+ visually_hidden_text: I18n.t("application_form.summary.name"),
+ href: [:edit, :assessor_interface, application_form],
+ }
+ end,
+ ].compact,
}
end
),
diff --git a/app/views/assessor_interface/application_forms/index.html.erb b/app/views/assessor_interface/application_forms/index.html.erb
index 6eb7429ca3..10b918ed3c 100644
--- a/app/views/assessor_interface/application_forms/index.html.erb
+++ b/app/views/assessor_interface/application_forms/index.html.erb
@@ -71,11 +71,11 @@
- <% if @view_object.application_forms_records.any? %>
+ <% if (records = @view_object.application_forms_records).present? %>
- <%- @view_object.application_forms_records.each do |application_form| -%>
- <%= render(ApplicationFormSearchResult::Component.new(application_form:)) %>
- <%- end -%>
+ <% records.each do |application_form| %>
+ <%= render(ApplicationFormSearchResult::Component.new(application_form, current_staff:)) %>
+ <% end %>
<%= govuk_pagination(pagy: @view_object.application_forms_pagy) %>
diff --git a/app/views/assessor_interface/application_forms/show.html.erb b/app/views/assessor_interface/application_forms/show.html.erb
index 97dea122e5..e16d43ce8c 100644
--- a/app/views/assessor_interface/application_forms/show.html.erb
+++ b/app/views/assessor_interface/application_forms/show.html.erb
@@ -21,7 +21,9 @@
<%= render "shared/assessor_header", title: "Application", application_form: %>
-<%= render(ApplicationFormOverview::Component.new(application_form, highlight_email: @view_object.highlight_email?)) %>
+<%= render(ApplicationFormOverview::Component.new(
+ application_form, current_staff:, highlight_email: @view_object.highlight_email?
+)) %>
Assessment
diff --git a/spec/components/application_form_overview_component_spec.rb b/spec/components/application_form_overview_component_spec.rb
index ff66ec2ba7..87abbb5c1e 100644
--- a/spec/components/application_form_overview_component_spec.rb
+++ b/spec/components/application_form_overview_component_spec.rb
@@ -3,9 +3,12 @@
require "rails_helper"
RSpec.describe ApplicationFormOverview::Component, type: :component do
- subject(:component) { render_inline(described_class.new(application_form)) }
+ subject(:component) do
+ render_inline(described_class.new(application_form, current_staff:))
+ end
let(:application_form) { create(:application_form, :submitted) }
+ let(:current_staff) { create(:staff) }
describe "heading" do
subject(:text) { component.at_css("h2").text.strip }
diff --git a/spec/components/application_form_search_result_component_spec.rb b/spec/components/application_form_search_result_component_spec.rb
index b9e8a719c1..8a525c7a08 100644
--- a/spec/components/application_form_search_result_component_spec.rb
+++ b/spec/components/application_form_search_result_component_spec.rb
@@ -3,7 +3,9 @@
require "rails_helper"
RSpec.describe ApplicationFormSearchResult::Component, type: :component do
- subject(:component) { render_inline(described_class.new(application_form:)) }
+ subject(:component) do
+ render_inline(described_class.new(application_form, current_staff:))
+ end
let(:application_form) do
create(
@@ -14,6 +16,7 @@
family_name: "Family",
)
end
+ let(:current_staff) { create(:staff) }
describe "heading text" do
subject(:text) { component.at_css("h2").text.strip }
diff --git a/spec/helpers/application_form_helper_spec.rb b/spec/helpers/application_form_helper_spec.rb
index 81c25f2f45..77cdb189ba 100644
--- a/spec/helpers/application_form_helper_spec.rb
+++ b/spec/helpers/application_form_helper_spec.rb
@@ -33,13 +33,27 @@
describe "#application_form_summary_rows" do
subject(:summary_rows) do
- application_form_summary_rows(application_form, include_name: true)
+ application_form_summary_rows(
+ application_form,
+ current_staff:,
+ include_name: true,
+ )
end
+ let(:current_staff) { create(:staff) }
+
it do
is_expected.to eq(
[
- { key: { text: "Name" }, value: { text: "Given Family" } },
+ {
+ key: {
+ text: "Name",
+ },
+ value: {
+ text: "Given Family",
+ },
+ actions: [],
+ },
{
key: {
text: "Country trained in",
@@ -115,10 +129,36 @@
)
end
+ context "user has change name permission" do
+ let(:current_staff) { create(:staff, :with_change_name_permission) }
+
+ it "has an action to change the name" do
+ name_row = summary_rows.find { |row| row[:key][:text] == "Name" }
+
+ expect(name_row).to eq(
+ {
+ key: {
+ text: "Name",
+ },
+ value: {
+ text: "Given Family",
+ },
+ actions: [
+ {
+ visually_hidden_text: "Name",
+ href: [:edit, :assessor_interface, application_form],
+ },
+ ],
+ },
+ )
+ end
+ end
+
context "include_reviewer false" do
subject(:summary_rows_without_reviewer) do
application_form_summary_rows(
application_form,
+ current_staff:,
include_name: true,
include_reviewer: false,
)