Skip to content
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
32 changes: 32 additions & 0 deletions app/assets/javascripts/faf_select_school.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Deselect school_urn radio buttons if a group_uid is selected and vice versa
*/

function uncheck(radioButtons) {
radioButtons.forEach(r => r.checked = false);
}

window.addEventListener("load", () => {
const schoolRadioButtons = document.querySelectorAll("input[name='framework_support_form[school_urn]'][type=radio]");
const groupRadioButtons = document.querySelectorAll("input[name='framework_support_form[group_uid]'][type=radio]");
const schoolField = document.querySelector("input[name='framework_support_form[school_urn]'][type=hidden]");
const groupField = document.querySelector("input[name='framework_support_form[group_uid]'][type=hidden]");

schoolRadioButtons.forEach(r => {
r.addEventListener("change", () => {
if (r.checked) {
uncheck(groupRadioButtons);
groupField.value = null;
}
});
});

groupRadioButtons.forEach(r => {
r.addEventListener("change", () => {
if (r.checked) {
uncheck(schoolRadioButtons);
schoolField.value = null;
}
});
});
});
27 changes: 20 additions & 7 deletions app/controllers/framework_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def create
@organisation = organisation
@establishment_group = establishment_group

forget_org

# DSI users clicking back on the FaF support form skip steps intended for guests
if form_params[:back] == "true" || form_params[:correct_group] == "false" || form_params[:correct_organisation] == "false"

Expand All @@ -51,14 +53,14 @@ def create
)

# authenticated user / inferred school / message step -> start page
if @framework_support_form.position?(7) && !current_user.guest? && !current_user.school_urn.nil?
if @framework_support_form.position?(7) && !current_user.guest? && current_user.single_org?
redirect_to framework_requests_path
# authenticated user / many schools / message step -> choose school step
elsif @framework_support_form.position?(7) && !current_user.guest? && current_user.school_urn.nil?
elsif @framework_support_form.position?(7) && !current_user.guest? && !current_user.single_org?
@framework_support_form.back!(4)
render :new
# authenticated user / many schools / school step -> start page
elsif @framework_support_form.position?(3) && !current_user.guest? && current_user.school_urn.nil?
elsif @framework_support_form.position?(3) && !current_user.guest? && !current_user.single_org?
redirect_to framework_requests_path
else
@framework_support_form.back!
Expand Down Expand Up @@ -97,6 +99,7 @@ def create
def update
@framework_support_form = form
if validation.success?
forget_org

# capture full "xxxxx - name"
session[:faf_school] = @framework_support_form.school_urn
Expand Down Expand Up @@ -158,7 +161,7 @@ def initial_position
if current_user.guest?
1
else
current_user.school_urn ? 7 : 3
current_user.school_urn || current_user.group_uid ? 7 : 3
end
end

Expand All @@ -174,17 +177,19 @@ def conditional_form_params
last_name: current_user.last_name, # (step 5)
email: current_user.email, # (step 6)
school_urn: current_user.school_urn, # (step 3)
group_uid: nil, # (step 3)
group_uid: current_user.group_uid, # (step 3)
# message (step 7)
}
end
end

# TODO: extract into a service rather than access supported data directly
# @return [OrganisationPresenter, nil]
def organisation
Support::OrganisationPresenter.new(Support::Organisation.find_by(urn: urn)) if urn
end

# TODO: extract into a service rather than access supported data directly
def establishment_group
Support::EstablishmentGroupPresenter.new(Support::EstablishmentGroup.find_by(uid: group_uid)) if group_uid
end
Expand All @@ -195,7 +200,7 @@ def establishment_group
#
# @return [String, nil]
def urn
form_params[:school_urn]&.split(" - ")&.first || @framework_request&.school_urn
form_params[:school_urn]&.split(" - ")&.first
end

# Extract the group UID from the format "uid - group name"
Expand All @@ -204,6 +209,14 @@ def urn
#
# @return [String, nil]
def group_uid
form_params[:group_uid]&.split(" - ")&.first || @framework_request&.group_uid
form_params[:group_uid]&.split(" - ")&.first
end

def forget_org
if @framework_support_form.position?(3) && @framework_support_form.has_school?
@framework_support_form.forget_group!
elsif @framework_support_form.position?(3) && @framework_support_form.has_group?
@framework_support_form.forget_school!
end
end
end
41 changes: 28 additions & 13 deletions app/forms/framework_support_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class FrameworkSupportForm < Form
# @return [String]
option :email, optional: true # 4 (skipped if logged in)

option :group, optional: true

# @!attribute [r] school_urn
# @return [String] URN identifier and name in the format "100000 - School Name"
option :school_urn, optional: true # 5 (skipped if inferred at login)
Expand Down Expand Up @@ -60,16 +58,33 @@ def guest?
!dsi?
end

# TODO: - ref for ticket 231
# # @return [nil]
# def forget_school_urn!
# instance_variable_set :@school_urn, nil
# end

# TODO: - ref for ticket 231
# # @return [nil]
# def forget_group_uid!
# instance_variable_set :@group_uid, nil
# end
# @see FrameworkRequestsController#create
#
# @return [Boolean] school URN is present
def has_school?
school_urn.present?
end

# @see FrameworkRequestsController#create
#
# @return [Boolean] group UID is present
def has_group?
group_uid.present?
end

# @return [nil]
def forget_school!
instance_variable_set :@school_urn, nil
end

# @return [nil]
def forget_group!
instance_variable_set :@group_uid, nil
end

# @return [Boolean]
def multiple_schools?
instance_variable_get :@group
end
end
# :nocov:
22 changes: 20 additions & 2 deletions app/forms/framework_support_form_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class FrameworkSupportFormSchema < Schema
optional(:correct_organisation).value(:bool) # step 6

optional(:correct_group).value(:bool) # step 6

optional(:affiliation).value(:string)
end

rule(:first_name) do
Expand All @@ -43,15 +45,31 @@ class FrameworkSupportFormSchema < Schema
end

rule(:school_urn) do
key.failure(:missing) if key? && !values[:group] && Support::Organisation.find_by(urn: value.split(" - ").first).nil?
# validate individual school_urn field only in the non-dsi journey
key.failure(:missing) if key? && !values[:dsi] && !values[:group] && !org_exists?(value.split(" - ").first, false)
end

rule(:group_uid) do
key.failure(:missing) if key? && values[:group] && Support::EstablishmentGroup.find_by(uid: value.split(" - ").first).nil?
# validate individual group_uid field only in the non-dsi journey
key.failure(:missing) if key? && !values[:dsi] && values[:group] && !org_exists?(value.split(" - ").first, true)
end

rule(:message_body) do
key.failure(:missing) if key? && value.blank?
end

rule(:affiliation) do
# validate that either school_urn or group_uid is provided in the dsi journey
key.failure(:missing) if values[:dsi] && values[:school_urn].blank? && values[:group_uid].blank?
end

# TODO: extract into a service rather than access supported data directly
def org_exists?(id, group)
if group
Support::EstablishmentGroup.find_by(uid: id).present?
Comment thread
EdwinKruglov marked this conversation as resolved.
else
Support::Organisation.find_by(urn: id).present?
end
end
end
# :nocov:
42 changes: 28 additions & 14 deletions app/presenters/user_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ def active_journeys

# @return [String, nil] inferred unique school identifier
def school_urn
supported_schools.first.urn if supported_schools.one?
supported_orgs.first.urn if single_org? && !supported_orgs.first.group
end

# TODO: - ref for ticket 231
# # @return [String, nil] inferred unique school identifier
# def group_uid
# supported_groups.first.uid if supported_groups.one?
# end
# @return [Boolean]
def single_org?
supported_orgs.one?
end

# @return [String, nil] inferred unique group identifier
def group_uid
supported_orgs.first.uid if single_org? && supported_orgs.first.group
end

# @return [String, nil] inferred school name
# def school_name
Expand All @@ -28,18 +32,28 @@ def supported_schools
orgs.map { |org|
next unless org.dig("type", "id").to_i.in?(ORG_TYPE_IDS)

OpenStruct.new(name: org["name"], urn: org["urn"])
OpenStruct.new(name: org["name"], urn: org["urn"], group: false)
}.compact
end

# TODO: - ref for ticket 231
# def supported_groups
# orgs.map { |org|
# next unless org.dig("category", "id").to_i.in?(GROUP_CATEGORY_IDS)
# Support/FaF request form options when a single UID cannot be inferred
#
# @return [Array<OpenStruct>] the name/uid of a user's supported groups
def supported_groups
orgs.map { |org|
next unless org.dig("category", "id").to_i.in?(GROUP_CATEGORY_IDS)

OpenStruct.new(name: "#{org['name']} (MAT)", uid: org["uid"], group: true)
}.compact
end

# OpenStruct.new(name: org["name"], uid: org["uid"])
# }.compact
# end
# FaF request form options (schools and trusts) when a single UID cannot be inferred
#
# @return [Array<OpenStruct>] the name/uid of a user's supported organisations
def supported_orgs
all_orgs = supported_schools + supported_groups
all_orgs.sort_by(&:name)
end

# @return [String]
def full_name
Expand Down
2 changes: 1 addition & 1 deletion app/views/framework_requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<% end %>
<dd class="govuk-summary-list__actions">
<% unless @framework_request.submitted? %>
<%= link_to I18n.t("generic.button.change_answer"), edit_framework_request_path(@framework_request, step: 3), class: "govuk-link", id: "edit-school" unless current_user.supported_schools.one? %>
<%= link_to I18n.t("generic.button.change_answer"), edit_framework_request_path(@framework_request, step: 3), class: "govuk-link", id: "edit-school" unless current_user.single_org? %>
<% end %>
</dd>
</div>
Expand Down
20 changes: 12 additions & 8 deletions app/views/framework_requests/steps/_step_3.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ form_data = @framework_support_form.to_h.merge(step: @framework_support_form.ste
<% if !current_user.guest? %>
<%= content_for :title, I18n.t("faf.user_organisation.header") %>

<%= form.govuk_collection_radio_buttons :school_urn,
current_user.supported_schools,
:urn,
:name,
caption: { text: I18n.t("faf.which_school.caption"), size: "l" },
legend: { text: I18n.t("faf.which_school.legend"), size: "l" }
%>
<% elsif form.object.group == true %>
<%= form.govuk_radio_buttons_fieldset(:org_id, caption: { text: I18n.t("faf.which_school.caption"), size: "l" }, legend: { text: I18n.t("faf.which_school.legend"), size: "l" }) do %>
<% current_user.supported_orgs.each do |org| %>
<% if org.urn %>
<%= form.govuk_radio_button :school_urn, org.urn, label: { text: org.name } %>
<% else %>
<%= form.govuk_radio_button :group_uid, org.uid, label: { text: org.name } %>
<% end %>
<% end %>
<% end %>

<%= javascript_include_tag "faf_select_school" %>
<% elsif @framework_support_form.multiple_schools? %>
<%= render "framework_requests/steps/search_for_a_group", form: form, form_data: form_data %>
<% else %>
<%= render "framework_requests/steps/search_for_a_school", form: form, form_data: form_data %>
Expand Down
15 changes: 8 additions & 7 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ en:
- Private, voluntary-aided and independent early years providers and institutions that provide only for pupils aged 16+ are not eligible for this service.
unsupported_organisation:
page_title: Your organisation is not supported by this service
supported_schools: "This service is for those procuring for one school, either:"
supported_schools: "This service is for those procuring for a school in England. We can provide support to:"
supported_schools_list:
- a local authority maintained school, or
- one academy within a single or multi-academy trust
- a local authority maintained school
- a federation school
- an academy in a single or multi-academy trust
page_body:
- If you need to try a different account you can
- This service is available to all state-funded primary, secondary, special and alternative provision schools which have pupils aged between 5-16.
- Private, voluntary-aided and independent early years providers and institutions that provide only for pupils aged 16+ are not eligible for this service.
link: sign in into the service again.
- If you want to try a different account you can
- This service is available to all state-funded primary, secondary, special and alternative provision schools with pupils aged between 5 to 16 years old.
- Private, voluntary-aided and independent early years providers and institutions with pupils aged 16 years and above are not eligible for this service.
link: sign in to the service again.
#
# Self-Serve -----------------------------------------------------------------
#
Expand Down
3 changes: 3 additions & 0 deletions config/locales/validation/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ en:
message_body: "" # Omitted
correct_organisation: "" # Omitted
correct_group: "" # Omitted
affiliation: "" # Omitted
errors:
rules:
dsi:
Expand All @@ -58,3 +59,5 @@ en:
bool?: Select whether this is the Group or Trust you're buying for
correct_organisation:
bool?: Select whether this is the organisation you're buying for
affiliation:
missing: Select the school or group you want help buying for
27 changes: 27 additions & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@
end
end

trait :many_supported_schools_and_groups do
orgs do
[
{
"urn": "100253",
"name": "Specialist School for Testing",
"type": { "id": ORG_TYPE_IDS.first, "name": "Community School" },
},
{
"urn": "100254",
"name": "Greendale Academy for Bright Sparks",
"type": { "id": ORG_TYPE_IDS.last, "name": "Academy Special Converter" },
},
{
"uid": "2314",
"name": "Testing Multi Academy Trust",
"category": { "id": GROUP_CATEGORY_IDS.first, "name": "Multi-academy Trust" },
},
{
"uid": "2315",
"name": "New Academy Trust",
"category": { "id": GROUP_CATEGORY_IDS.last, "name": "Single-academy Trust" },
},
]
end
end

trait :analyst do
roles do
%w[analyst]
Expand Down
Loading