Skip to content

Commit 1a88c3d

Browse files
authored
Merge pull request #2650 from govuk-forms/add-content-to-make-english-live
Add content to make english live
2 parents 8454395 + adb1384 commit 1a88c3d

File tree

13 files changed

+238
-150
lines changed

13 files changed

+238
-150
lines changed

app/controllers/forms/make_live_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def make_live_input_params
3131
end
3232

3333
def render_new(status: :ok)
34-
if current_form.is_live?
34+
if current_form.live_welsh_form_document.present? && current_form.task_statuses[:welsh_language_status] == :in_progress
35+
render "make_your_changes_to_english_live", status:, locals: { current_form: }
36+
elsif current_form.is_live?
3537
render "make_your_changes_live", status:, locals: { current_form: }
3638
elsif current_form.is_archived?
3739
render "make_archived_draft_live", status:, locals: { current_form: }

app/models/form.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def ready_for_live
111111
end
112112

113113
def all_ready_for_live?
114-
ready_for_live && email_task_status_service.ready_for_live?
114+
ready_for_live
115115
end
116116

117117
delegate :incomplete_tasks, to: :task_status_service
@@ -141,11 +141,11 @@ def has_no_remaining_routes_available?
141141
end
142142

143143
def all_incomplete_tasks
144-
incomplete_tasks.concat(email_task_status_service.incomplete_email_tasks)
144+
incomplete_tasks
145145
end
146146

147147
def all_task_statuses
148-
task_statuses.merge(email_task_status_service.email_task_statuses)
148+
task_statuses
149149
end
150150

151151
def page_number(page)
@@ -241,12 +241,6 @@ def group_form
241241
GroupForm.find_by_form_id(id)
242242
end
243243

244-
def email_task_status_service
245-
# TODO: refactor this in favour of dependency injection
246-
# it can also lead to use of `allow_any_instance_of` in testing
247-
@email_task_status_service ||= EmailTaskStatusService.new(form: self)
248-
end
249-
250244
def steps
251245
ordered_pages = pages.includes(:routing_conditions).to_a
252246
ordered_pages.map.with_index do |page, index|

app/services/email_task_status_service.rb

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/services/form_task_list_service.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,22 @@ def make_form_live_section_tasks
200200
status: @task_statuses[:share_preview_status],
201201
active: @form.pages.any?,
202202
},
203-
{
204-
task_name: live_task_name,
205-
path: live_path,
206-
status: @task_statuses[:make_live_status],
207-
active: @form.all_ready_for_live?,
208-
},
203+
make_live_task,
209204
]
210205
end
211206

207+
def make_live_task
208+
status = @task_statuses[:make_live_status]
209+
can_make_form_live = status == :not_started
210+
211+
{
212+
task_name: live_task_name,
213+
path: can_make_form_live ? make_live_path(@form.id) : "",
214+
status: status,
215+
active: can_make_form_live,
216+
}
217+
end
218+
212219
def live_title_name
213220
return I18n.t("forms.task_list_create.make_form_live_section.title") if @form.is_archived?
214221

@@ -225,12 +232,6 @@ def live_task_name
225232
I18n.t("forms.task_list_#{create_or_edit}.make_form_live_section.make_live")
226233
end
227234

228-
def live_path
229-
return "" unless @form.all_ready_for_live?
230-
231-
make_live_path(@form.id)
232-
end
233-
234235
def statuses_by_user
235236
statuses = @task_statuses
236237

app/services/task_status_service.rb

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ def initialize(form:)
33
@form = form
44
end
55

6-
def mandatory_tasks_completed?
7-
incomplete_tasks.empty?
6+
def mandatory_tasks_completed?(ignore_missing_welsh: false)
7+
if ignore_missing_welsh
8+
incomplete_tasks.reject { |task| task == :missing_welsh_translations }.empty?
9+
else
10+
incomplete_tasks.empty?
11+
end
812
end
913

1014
def incomplete_tasks
@@ -15,6 +19,7 @@ def incomplete_tasks
1519
missing_contact_details: support_contact_details_status,
1620
share_preview_not_completed: share_preview_status,
1721
missing_welsh_translations: welsh_language_status,
22+
missing_submission_email: submission_email_status,
1823
}.reject { |_k, v| %i[completed optional].include?(v) }.keys
1924
end
2025

@@ -32,6 +37,21 @@ def task_statuses
3237
share_preview_status:,
3338
make_live_status:,
3439
welsh_language_status:,
40+
submission_email_status:,
41+
confirm_submission_email_status:,
42+
}
43+
end
44+
45+
def incomplete_email_tasks
46+
{
47+
missing_submission_email: submission_email_status,
48+
}.reject { |_k, v| v == :completed }.keys
49+
end
50+
51+
def email_task_statuses
52+
{
53+
submission_email_status:,
54+
confirm_submission_email_status:,
3555
}
3656
end
3757

@@ -114,7 +134,12 @@ def make_live_status
114134
end
115135

116136
def make_live_status_for_draft
117-
mandatory_tasks_completed? ? :not_started : :cannot_start
137+
# If the form has a live Welsh version, we ignore missing Welsh translations
138+
# and show the make live task and link. In this case, we will show a warning
139+
# message on the make live page asking the user to update the Welsh before
140+
# the form can be made live.
141+
ignore_missing_welsh = @form.live_welsh_form_document.present?
142+
mandatory_tasks_completed?(ignore_missing_welsh:) ? :not_started : :cannot_start
118143
end
119144

120145
def welsh_translations_invalid
@@ -123,4 +148,22 @@ def welsh_translations_invalid
123148
translation_input.invalid?
124149
end
125150
end
151+
152+
def submission_email_status
153+
{
154+
email_set_without_confirmation: :completed,
155+
not_started: :not_started,
156+
sent: :in_progress,
157+
confirmed: :completed,
158+
}[@form.email_confirmation_status]
159+
end
160+
161+
def confirm_submission_email_status
162+
{
163+
email_set_without_confirmation: :completed,
164+
not_started: :cannot_start,
165+
sent: :not_started,
166+
confirmed: :completed,
167+
}[@form.email_confirmation_status]
168+
end
126169
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<% set_page_title(t('page_titles.make_your_changes_to_english_live')) %>
2+
<% content_for :back_link, govuk_back_link_to(form_path, t("back_link.form_edit")) %>
3+
4+
<div class="govuk-grid-row">
5+
<div class="govuk-grid-column-two-thirds">
6+
<h1 class="govuk-heading-l">
7+
<span class="govuk-caption-l"><%= @current_form.name %></span>
8+
<%= t("page_titles.make_your_changes_to_english_live") %>
9+
</h1>
10+
11+
<%= t("make_your_changes_to_english_live.body_html", archive_welsh_link: archive_welsh_path) %>
12+
13+
<p> <%= govuk_link_to t("make_your_changes_to_english_live.continue_editing_link_text"), form_path %> </p>
14+
</div>
15+
</div>
16+

config/locales/en.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,12 @@ en:
12161216
<p>
12171217
After you have made your form live, completed forms will be sent to <span class="govuk-!-text-break-word">%{submission_email}</span>.
12181218
</p>
1219+
make_your_changes_to_english_live:
1220+
body_html: |
1221+
<p>You’ve updated your English form.<p>
1222+
<p>The English and Welsh versions must match before you can make your changes live.</p>
1223+
<p>If necessary, you can <a href="%{archive_welsh_link}">archive the Welsh version</a> to take it offline until you have new translations.</p>
1224+
continue_editing_link_text: Continue editing your form
12191225
mark_complete:
12201226
'false': No, I’ll come back later
12211227
hint: Selecting ‘Yes’ will mark this task as complete. You’ll still be able to make changes if you need to.
@@ -1475,6 +1481,7 @@ en:
14751481
make_archived_draft_live: Make your form live again
14761482
make_changes_live: Make your changes live
14771483
make_live: Make your form live
1484+
make_your_changes_to_english_live: Make the changes to your English form live
14781485
missing_draft_question: There’s a problem with this page
14791486
mou_signature_confirmation: You’ve agreed to the MOU
14801487
mou_signature_new: GOV.UK Forms Memorandum of Understanding

spec/models/form_spec.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -942,35 +942,20 @@
942942

943943
describe "#all_ready_for_live?" do
944944
before do
945-
email_task_status_service = instance_double(EmailTaskStatusService)
946-
allow(EmailTaskStatusService).to receive(:new).and_return(email_task_status_service)
947-
allow(email_task_status_service).to receive(:ready_for_live?).and_return(email_tasks_completed)
948-
949945
task_status_service = instance_double(TaskStatusService)
950946
allow(TaskStatusService).to receive(:new).and_return(task_status_service)
951947
allow(task_status_service).to receive(:mandatory_tasks_completed?).and_return(mandatory_tasks_completed)
952948
end
953949

954950
context "when not all mandatory tasks have been completed" do
955-
let(:email_tasks_completed) { true }
956951
let(:mandatory_tasks_completed) { false }
957952

958953
it "returns false" do
959954
expect(form.all_ready_for_live?).to be false
960955
end
961956
end
962957

963-
context "when not all submission emails tasks have been completed" do
964-
let(:email_tasks_completed) { false }
965-
let(:mandatory_tasks_completed) { true }
966-
967-
it "returns false" do
968-
expect(form.all_ready_for_live?).to be false
969-
end
970-
end
971-
972958
context "when all mandatory tasks have been completed" do
973-
let(:email_tasks_completed) { true }
974959
let(:mandatory_tasks_completed) { true }
975960

976961
it "returns true" do

spec/requests/forms/make_live_controller_spec.rb

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
GroupForm.create!(form_id: form.id, group_id: group.id)
1818

1919
login_as user
20-
21-
get make_live_path(form_id: form.id)
2220
end
2321

2422
it "returns 200" do
23+
get make_live_path(form_id: form.id)
2524
expect(response).to have_http_status(:ok)
2625
end
2726

2827
context "when the form is being created for the first time" do
2928
it "renders make your form live" do
29+
get make_live_path(form_id: form.id)
3030
expect(response).to render_template("make_your_form_live")
3131
end
3232
end
@@ -35,6 +35,7 @@
3535
let(:form) { create(:form, :live) }
3636

3737
it "renders make your changes live" do
38+
get make_live_path(form_id: form.id)
3839
expect(response).to render_template("make_your_changes_live")
3940
end
4041
end
@@ -43,6 +44,7 @@
4344
let(:form) { create(:form, :archived_with_draft) }
4445

4546
it "renders make your changes live" do
47+
get make_live_path(form_id: form.id)
4648
expect(response).to render_template("make_archived_draft_live")
4749
end
4850
end
@@ -51,9 +53,51 @@
5153
let(:group_role) { :editor }
5254

5355
it "is forbidden" do
56+
get make_live_path(form_id: form.id)
5457
expect(response).to have_http_status(:forbidden)
5558
end
5659
end
60+
61+
context "when the form has an existing live welsh form document" do
62+
let(:form) do
63+
create(:form, :with_welsh_translation,
64+
support_email: "english@example.gov.uk",
65+
support_email_cy: "welsh@example.gov.uk",
66+
what_happens_next_markdown: "English what happens next",
67+
what_happens_next_markdown_cy: "Welsh what happens next",
68+
question_section_completed: true,
69+
declaration_section_completed: true,
70+
share_preview_completed: true,
71+
privacy_policy_url: "https://www.gov.uk/english-privacy",
72+
privacy_policy_url_cy: "https://www.gov.uk/welsh-privacy",
73+
welsh_completed: true,
74+
pages: [build(:page, question_text: "English question", question_text_cy: "Welsh question")])
75+
end
76+
77+
before do
78+
# Create the en and cy live FormDocuments
79+
form.make_live!
80+
end
81+
82+
context "and a complete welsh translations" do
83+
it "renders make your changes live" do
84+
get make_live_path(form_id: form.id)
85+
expect(response).to render_template("make_your_changes_live")
86+
end
87+
end
88+
89+
context "and in progress welsh translations" do
90+
before do
91+
# Add a declaration in English only to the draft form
92+
form.update!(declaration_markdown: "English declaration", share_preview_completed: true)
93+
end
94+
95+
it "renders make your changes to english live" do
96+
get make_live_path(form_id: form.id)
97+
expect(response).to render_template("make_your_changes_to_english_live")
98+
end
99+
end
100+
end
57101
end
58102

59103
describe "#create" do

0 commit comments

Comments
 (0)