Skip to content
Open
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
18 changes: 17 additions & 1 deletion app/controllers/forms/make_language_live_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def make_language_live_input_params
end

def render_new(status: :ok)
render "new", status:, locals: { current_form:, language: params[:language] }
render "new", status:, locals: { current_form:, language: params[:language], page_title: new_page_title, page_body: new_page_body }
end

def render_confirmation(status: :ok)
Expand All @@ -73,5 +73,21 @@ def render_confirmation(status: :ok)
def go_to_make_welsh_live_input_params
params.require(:forms_go_to_make_welsh_live_input).permit(:confirm)
end

def new_page_title
return I18n.t("page_titles.make_your_changes_to_english_live") if making_english_changes_live?

I18n.t("page_titles.make_language_live.#{params[:language]}")
end

def new_page_body
return t("make_language_live.en.make_your_changes_to_english_live.body_html", submission_email: @current_form.submission_email) if making_english_changes_live?

t("make_language_live.#{params[:language]}.new.body_html", submission_email: @current_form.submission_email)
end

def making_english_changes_live?
@current_form.is_live? && params[:language] == "en"
end
end
end
20 changes: 19 additions & 1 deletion app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ def can_make_language_live?(language:)
can_make_welsh_version_live? if language == "cy"
end

def changed_from_live_version?(language:)
live_document = language == "cy" ? live_welsh_form_document : live_form_document
return false if live_document.blank?

ignored_keys = %w[live_at available_languages updated_at]
return false if live_document.content.except(*ignored_keys) == as_form_document(language:).except(*ignored_keys)

true
end

private

def set_external_id
Expand Down Expand Up @@ -296,7 +306,15 @@ def can_make_english_version_live?
end

def can_make_welsh_version_live?
has_live_version && all_ready_for_live? && welsh_completed? && live_form_document.present? && live_welsh_form_document.blank?
english_version_has_been_made_live? && !changed_from_live_version?(language: "en") && welsh_version_ready? && live_welsh_form_document.blank?
end

def english_version_has_been_made_live?
has_live_version && live_form_document.present?
end

def welsh_version_ready?
all_ready_for_live? && welsh_completed?
end

def after_archive
Expand Down
50 changes: 42 additions & 8 deletions app/services/form_task_list_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,20 @@ def group_upgrade_url

def make_form_live_section_tasks
[
{
task_name: share_preview_task_name,
path: share_preview_path(@form.id),
status: @task_statuses[:share_preview_status],
active: @form.pages.any?,
},
make_live_task,
]
share_preview_task,
(make_live_task unless display_make_languages_live_tasks?),
(make_only_english_live_task if display_make_languages_live_tasks?),
(make_only_welsh_live_task if display_make_languages_live_tasks?),
].compact
end

def share_preview_task
{
task_name: share_preview_task_name,
path: share_preview_path(@form.id),
status: @task_statuses[:share_preview_status],
active: @form.pages.any?,
}
end

def make_live_task
Expand All @@ -215,6 +221,34 @@ def make_live_task
}
end

def make_only_english_live_task
status = @task_statuses[:make_only_english_live_status]
can_make_form_live = status == :not_started

{
task_name: @form.is_live? ? I18n.t("forms.task_list_edit.make_form_live_section.make_english_form_live") : I18n.t("forms.task_list_create.make_form_live_section.make_english_form_live"),
path: can_make_form_live ? make_language_live_path(@form.id, language: "en") : "",
status:,
active: can_make_form_live,
}
end

def make_only_welsh_live_task
status = @task_statuses[:make_only_welsh_live_status]
can_make_form_live = status == :not_started

{
task_name: I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live"),
path: can_make_form_live ? make_language_live_path(@form.id, language: "cy") : "",
status:,
active: can_make_form_live,
}
end

def display_make_languages_live_tasks?
@form.live_welsh_form_document.blank? && @form.has_welsh_translation?
end

def live_title_name
return I18n.t("forms.task_list_create.make_form_live_section.title") if @form.is_archived?

Expand Down
16 changes: 16 additions & 0 deletions app/services/task_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def all_task_statuses
batch_submissions_status:,
share_preview_status:,
make_live_status:,
make_only_english_live_status:,
make_only_welsh_live_status:,
welsh_language_status:,
submission_email_status:,
confirm_submission_email_status:,
Expand Down Expand Up @@ -139,6 +141,20 @@ def make_live_status
:completed if @form.has_live_version
end

def make_only_english_live_status
return :completed if @form.has_live_version && !@form.changed_from_live_version?(language: "en")
return :not_started if @form.can_make_language_live?(language: "en")

:cannot_start
end

def make_only_welsh_live_status
return :not_started if @form.can_make_language_live?(language: "cy")
return :completed if @form.live_welsh_form_document.present?

:cannot_start
end

def make_live_status_for_draft
# If the form has a live Welsh version, we ignore missing Welsh translations
# and show the make live task and link. In this case, we will show a warning
Expand Down
2 changes: 1 addition & 1 deletion app/state_machines/form_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module FormStateMachine
before :before_make_english_live
after :after_make_english_live

transitions from: %i[draft live live_with_draft archived_with_draft], to: :live, guard: :can_make_english_version_live?
transitions from: %i[draft live live_with_draft archived_with_draft], to: :live_with_draft, guard: :can_make_english_version_live?
end

event :make_welsh_version_live do
Expand Down
6 changes: 3 additions & 3 deletions app/views/forms/make_language_live/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% set_page_title(title_with_error_prefix(t("page_titles.make_language_live.#{language}"), @make_language_live_input.errors.any?)) %>
<% set_page_title(title_with_error_prefix((page_title), @make_language_live_input.errors.any?)) %>
<% content_for :back_link, govuk_back_link_to(form_path, t("back_link.form_create")) %>

<div class="govuk-grid-row">
Expand All @@ -10,10 +10,10 @@

<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @make_language_live_input.form.name %></span>
<%= t("page_titles.make_language_live.#{language}") %>
<%= page_title %>
</h1>

<%= t("make_language_live.#{language}.new.body_html", submission_email: @make_language_live_input.form.submission_email) %>
<%= page_body %>

<%= f.govuk_collection_radio_buttons :confirm,
@make_language_live_input.values, ->(option) { option }, ->(option) { t("helpers.label.confirm_action_input.options.#{option}") },
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ en:

A group admin can request to upgrade the group so forms can be made live. You can <a href="%{group_members_path}">view the members of the group</a> to find a group admin.
no_org_admin: You cannot make this form live because it’s in a ‘trial’ group.
make_english_form_live: Make your English form live
make_live: Make your form live
make_welsh_form_live: Make your Welsh form live
share_preview: Share a preview of your draft form
title: Make your form live
user_cannot_administer:
Expand Down Expand Up @@ -580,6 +582,7 @@ en:
submission_attachments: Get a CSV or JSON file of each completed form
title: Change how you get completed forms
make_form_live_section:
make_english_form_live: Make changes to your English form live
make_live: Make your changes live
share_preview: Share a preview of your draft form
title: Make your changes live
Expand Down Expand Up @@ -1227,6 +1230,10 @@ en:
<p>The form will not be indexed by search engines, so people will not be able to find it easily. Contact your GOV.UK publishing team to publish links to your form on GOV.UK so people can find it.</p>
<p>Completed forms will be sent to: <span class="govuk-!-text-break-word">%{submission_email}</span></p>
en:
make_your_changes_to_english_live:
body_html: |
<p>The form will not be indexed by search engines, so people will not be able to find it easily. Contact your GOV.UK publishing team to publish links to your form on GOV.UK so people can find it.</p>
<p>Completed forms will be sent to: <span class="govuk-!-text-break-word">%{submission_email}</span></p>
new:
body_html: |
<p>When you make your form live you’ll get a new URL for the English version.</p>
Expand Down
34 changes: 33 additions & 1 deletion spec/models/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,8 @@
welsh_language_status: :optional,
share_preview_status: :completed,
make_live_status: :completed,
make_only_english_live_status: :completed,
make_only_welsh_live_status: :cannot_start,
}
expect(form.all_task_statuses).to eq expected_hash
end
Expand Down Expand Up @@ -1642,7 +1644,7 @@
context "when the Welsh task is still in progress" do
let(:form) { create :form, :ready_for_live, :with_welsh_translation, state: "live", welsh_completed: false }

it "returns true" do
it "returns false" do
expect(form.can_make_language_live?(language:)).to be false
end
end
Expand All @@ -1653,6 +1655,36 @@
it "returns true" do
expect(form.can_make_language_live?(language:)).to be true
end

context "when there are changes which have not yet been made live on the English version" do
before do
form.name = "A new form name"
form.save_draft!

form.share_preview_completed = true
form.save_draft!
end

it "returns false" do
expect(form.can_make_language_live?(language:)).to be false
end
end
end

context "when the Welsh task has been completed since the English form was made live" do
let(:form) { create :form, :ready_for_live, :with_welsh_translation, state: "live", welsh_completed: false }

before do
form.welsh_completed = true
form.save_draft!

form.share_preview_completed = true
form.save_draft!
end

it "returns true" do
expect(form.can_make_language_live?(language:)).to be true
end
end
end

Expand Down
15 changes: 10 additions & 5 deletions spec/requests/forms/make_language_live_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
get make_language_live_path(form_id: form.id, language:)
expect(response).to render_template("make_language_live/new")
expect(response).to have_http_status(:ok)
expect(response.body).to include(I18n.t("page_titles.make_language_live.en"))
expect(response.body).to include(I18n.t("make_language_live.en.new.body_html", submission_email: form.submission_email))
end

context "when editing a draft of an existing live form" do
let(:form) { create(:form, :live) }
let(:form) { create(:form, :live_with_draft) }

it "redirects to the form task list" do
it "renders make your form live" do
get make_language_live_path(form_id: form.id, language:)
expect(response).to redirect_to(form_path(form_id: form.id))
expect(response).to render_template("make_language_live/new")
expect(response).to have_http_status(:ok)
expect(response.body).to include(I18n.t("page_titles.make_your_changes_to_english_live"))
expect(response.body).to include(I18n.t("make_language_live.en.make_your_changes_to_english_live.body_html", submission_email: form.submission_email))
end
end

Expand Down Expand Up @@ -80,7 +85,7 @@
expect {
post(make_language_live_path(form_id: form.id, language:), params: form_params)
}.to change { FormDocument.where(language:).count }.by(1)
.and change { form.reload.state }.to("live")
.and change { form.reload.state }.to("live_with_draft")
end

it "sets the English FormDocument's live_at time to be equal to the form's updated_at time" do
Expand Down Expand Up @@ -127,7 +132,7 @@
expect {
post(make_language_live_path(form_id: form.id, language:), params: form_params)
}.to change { FormDocument.where(language:).count }.by(1)
.and change { form.reload.state }.to("live")
.and change { form.reload.state }.to("live_with_draft")
end
end
end
Expand Down
67 changes: 67 additions & 0 deletions spec/services/form_task_list_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,22 @@
it "has the correct default status" do
expect(section_rows.second[:status]).to eq :not_started
end

context "when the form has Welsh translations" do
let(:form) { create(:form, :ready_for_live, :with_welsh_translation, welsh_completed: false) }

it "has a link to make the English form live" do
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_english_form_live")
expect(section_rows.second[:path]).to eq "/forms/#{form.id}/make-live/en"
expect(section_rows.second[:status]).to eq :not_started
end

it "has the make Welsh live task without a link" do
expect(section_rows.third[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live")
expect(section_rows.third[:path]).to eq ""
expect(section_rows.third[:status]).to eq :cannot_start
end
end
end

context "when form is live" do
Expand All @@ -487,6 +503,37 @@
it "describes the task correctly" do
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_edit.make_form_live_section.make_live")
end

context "when the form has a draft with welsh translations" do
before do
allow(form).to receive(:has_welsh_translation?).and_return(true)
end

it "has a link to make the English form live" do
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_edit.make_form_live_section.make_english_form_live")
expect(section_rows.second[:path]).to eq "/forms/#{form.id}/make-live/en"
expect(section_rows.second[:status]).to eq :not_started
end

it "has the make Welsh live task without a link" do
expect(section_rows.third[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live")
expect(section_rows.third[:path]).to eq ""
expect(section_rows.third[:status]).to eq :cannot_start
end

context "when the Welsh version can be made live" do
before do
allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(true)
allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(true)
end

it "has a link to make the Welsh form live" do
expect(section_rows.third[:task_name]).to eq "Make your Welsh form live"
expect(section_rows.third[:path]).to eq "/forms/#{form.id}/make-live/cy"
expect(section_rows.third[:status]).to eq :not_started
end
end
end
end

context "when the form is archived" do
Expand All @@ -496,6 +543,26 @@
expect(section_rows.second[:task_name]).to eq "Make your form live"
expect(section_rows.second[:path]).to eq "/forms/#{form.id}/make-live"
end

context "when the form has a draft with welsh translations" do
let(:form) { create(:form, :archived_with_draft) }

before do
allow(form).to receive(:has_welsh_translation?).and_return(true)
end

it "has a link to make the English form live" do
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_english_form_live")
expect(section_rows.second[:path]).to eq "/forms/#{form.id}/make-live/en"
expect(section_rows.second[:status]).to eq :not_started
end

it "has the make Welsh live task without a link" do
expect(section_rows.third[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live")
expect(section_rows.third[:path]).to eq ""
expect(section_rows.third[:status]).to eq :cannot_start
end
end
end
end
end
Expand Down
Loading