Skip to content

Commit 6fa9df7

Browse files
authored
Merge pull request #2775 from govuk-forms/new-groups-page
Add new groups confirmation page
2 parents d67c8db + 1c78a53 commit 6fa9df7

13 files changed

Lines changed: 203 additions & 15 deletions

File tree

app/controllers/groups_controller.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class GroupsController < WebController
2-
before_action :set_group, except: %i[index new create]
2+
before_action :set_group, except: %i[index new create confirm_new confirm_new_submit]
33
after_action :verify_authorized, except: :index
44
after_action :verify_policy_scoped, only: :index
55

@@ -28,6 +28,28 @@ def show
2828
@form_list_presenter = FormListPresenter.call(forms:, group: @group, can_admin: @current_user.can_administer_org?(@group.organisation)) unless forms.empty?
2929
end
3030

31+
def confirm_new
32+
authorize Group, :new?
33+
@confirm_new_input = Groups::ConfirmNewInput.new
34+
@organisation = @current_user.organisation
35+
end
36+
37+
def confirm_new_submit
38+
authorize Group, :new?
39+
@confirm_new_input = Groups::ConfirmNewInput.new(confirm_new_input_params)
40+
@organisation = @current_user.organisation
41+
42+
if @confirm_new_input.invalid?
43+
return render :confirm_new, status: :unprocessable_content
44+
end
45+
46+
if @confirm_new_input.confirmed?
47+
redirect_to new_group_path
48+
else
49+
redirect_to groups_path
50+
end
51+
end
52+
3153
# GET /groups/new
3254
def new
3355
@group = Group.new
@@ -188,4 +210,8 @@ def delete_confirmation_input_params
188210
def search_params
189211
params[:search]&.permit(:organisation_id) || {}
190212
end
213+
214+
def confirm_new_input_params
215+
params.require(:groups_confirm_new_input).permit(:confirm)
216+
end
191217
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Groups
2+
class ConfirmNewInput < ConfirmActionInput
3+
end
4+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<% set_page_title(title_with_error_prefix(t("page_titles.group_confirm_new"), @confirm_new_input.errors.any?)) %>
2+
<% content_for :back_link, govuk_back_link_to(groups_path,t("back_link.groups")) %>
3+
4+
<div class="govuk-grid-row">
5+
<div class="govuk-grid-column-two-thirds">
6+
<%= form_with(model: @confirm_new_input, url: confirm_new_groups_path) do |f| %>
7+
<% if @confirm_new_input&.errors.any? %>
8+
<%= f.govuk_error_summary %>
9+
<% end %>
10+
11+
<h1 class="govuk-heading-l"><%= t("page_titles.group_confirm_new") %></h1>
12+
13+
<% if @organisation.admin_users.empty? %>
14+
<%= t(".without_org_admin.body_html") %>
15+
<% else %>
16+
<%= t(".with_org_admin.body_html") %>
17+
18+
<p><%= t(".with_org_admin.org_admin_list_title") %></p>
19+
<ul class="govuk-list govuk-list--bullet">
20+
<% @organisation.admin_users.order(:email).each do |user| %>
21+
<li><%= user.email %></li>
22+
<% end %>
23+
</ul>
24+
<% end %>
25+
26+
<%= f.govuk_collection_radio_buttons :confirm,
27+
@confirm_new_input.values, ->(option) { option }, ->(option) { t('helpers.label.confirm_action_input.options.' + "#{option}") },
28+
legend: { text: t('groups.confirm_new.radios_legend'), size: 'm' },
29+
inline: true %>
30+
<%= f.govuk_submit t("continue") %>
31+
<% end %>
32+
</div>
33+
</div>

app/views/groups/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<%= render GroupListComponent::View.new(groups: @active_groups, title: t('groups.index.active_title'), empty_message: t('groups.index.active_empty_message')) %>
5353
<%= render GroupListComponent::View.new(groups: @trial_groups, title: t('groups.index.trial_title'), empty_message: t('groups.index.trial_empty_message')) %>
5454

55-
<%= govuk_button_link_to t("groups.index.create_group"), new_group_path, class:"govuk-!-margin-top-3" %>
55+
<%= govuk_button_link_to t("groups.index.create_group"), confirm_new_groups_path, class:"govuk-!-margin-top-3" %>
5656
</div>
5757
</div>
5858

app/views/groups/new.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<% set_page_title(title_with_error_prefix(t(".title"), @group.errors.any?)) %>
2-
<% content_for :back_link, govuk_back_link_to(groups_path,t("back_link.groups")) %>
1+
<% set_page_title(title_with_error_prefix(t("page_titles.new_group"), @group.errors.any?)) %>
2+
<% content_for :back_link, govuk_back_link_to(confirm_new_groups_path,t(".back_link")) %>
33

44
<%= form_with(model: @group) do |f| %>
55
<div class="govuk-grid-row">
@@ -8,7 +8,7 @@
88
<%= f.govuk_error_summary %>
99
<% end %>
1010

11-
<h1 class="govuk-heading-l"><%= t(".title") %></h1>
11+
<h1 class="govuk-heading-l"><%= t("page_titles.new_group") %></h1>
1212

1313
<%= t(".body_html") %>
1414

config/locales/en.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,20 @@ en:
653653
title: Add an editor to this group
654654
title_show_role_options: Add an editor or group admin to this group
655655
groups:
656+
confirm_new:
657+
radios_legend: Do you still want to create a new group?
658+
with_org_admin:
659+
body_html: |
660+
<p>Each form needs to be created in a ‘group’. Once you have a group, you can add other people to create and edit forms in it.</p>
661+
<p>When you first create a group, it will be a ‘trial’ group. That means you can test how the platform works, but you cannot make any forms in the group live.</p>
662+
<p>You’ll only be able to make forms live if you get permission from your organisation’s GOV.UK Forms admin.</p>
663+
<p>If you want to use this group to create live forms, or if you are not sure you should make a new group, contact your organisation’s GOV.UK Forms admin before you continue. They’ll be able to advise about how they’re managing the use of the platform and the creation of forms in your organisation.</p>
664+
org_admin_list_title: 'Your organisation’s GOV.UK forms admins are:'
665+
without_org_admin:
666+
body_html: |
667+
<p>Each form needs to be created in a ‘group’. Once you have a group, you can add other people to create and edit forms in it.</p>
668+
<p>When you first create a group, it will be a ‘trial’ group. That means you can test how the platform works, but you cannot make any forms in the group live.</p>
669+
<p>If you’re not sure if you should make a new group, or you want to use this group for live forms, contact your organisation’s GOV.UK publishing team.</p>
656670
confirm_upgrade:
657671
body_html: |
658672
<p>If you upgrade this group:</p>
@@ -728,21 +742,18 @@ en:
728742
label: Move this group to another organisation
729743
prompt: Select an organisation
730744
new:
745+
back_link: Back to create a new group
731746
body_html: |
732-
<p>Each form needs to be created in a ‘group’. Once you have a group, you can add other people to create and edit forms in it.</p>
733-
734-
<p class="govuk-inset-text">When a group is first created it will be a ‘trial’ group. That means you cannot make any forms in the group live. You’ll be able to request for a group to be upgraded to an ‘active’ group if you need to make forms live.</p>
735-
736-
<p>Give your group a meaningful name that will reflect the forms you’ll create in the group, and make sense to the people that will be added to it. For example:</p>
737-
747+
<p>Give your group a meaningful name that will reflect the forms you’ll
748+
create in the group, and make sense to the people that will be added to
749+
it. For example:</p>
738750
<ul class="govuk-list govuk-list--bullet">
739751
<li>Licensing forms</li>
740752
<li>GOV.UK content team</li>
741753
<li>Juggling service forms</li>
754+
<li>Test forms</li>
742755
</ul>
743-
744756
<p>You can change the name later if you need to.</p>
745-
title: Create a new group for forms
746757
review_upgrade:
747758
body_html: |
748759
<p>%{upgrade_requester_name} has asked to upgrade this group to an ‘active’ group.</p>
@@ -1489,6 +1500,7 @@ en:
14891500
error_prefix: 'Error: '
14901501
exit_page_new: Add exit page
14911502
forbidden: You cannot view this page
1503+
group_confirm_new: Create a new group for forms
14921504
group_confirm_upgrade_request: Request to upgrade this trial group
14931505
group_index: Your groups
14941506
group_review_upgrade: Upgrade this group
@@ -1509,6 +1521,7 @@ en:
15091521
mou_signatures: MOUs and agreements
15101522
move_form: Move this form to a different group
15111523
name_settings: Ask for a person’s name
1524+
new_group: Give your group a name
15121525
new_page: Edit question
15131526
new_secondary_skip: 'Route for any other answer: set questions to skip'
15141527
non_crown_agreement_confirmation: You’ve agreed to the GOV.UK Forms agreement
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
en:
3+
activemodel:
4+
errors:
5+
models:
6+
groups/confirm_new_input:
7+
attributes:
8+
confirm:
9+
blank: Select yes if you want to create a new group

config/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@
223223
resources :groups do
224224
resources :forms, controller: :group_forms, only: %i[new create edit update]
225225
resources :members, controller: :group_members, only: %i[index new create]
226+
227+
collection do
228+
get "confirm-new", to: "groups#confirm_new"
229+
post "confirm-new", to: "groups#confirm_new_submit"
230+
end
231+
226232
member do
227233
get "delete", to: "groups#delete"
228234
get "move", to: "groups#move"

spec/features/groups/create_group_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
scenario "Form creator creates a new group" do
99
when_i_visit_the_groups_page
1010
and_i_click_create_a_group
11+
and_i_click_yes
1112
and_i_fill_in_the_group_name
1213
then_i_should_see_the_new_group
1314
and_i_use_the_back_link
@@ -25,6 +26,11 @@ def and_i_click_create_a_group
2526
expect_page_to_have_no_axe_errors(page)
2627
end
2728

29+
def and_i_click_yes
30+
choose "Yes"
31+
click_button "Continue"
32+
end
33+
2834
def and_i_fill_in_the_group_name
2935
fill_in "Enter a name for your new group", with: "Group 1"
3036
click_button "Save"

spec/requests/groups_controller_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,4 +968,46 @@
968968
end
969969
end
970970
end
971+
972+
describe "GET /confirm_new" do
973+
it "renders a successful response" do
974+
get confirm_new_groups_url
975+
expect(response).to be_successful
976+
end
977+
end
978+
979+
describe "POST /confirm_new" do
980+
before do
981+
post confirm_new_groups_url, params: { groups_confirm_new_input: { confirm: } }
982+
end
983+
984+
context "when 'Yes' is selected" do
985+
let(:confirm) { :yes }
986+
987+
it "redirects to the new group page" do
988+
expect(response).to redirect_to(new_group_path)
989+
end
990+
end
991+
992+
context "when 'No' is selected" do
993+
let(:confirm) { :no }
994+
995+
it "redirects to the groups page" do
996+
expect(response).to redirect_to(groups_path)
997+
end
998+
end
999+
1000+
context "when no option is selected" do
1001+
let(:confirm) { nil }
1002+
1003+
it "returns 422" do
1004+
expect(response).to have_http_status(:unprocessable_content)
1005+
end
1006+
1007+
it "re-renders the confirm new page with an error" do
1008+
expect(response).to render_template(:confirm_new)
1009+
expect(response.body).to include("Select yes if you want to create a new group")
1010+
end
1011+
end
1012+
end
9711013
end

0 commit comments

Comments
 (0)