Skip to content

Commit

Permalink
Merge pull request #2379 from DFE-Digital/ghana-validation-number
Browse files Browse the repository at this point in the history
Add teacher license form for Ghana
  • Loading branch information
Hassanmir92 authored Sep 5, 2024
2 parents 7456e95 + 7c32ef8 commit bbd3b39
Show file tree
Hide file tree
Showing 19 changed files with 665 additions and 10 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ PLATFORMS
arm64-darwin-23
x86_64-darwin-21
x86_64-darwin-22
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,51 @@ class RegistrationNumberController < BaseController

def edit
@form =
RegistrationNumberForm.new(
form_class.new(
application_form:,
registration_number: application_form.registration_number,
)

render view_name
end

def update
@form = RegistrationNumberForm.new(form_params.merge(application_form:))
@form = form_class.new(form_params.merge(application_form:))

handle_application_form_section(form: @form)
handle_application_form_section(
form: @form,
if_failure_then_render: view_name,
)
end

private

def ghana?
CountryCode.ghana?(application_form.country.code)
end

def form_params
params.require(:teacher_interface_registration_number_form).permit(
:registration_number,
)
if ghana?
params.require(
:teacher_interface_ghana_registration_number_form,
).permit(
:license_number_part_one,
:license_number_part_two,
:license_number_part_three,
)
else
params.require(:teacher_interface_registration_number_form).permit(
:registration_number,
)
end
end

def view_name
ghana? ? :edit_ghana : :edit
end

def form_class
ghana? ? GhanaRegistrationNumberForm : RegistrationNumberForm
end
end
end
57 changes: 57 additions & 0 deletions app/forms/teacher_interface/ghana_registration_number_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

module TeacherInterface
class GhanaRegistrationNumberForm < BaseForm
attr_accessor :application_form

attribute :registration_number, :string
attribute :license_number_part_one, :string
attribute :license_number_part_two, :string
attribute :license_number_part_three, :string

validates :application_form, presence: true

validate :license_number_parts_valid

def initialize(attributes = {})
super

if attributes[:registration_number].present?
license_number_parts = attributes[:registration_number].split("/")

self.license_number_part_one = license_number_parts[0]
self.license_number_part_two = license_number_parts[1]
self.license_number_part_three = license_number_parts[2]
end
end

def update_model
application_form.update!(registration_number:)
end

def registration_number_validator
@registration_number_validator ||=
RegistrationNumberValidators::Ghana.new(registration_number:)
end

private

def license_number_parts_valid
return if registration_number_validator.valid?

errors.add(:registration_number, :invalid)
end

def registration_number
registration_number_parts = [
license_number_part_one,
license_number_part_two,
license_number_part_three,
].map(&:strip)

return nil if registration_number_parts.compact_blank.empty?

registration_number_parts.join("/")
end
end
end
12 changes: 11 additions & 1 deletion app/lib/application_form_section_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@ def work_history_status
end

def registration_number_status
registration_number.nil? ? :not_started : :completed
if CountryCode.ghana?(application_form.country.code)
if registration_number.present?
registration_number_validator =
RegistrationNumberValidators::Ghana.new(registration_number:)
registration_number_validator.valid? ? :completed : :in_progress
else
:not_started
end
else
registration_number.nil? ? :not_started : :completed
end
end

def written_statement_status
Expand Down
4 changes: 4 additions & 0 deletions app/lib/country_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def northern_ireland?(code)
code == "GB-NIR"
end

def ghana?(code)
code == "GH"
end

def european_economic_area?(code)
Country::CODES_IN_EUROPEAN_ECONOMIC_AREA.include?(code)
end
Expand Down
41 changes: 41 additions & 0 deletions app/lib/registration_number_validators/ghana.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module RegistrationNumberValidators
class Ghana
def initialize(registration_number:)
@registration_number = registration_number

registration_number_parts = registration_number.to_s.split("/")

@license_number_part_one = registration_number_parts[0]
@license_number_part_two = registration_number_parts[1]
@license_number_part_three = registration_number_parts[2]
end

def valid?
license_number_part_one_valid? && license_number_part_two_valid? &&
license_number_part_three_valid?
end

def license_number_part_one_valid?
license_number_part_one.to_s.length == 2 &&
license_number_part_one.match?(/\A[a-zA-Z]*\z/)
end

def license_number_part_two_valid?
license_number_part_two.to_s.length == 6 &&
license_number_part_two.match?(/^[0-9]+$/)
end

def license_number_part_three_valid?
license_number_part_three.to_s.length == 4 &&
license_number_part_three.match?(/^[0-9]+$/)
end

private

attr_reader :license_number_part_one,
:license_number_part_two,
:license_number_part_three
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def task_list_item_name(key)
else
I18n.t("application_form.tasks.items.written_statement.upload")
end
elsif key == :registration_number
if CountryCode.ghana?(application_form.country.code)
I18n.t("application_form.tasks.items.registration_number.ghana")
else
I18n.t("application_form.tasks.items.registration_number.other")
end
else
I18n.t("application_form.tasks.items.#{key}")
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= render(CheckYourAnswersSummary::Component.new(
id: "registration-number",
model: application_form,
title: I18n.t("application_form.tasks.items.registration_number"),
title: t(CountryCode.ghana?(application_form.country.code) ? "ghana" : "other", scope: %i[application_form tasks items registration_number]),
fields: {
registration_number: {
href: %i[registration_number teacher_interface application_form]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% content_for :page_title, title_with_error_prefix(t("application_form.tasks.items.registration_number"), error: @form.errors.any?) %>
<% content_for :page_title, title_with_error_prefix(t("application_form.tasks.items.registration_number.other"), error: @form.errors.any?) %>
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %>

<%= form_with model: @form, url: %i[registration_number teacher_interface application_form] do |f| %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<% content_for :page_title, title_with_error_prefix(t("application_form.tasks.items.registration_number.ghana"), error: @form.errors.any?) %>
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %>

<%= form_with model: @form, url: %i[registration_number teacher_interface application_form] do |f| %>
<%= f.govuk_error_summary %>

<div class="govuk-form-group <%= 'govuk-form-group--error' if @form.errors.present? %>">
<fieldset class="govuk-fieldset" aria-describedby="teacher-interface-ghana-registration-number-form-registration-number-hint">
<h1 class="govuk-label-wrapper">
<label for="teacher-interface-ghana-registration-number-form-registration-number-field" class="govuk-label govuk-label--l">
<%= t("helpers.label.teacher_interface_ghana_registration_number_form.registration_number") %>
</label>
</h1>
<div class="govuk-hint" id="teacher-interface-ghana-registration-number-form-registration-number-hint">
<%= t("helpers.hint.teacher_interface_ghana_registration_number_form.registration_number") %>
</div>

<% if @form.errors.present? %>
<p id="teacher-interface-ghana-registration-number-form-registration-number-field-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span>
<%= @form.errors.first.message %>
</p>
<% end %>

<div class="govuk-date-input">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<input id="teacher-interface-ghana-registration-number-form-license-number-part-one"
class="govuk-input govuk-date-input__input govuk-input--width-2 <%= 'govuk-input--error' if @form.errors.present? && !@form.registration_number_validator.license_number_part_one_valid? %>"
name="teacher_interface_ghana_registration_number_form[license_number_part_one]"
type="text" inputmode="text" value=<%= @form.license_number_part_one %>>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<input id="teacher-interface-ghana-registration-number-form-license-number-part-two"
class="govuk-input govuk-date-input__input govuk-input--width-4 <%= 'govuk-input--error' if @form.errors.present? && !@form.registration_number_validator.license_number_part_two_valid? %>"
name="teacher_interface_ghana_registration_number_form[license_number_part_two]"
type="text"
inputmode="numeric"
value=<%= @form.license_number_part_two %>>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<input id="teacher-interface-ghana-registration-number-form-license-number-part-three"
class="govuk-input govuk-date-input__input govuk-input--width-3 <%= 'govuk-input--error' if @form.errors.present? && !@form.registration_number_validator.license_number_part_three_valid? %>"
name="teacher_interface_ghana_registration_number_form[license_number_part_three]"
type="text"
inputmode="numeric"
value=<%= @form.license_number_part_three %>>
</div>
</div>
</div>
</fieldset>
</div>

<div class="govuk-!-padding-bottom-3"></div>

<h2 class="govuk-heading-m">Finding and checking your teacher license number</h2>
<p class="govuk-body">
You can get your teacher license number by signing in to your <%= link_to "Teacher Portal Ghana account", "https://tpg.ntc.gov.gh/account/login/teacher" %>.</p>
<p class="govuk-body">You can check your number on the <%= link_to "Teacher Portal Ghana website", "https://tpg.ntc.gov.gh/public/teacher/verify-license" %>.</p>
<p class="govuk-body">If you cannot find your teaching license number, contact the <%= link_to "Ghana National Teaching Council", "https://ntc.gov.gh/" %>.</p>

<div class="govuk-!-padding-bottom-3"></div>

<h2 class="govuk-heading-m">Why we need your teacher license number</h2>
<p class="govuk-body">
We use this number to verify you are registered to teach in Ghana.
If you do not have one, we will not be able to verify you. This means your application will be declined. We do not accept other registration or license numbers.
</p>

<div class="govuk-!-padding-bottom-3"></div>

<%= render "shared/save_submit_buttons", f: %>
<% end %>
4 changes: 4 additions & 0 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ en:
provider: The test must have been taken within the last 2 years. We cannot accept English language tests from a provider that does not appear on the list.
teacher_interface_further_information_request_item_text_form:
response: Use the text box below to respond to the assessor’s question.
teacher_interface_ghana_registration_number_form:
registration_number: Your teacher license number is made up of 2 letters, 6 numbers and a final 4 numbers. For example, PT/123456/1234.
teacher_interface_has_work_history_form:
has_work_history: If you’re a recent university graduate, or you've just completed your teaching qualification, you may not have held a professional teaching position yet.
teacher_interface_new_session_form:
Expand Down Expand Up @@ -223,6 +225,8 @@ en:
provider: Upload proof of a Secure English Language Test (SELT) at B2 level, from one of the approved providers.
teacher_interface_further_information_request_item_text_form:
response: Enter your response
teacher_interface_ghana_registration_number_form:
registration_number: Enter your teacher license number
teacher_interface_has_work_history_form:
has_work_history_options:
true: "Yes"
Expand Down
8 changes: 7 additions & 1 deletion config/locales/teacher_interface.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ en:
subjects: Enter the subjects you can teach
english_language: Verify your English language proficiency
work_history: Add your work history
registration_number: Enter your registration number
registration_number:
ghana: Enter your teacher license number
other: Enter your registration number
written_statement:
upload: Upload your written statement
provide: Provide your written statement
Expand Down Expand Up @@ -319,6 +321,10 @@ en:
attributes:
downloaded:
blank: Confirm that you have downloaded the consent document.
teacher_interface/ghana_registration_number_form:
attributes:
registration_number:
invalid: Enter your teacher license number. It is made up of 2 letters, 6 numbers and a final 4 numbers. For example, PT/123456/1234.
teacher_interface/reference_request_children_response_form:
attributes:
children_response:
Expand Down
Loading

0 comments on commit bbd3b39

Please sign in to comment.