Skip to content

Commit

Permalink
Merge pull request #1621 from DFE-Digital/change-name
Browse files Browse the repository at this point in the history
Add change applicant name functionality
  • Loading branch information
thomasleese authored Sep 6, 2023
2 parents 8c18d54 + ffcab97 commit 0509fcd
Show file tree
Hide file tree
Showing 51 changed files with 569 additions and 321 deletions.
11 changes: 5 additions & 6 deletions app/components/application_form_overview/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -15,8 +16,8 @@ def title
def summary_rows
application_form_summary_rows(
application_form,
current_staff:,
include_name: true,
include_reference: true,
highlight_email:,
) +
[
Expand All @@ -28,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],
),
},
},
Expand All @@ -39,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
Expand Down
10 changes: 7 additions & 3 deletions app/components/application_form_search_result/component.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,15 +19,16 @@ def href
def summary_rows
application_form_summary_rows(
application_form,
current_staff:,
include_name: false,
include_reference: true,
include_reviewer: application_form.reviewer.present?,
class_context: "app-search-result__item",
)
end

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
Expand Down
28 changes: 28 additions & 0 deletions app/controllers/assessor_interface/application_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ def status
@view_object = show_view_object
end

def edit
authorize [:assessor_interface, application_form]

@form = ApplicationFormNameForm.new
end

def update
authorize [:assessor_interface, application_form]

@form =
ApplicationFormNameForm.new(
form_params.merge(application_form:, user: current_staff),
)

if @form.save
redirect_to [:assessor_interface, application_form]
else
render :edit, status: :unprocessable_entity
end
end

def withdraw
authorize [:assessor_interface, application_form]
end
Expand Down Expand Up @@ -65,5 +86,12 @@ def show_view_object
def application_form
@application_form ||= show_view_object.application_form
end

def form_params
params.require(:assessor_interface_application_form_name_form).permit(
:given_names,
:family_name,
)
end
end
end
1 change: 1 addition & 0 deletions app/controllers/staff/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def configure_permitted_parameters
keys: %i[
name
award_decline_permission
change_name_permission
change_work_history_permission
reverse_decision_permission
support_console_permission
Expand Down
1 change: 1 addition & 0 deletions app/controllers/support_interface/staff_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def load_staff
def staff_params
params.require(:staff).permit(
:award_decline_permission,
:change_name_permission,
:change_work_history_permission,
:reverse_decision_permission,
:support_console_permission,
Expand Down
25 changes: 25 additions & 0 deletions app/forms/assessor_interface/application_form_name_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

class AssessorInterface::ApplicationFormNameForm
include ActiveModel::Model
include ActiveModel::Attributes

attr_accessor :application_form, :user
attribute :given_names, :string
attribute :family_name, :string

validates :application_form, :user, presence: true

def save
return false if invalid?

UpdateApplicationFormName.call(
application_form:,
user:,
given_names:,
family_name:,
)

true
end
end
184 changes: 114 additions & 70 deletions app/helpers/application_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,98 +12,142 @@ def application_form_full_name(application_form)

def application_form_summary_rows(
application_form,
current_staff:,
include_name:,
include_reference:,
include_reviewer: true,
highlight_email: false
highlight_email: false,
class_context: nil
)
[
(
if include_name
[
I18n.t("application_form.summary.name"),
application_form_full_name(application_form),
]
{
key: {
text: I18n.t("application_form.summary.name"),
},
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
),
[
I18n.t("application_form.summary.country"),
CountryName.from_country(application_form.region.country),
],
[
I18n.t("application_form.summary.email"),
(
if highlight_email
"<em class=\"app-highlight\">#{ERB::Util.html_escape(application_form.teacher.email)}</em>".html_safe
else
application_form.teacher.email
end
),
],
{
key: {
text: I18n.t("application_form.summary.country"),
},
value: {
text: CountryName.from_country(application_form.region.country),
},
},
(
if application_form.region.name.present?
[
I18n.t("application_form.summary.region"),
application_form.region.name,
]
{
key: {
text: I18n.t("application_form.summary.region"),
},
value: {
text: application_form.region.name,
},
}
end
),
[
I18n.t("application_form.summary.submitted_at"),
application_form.submitted_at.strftime("%e %B %Y"),
],
[
I18n.t("application_form.summary.days_since_submission"),
pluralize(application_form.working_days_since_submission, "day"),
],
[
I18n.t("application_form.summary.assessor"),
application_form.assessor&.name ||
I18n.t("application_form.summary.unassigned"),
[
{
key: {
text: I18n.t("application_form.summary.email"),
},
value: {
text:
(
if highlight_email
"<em class=\"app-highlight\">#{ERB::Util.html_escape(application_form.teacher.email)}</em>".html_safe
else
application_form.teacher.email
end
),
},
},
{
key: {
text: I18n.t("application_form.summary.submitted_at"),
},
value: {
text: application_form.submitted_at.strftime("%e %B %Y"),
},
},
{
key: {
text: I18n.t("application_form.summary.days_since_submission"),
},
value: {
text:
pluralize(application_form.working_days_since_submission, "day"),
},
},
{
key: {
text: I18n.t("application_form.summary.assessor"),
},
value: {
text:
application_form.assessor&.name ||
I18n.t("application_form.summary.unassigned"),
},
actions: [
{
href:
assessor_interface_application_form_assign_assessor_path(
application_form,
),
visually_hidden_text: I18n.t("application_form.summary.assessor"),
href: [:assessor_interface, application_form, :assign_assessor],
},
],
],
},
(
if include_reviewer
[
I18n.t("application_form.summary.reviewer"),
application_form.reviewer&.name ||
I18n.t("application_form.summary.unassigned"),
[
{
key: {
text: I18n.t("application_form.summary.reviewer"),
},
value: {
text:
application_form.reviewer&.name ||
I18n.t("application_form.summary.unassigned"),
},
actions: [
{
href:
assessor_interface_application_form_assign_reviewer_path(
application_form,
),
visually_hidden_text:
I18n.t("application_form.summary.reviewer"),
href: [:assessor_interface, application_form, :assign_reviewer],
},
],
]
end
),
(
if include_reference
[
I18n.t("application_form.summary.reference"),
application_form.reference,
]
}
end
),
[
I18n.t("application_form.summary.status"),
application_form_status_tags(
application_form,
class_context: "app-search-result__item",
),
],
].compact.map do |key, value, actions|
{ key: { text: key }, value: { text: value }, actions: actions || [] }
end
{
key: {
text: I18n.t("application_form.summary.reference"),
},
value: {
text: application_form.reference,
},
},
{
key: {
text: I18n.t("application_form.summary.status"),
},
value: {
text: application_form_status_tags(application_form, class_context:),
},
},
].compact
end

def application_form_display_work_history_before_teaching_qualification_banner?(
Expand Down
1 change: 1 addition & 0 deletions app/models/staff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# id :bigint not null, primary key
# award_decline_permission :boolean default(FALSE)
# azure_ad_uid :string
# change_name_permission :boolean default(FALSE), not null
# change_work_history_permission :boolean default(FALSE), not null
# confirmation_sent_at :datetime
# confirmation_token :string
Expand Down
4 changes: 4 additions & 0 deletions app/policies/assessor_interface/application_form_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def show?
true
end

def update?
user.change_name_permission
end

def destroy?
user.withdraw_permission
end
Expand Down
Loading

0 comments on commit 0509fcd

Please sign in to comment.