Skip to content

Commit 1055455

Browse files
PiperS52Simon PiperEdwinKruglov
authored
FaF support request - updates to DfE signed in journey for MATs (#855)
- update content for kick-out page - add trusts to the DSI journey school page - add (MAT) string to trusts listed on DSI journey school page Co-authored-by: Simon Piper <simonpiper@C02FL95VMD6M.local> Co-authored-by: Edwin Kruglov <edwin.kruglov@education.gov.uk>
1 parent 08f683b commit 1055455

14 files changed

Lines changed: 476 additions & 63 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Deselect school_urn radio buttons if a group_uid is selected and vice versa
3+
*/
4+
5+
function uncheck(radioButtons) {
6+
radioButtons.forEach(r => r.checked = false);
7+
}
8+
9+
window.addEventListener("load", () => {
10+
const schoolRadioButtons = document.querySelectorAll("input[name='framework_support_form[school_urn]'][type=radio]");
11+
const groupRadioButtons = document.querySelectorAll("input[name='framework_support_form[group_uid]'][type=radio]");
12+
const schoolField = document.querySelector("input[name='framework_support_form[school_urn]'][type=hidden]");
13+
const groupField = document.querySelector("input[name='framework_support_form[group_uid]'][type=hidden]");
14+
15+
schoolRadioButtons.forEach(r => {
16+
r.addEventListener("change", () => {
17+
if (r.checked) {
18+
uncheck(groupRadioButtons);
19+
groupField.value = null;
20+
}
21+
});
22+
});
23+
24+
groupRadioButtons.forEach(r => {
25+
r.addEventListener("change", () => {
26+
if (r.checked) {
27+
uncheck(schoolRadioButtons);
28+
schoolField.value = null;
29+
}
30+
});
31+
});
32+
});

app/controllers/framework_requests_controller.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def create
3939
@organisation = organisation
4040
@establishment_group = establishment_group
4141

42+
forget_org
43+
4244
# DSI users clicking back on the FaF support form skip steps intended for guests
4345
if form_params[:back] == "true" || form_params[:correct_group] == "false" || form_params[:correct_organisation] == "false"
4446

@@ -51,14 +53,14 @@ def create
5153
)
5254

5355
# authenticated user / inferred school / message step -> start page
54-
if @framework_support_form.position?(7) && !current_user.guest? && !current_user.school_urn.nil?
56+
if @framework_support_form.position?(7) && !current_user.guest? && current_user.single_org?
5557
redirect_to framework_requests_path
5658
# authenticated user / many schools / message step -> choose school step
57-
elsif @framework_support_form.position?(7) && !current_user.guest? && current_user.school_urn.nil?
59+
elsif @framework_support_form.position?(7) && !current_user.guest? && !current_user.single_org?
5860
@framework_support_form.back!(4)
5961
render :new
6062
# authenticated user / many schools / school step -> start page
61-
elsif @framework_support_form.position?(3) && !current_user.guest? && current_user.school_urn.nil?
63+
elsif @framework_support_form.position?(3) && !current_user.guest? && !current_user.single_org?
6264
redirect_to framework_requests_path
6365
else
6466
@framework_support_form.back!
@@ -97,6 +99,7 @@ def create
9799
def update
98100
@framework_support_form = form
99101
if validation.success?
102+
forget_org
100103

101104
# capture full "xxxxx - name"
102105
session[:faf_school] = @framework_support_form.school_urn
@@ -158,7 +161,7 @@ def initial_position
158161
if current_user.guest?
159162
1
160163
else
161-
current_user.school_urn ? 7 : 3
164+
current_user.school_urn || current_user.group_uid ? 7 : 3
162165
end
163166
end
164167

@@ -174,17 +177,19 @@ def conditional_form_params
174177
last_name: current_user.last_name, # (step 5)
175178
email: current_user.email, # (step 6)
176179
school_urn: current_user.school_urn, # (step 3)
177-
group_uid: nil, # (step 3)
180+
group_uid: current_user.group_uid, # (step 3)
178181
# message (step 7)
179182
}
180183
end
181184
end
182185

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

192+
# TODO: extract into a service rather than access supported data directly
188193
def establishment_group
189194
Support::EstablishmentGroupPresenter.new(Support::EstablishmentGroup.find_by(uid: group_uid)) if group_uid
190195
end
@@ -195,7 +200,7 @@ def establishment_group
195200
#
196201
# @return [String, nil]
197202
def urn
198-
form_params[:school_urn]&.split(" - ")&.first || @framework_request&.school_urn
203+
form_params[:school_urn]&.split(" - ")&.first
199204
end
200205

201206
# Extract the group UID from the format "uid - group name"
@@ -204,6 +209,14 @@ def urn
204209
#
205210
# @return [String, nil]
206211
def group_uid
207-
form_params[:group_uid]&.split(" - ")&.first || @framework_request&.group_uid
212+
form_params[:group_uid]&.split(" - ")&.first
213+
end
214+
215+
def forget_org
216+
if @framework_support_form.position?(3) && @framework_support_form.has_school?
217+
@framework_support_form.forget_group!
218+
elsif @framework_support_form.position?(3) && @framework_support_form.has_group?
219+
@framework_support_form.forget_school!
220+
end
208221
end
209222
end

app/forms/framework_support_form.rb

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ class FrameworkSupportForm < Form
2222
# @return [String]
2323
option :email, optional: true # 4 (skipped if logged in)
2424

25-
option :group, optional: true
26-
2725
# @!attribute [r] school_urn
2826
# @return [String] URN identifier and name in the format "100000 - School Name"
2927
option :school_urn, optional: true # 5 (skipped if inferred at login)
@@ -60,16 +58,33 @@ def guest?
6058
!dsi?
6159
end
6260

63-
# TODO: - ref for ticket 231
64-
# # @return [nil]
65-
# def forget_school_urn!
66-
# instance_variable_set :@school_urn, nil
67-
# end
68-
69-
# TODO: - ref for ticket 231
70-
# # @return [nil]
71-
# def forget_group_uid!
72-
# instance_variable_set :@group_uid, nil
73-
# end
61+
# @see FrameworkRequestsController#create
62+
#
63+
# @return [Boolean] school URN is present
64+
def has_school?
65+
school_urn.present?
66+
end
67+
68+
# @see FrameworkRequestsController#create
69+
#
70+
# @return [Boolean] group UID is present
71+
def has_group?
72+
group_uid.present?
73+
end
74+
75+
# @return [nil]
76+
def forget_school!
77+
instance_variable_set :@school_urn, nil
78+
end
79+
80+
# @return [nil]
81+
def forget_group!
82+
instance_variable_set :@group_uid, nil
83+
end
84+
85+
# @return [Boolean]
86+
def multiple_schools?
87+
instance_variable_get :@group
88+
end
7489
end
7590
# :nocov:

app/forms/framework_support_form_schema.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class FrameworkSupportFormSchema < Schema
2626
optional(:correct_organisation).value(:bool) # step 6
2727

2828
optional(:correct_group).value(:bool) # step 6
29+
30+
optional(:affiliation).value(:string)
2931
end
3032

3133
rule(:first_name) do
@@ -43,15 +45,31 @@ class FrameworkSupportFormSchema < Schema
4345
end
4446

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

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

5357
rule(:message_body) do
5458
key.failure(:missing) if key? && value.blank?
5559
end
60+
61+
rule(:affiliation) do
62+
# validate that either school_urn or group_uid is provided in the dsi journey
63+
key.failure(:missing) if values[:dsi] && values[:school_urn].blank? && values[:group_uid].blank?
64+
end
65+
66+
# TODO: extract into a service rather than access supported data directly
67+
def org_exists?(id, group)
68+
if group
69+
Support::EstablishmentGroup.find_by(uid: id).present?
70+
else
71+
Support::Organisation.find_by(urn: id).present?
72+
end
73+
end
5674
end
5775
# :nocov:

app/presenters/user_presenter.rb

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ def active_journeys
66

77
# @return [String, nil] inferred unique school identifier
88
def school_urn
9-
supported_schools.first.urn if supported_schools.one?
9+
supported_orgs.first.urn if single_org? && !supported_orgs.first.group
1010
end
1111

12-
# TODO: - ref for ticket 231
13-
# # @return [String, nil] inferred unique school identifier
14-
# def group_uid
15-
# supported_groups.first.uid if supported_groups.one?
16-
# end
12+
# @return [Boolean]
13+
def single_org?
14+
supported_orgs.one?
15+
end
16+
17+
# @return [String, nil] inferred unique group identifier
18+
def group_uid
19+
supported_orgs.first.uid if single_org? && supported_orgs.first.group
20+
end
1721

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

31-
OpenStruct.new(name: org["name"], urn: org["urn"])
35+
OpenStruct.new(name: org["name"], urn: org["urn"], group: false)
3236
}.compact
3337
end
3438

35-
# TODO: - ref for ticket 231
36-
# def supported_groups
37-
# orgs.map { |org|
38-
# next unless org.dig("category", "id").to_i.in?(GROUP_CATEGORY_IDS)
39+
# Support/FaF request form options when a single UID cannot be inferred
40+
#
41+
# @return [Array<OpenStruct>] the name/uid of a user's supported groups
42+
def supported_groups
43+
orgs.map { |org|
44+
next unless org.dig("category", "id").to_i.in?(GROUP_CATEGORY_IDS)
45+
46+
OpenStruct.new(name: "#{org['name']} (MAT)", uid: org["uid"], group: true)
47+
}.compact
48+
end
3949

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

4458
# @return [String]
4559
def full_name

app/views/framework_requests/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<% end %>
5252
<dd class="govuk-summary-list__actions">
5353
<% unless @framework_request.submitted? %>
54-
<%= 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? %>
54+
<%= 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? %>
5555
<% end %>
5656
</dd>
5757
</div>

app/views/framework_requests/steps/_step_3.html.erb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ form_data = @framework_support_form.to_h.merge(step: @framework_support_form.ste
1818
<% if !current_user.guest? %>
1919
<%= content_for :title, I18n.t("faf.user_organisation.header") %>
2020

21-
<%= form.govuk_collection_radio_buttons :school_urn,
22-
current_user.supported_schools,
23-
:urn,
24-
:name,
25-
caption: { text: I18n.t("faf.which_school.caption"), size: "l" },
26-
legend: { text: I18n.t("faf.which_school.legend"), size: "l" }
27-
%>
28-
<% elsif form.object.group == true %>
21+
<%= 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 %>
22+
<% current_user.supported_orgs.each do |org| %>
23+
<% if org.urn %>
24+
<%= form.govuk_radio_button :school_urn, org.urn, label: { text: org.name } %>
25+
<% else %>
26+
<%= form.govuk_radio_button :group_uid, org.uid, label: { text: org.name } %>
27+
<% end %>
28+
<% end %>
29+
<% end %>
30+
31+
<%= javascript_include_tag "faf_select_school" %>
32+
<% elsif @framework_support_form.multiple_schools? %>
2933
<%= render "framework_requests/steps/search_for_a_group", form: form, form_data: form_data %>
3034
<% else %>
3135
<%= render "framework_requests/steps/search_for_a_school", form: form, form_data: form_data %>

config/locales/en.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ en:
7272
- Private, voluntary-aided and independent early years providers and institutions that provide only for pupils aged 16+ are not eligible for this service.
7373
unsupported_organisation:
7474
page_title: Your organisation is not supported by this service
75-
supported_schools: "This service is for those procuring for one school, either:"
75+
supported_schools: "This service is for those procuring for a school in England. We can provide support to:"
7676
supported_schools_list:
77-
- a local authority maintained school, or
78-
- one academy within a single or multi-academy trust
77+
- a local authority maintained school
78+
- a federation school
79+
- an academy in a single or multi-academy trust
7980
page_body:
80-
- If you need to try a different account you can
81-
- This service is available to all state-funded primary, secondary, special and alternative provision schools which have pupils aged between 5-16.
82-
- Private, voluntary-aided and independent early years providers and institutions that provide only for pupils aged 16+ are not eligible for this service.
83-
link: sign in into the service again.
81+
- If you want to try a different account you can
82+
- This service is available to all state-funded primary, secondary, special and alternative provision schools with pupils aged between 5 to 16 years old.
83+
- Private, voluntary-aided and independent early years providers and institutions with pupils aged 16 years and above are not eligible for this service.
84+
link: sign in to the service again.
8485
#
8586
# Self-Serve -----------------------------------------------------------------
8687
#

config/locales/validation/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ en:
3434
message_body: "" # Omitted
3535
correct_organisation: "" # Omitted
3636
correct_group: "" # Omitted
37+
affiliation: "" # Omitted
3738
errors:
3839
rules:
3940
dsi:
@@ -58,3 +59,5 @@ en:
5859
bool?: Select whether this is the Group or Trust you're buying for
5960
correct_organisation:
6061
bool?: Select whether this is the organisation you're buying for
62+
affiliation:
63+
missing: Select the school or group you want help buying for

spec/factories/user.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@
8888
end
8989
end
9090

91+
trait :many_supported_schools_and_groups do
92+
orgs do
93+
[
94+
{
95+
"urn": "100253",
96+
"name": "Specialist School for Testing",
97+
"type": { "id": ORG_TYPE_IDS.first, "name": "Community School" },
98+
},
99+
{
100+
"urn": "100254",
101+
"name": "Greendale Academy for Bright Sparks",
102+
"type": { "id": ORG_TYPE_IDS.last, "name": "Academy Special Converter" },
103+
},
104+
{
105+
"uid": "2314",
106+
"name": "Testing Multi Academy Trust",
107+
"category": { "id": GROUP_CATEGORY_IDS.first, "name": "Multi-academy Trust" },
108+
},
109+
{
110+
"uid": "2315",
111+
"name": "New Academy Trust",
112+
"category": { "id": GROUP_CATEGORY_IDS.last, "name": "Single-academy Trust" },
113+
},
114+
]
115+
end
116+
end
117+
91118
trait :analyst do
92119
roles do
93120
%w[analyst]

0 commit comments

Comments
 (0)