From b2d8851bcce7a99393fe0d01c0e6df71102f7748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 3 Jun 2019 12:49:17 +0200 Subject: [PATCH] Add the option to disable languages managment to cover special cases We understand languages management as the ability to add new languages or remove existing ones. When no option is passed it will allow language manipulation by default. There are 3 special places where we want block languages management: - admin legislation processes homepage - admin legislation processes milestones summary - proposals retired form Co-Authored-By: Sebastia --- app/helpers/globalize_helper.rb | 5 ----- .../legislation/homepages/_form.html.erb | 3 ++- .../milestones/_summary_form.html.erb | 3 ++- .../_globalize_locales.html.erb | 3 ++- app/views/proposals/retire_form.html.erb | 2 +- .../shared/_common_globalize_locales.html.erb | 1 - app/views/shared/_globalize_locales.html.erb | 3 ++- .../admin/legislation/processes_spec.rb | 21 +++++++++++++++++++ spec/features/proposals_spec.rb | 15 +++++++++++++ 9 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/helpers/globalize_helper.rb b/app/helpers/globalize_helper.rb index 592b49170..74ebc5ba0 100644 --- a/app/helpers/globalize_helper.rb +++ b/app/helpers/globalize_helper.rb @@ -96,11 +96,6 @@ module GlobalizeHelper end end - def can_manipulate_languages? - params[:controller] != "admin/legislation/milestones" && - params[:controller] != "admin/legislation/homepages" - end - def translation_enabled_tag(locale, enabled) hidden_field_tag("enabled_translations[#{locale}]", (enabled ? 1 : 0)) end diff --git a/app/views/admin/legislation/homepages/_form.html.erb b/app/views/admin/legislation/homepages/_form.html.erb index d5b5d73ec..4ce79ab30 100644 --- a/app/views/admin/legislation/homepages/_form.html.erb +++ b/app/views/admin/legislation/homepages/_form.html.erb @@ -1,6 +1,7 @@ <%= render "shared/globalize_locales", resource: @process, - display_style: lambda { |locale| enable_translation_style(@process, locale) } %> + display_style: lambda { |locale| enable_translation_style(@process, locale) }, + manage_languages: false %> <%= translatable_form_for [:admin, @process], url: url, html: {data: {watch_changes: true}} do |f| %> diff --git a/app/views/admin/legislation/milestones/_summary_form.html.erb b/app/views/admin/legislation/milestones/_summary_form.html.erb index e43cabf00..3c4297049 100644 --- a/app/views/admin/legislation/milestones/_summary_form.html.erb +++ b/app/views/admin/legislation/milestones/_summary_form.html.erb @@ -1,6 +1,7 @@ <%= render "shared/globalize_locales", resource: @process, - display_style: lambda { |locale| enable_translation_style(@process, locale) } %> + display_style: lambda { |locale| enable_translation_style(@process, locale) }, + manage_languages: false %> <%= translatable_form_for [:admin, @process] do |f| %>
diff --git a/app/views/admin/site_customization/information_texts/_globalize_locales.html.erb b/app/views/admin/site_customization/information_texts/_globalize_locales.html.erb index 61969d2f0..ef93a7ae7 100644 --- a/app/views/admin/site_customization/information_texts/_globalize_locales.html.erb +++ b/app/views/admin/site_customization/information_texts/_globalize_locales.html.erb @@ -1,3 +1,4 @@ <%= render "shared/common_globalize_locales", resource: nil, - display_style: lambda { |locale| site_customization_display_translation_style(locale) } %> + display_style: lambda { |locale| site_customization_display_translation_style(locale) }, + manage_languages: defined?(manage_languages) ? manage_languages : true %> diff --git a/app/views/proposals/retire_form.html.erb b/app/views/proposals/retire_form.html.erb index 0a54ecd92..604cd1a47 100644 --- a/app/views/proposals/retire_form.html.erb +++ b/app/views/proposals/retire_form.html.erb @@ -10,7 +10,7 @@ <%= t("proposals.retire_form.warning") %>
- <%= render "shared/globalize_locales", resource: @proposal %> + <%= render "shared/globalize_locales", resource: @proposal, manage_languages: false %> <%= translatable_form_for(@proposal, url: retire_proposal_path(@proposal)) do |f| %> <%= render "shared/errors", resource: @proposal %> diff --git a/app/views/shared/_common_globalize_locales.html.erb b/app/views/shared/_common_globalize_locales.html.erb index c114135c3..bf29a7344 100644 --- a/app/views/shared/_common_globalize_locales.html.erb +++ b/app/views/shared/_common_globalize_locales.html.erb @@ -10,7 +10,6 @@ options_for_select_language(resource), prompt: "Choose language", class: "js-select-language" %> -
<% if manage_languages %> <% I18n.available_locales.each do |locale| %> diff --git a/app/views/shared/_globalize_locales.html.erb b/app/views/shared/_globalize_locales.html.erb index a43961ab5..38464ac3b 100644 --- a/app/views/shared/_globalize_locales.html.erb +++ b/app/views/shared/_globalize_locales.html.erb @@ -1,5 +1,6 @@ <% if translations_interface_enabled? %> <%= render "shared/common_globalize_locales", resource: resource, - display_style: lambda { |locale| enable_translation_style(resource, locale) } %> + display_style: lambda { |locale| enable_translation_style(resource, locale) }, + manage_languages: defined?(manage_languages) ? manage_languages : true %> <% end %> diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 3b233717b..2e22c4404 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -282,4 +282,25 @@ describe "Admin collaborative legislation" do expect(page).to have_content "There is still a long journey ahead of us" end end + + context "Special interface translation behaviour" do + let!(:process) { create(:legislation_process) } + + before { Setting["feature.translation_interface"] = true } + after { Setting["feature.translation_interface"] = nil } + + scenario "Cant manage translations on homepage form" do + visit edit_admin_legislation_process_homepage_path(process) + + expect(page).not_to have_css "#add_language" + expect(page).not_to have_link "Remove language" + end + + scenario "Cant manage translations on milestones summary form" do + visit admin_legislation_process_milestones_path(process) + + expect(page).not_to have_css "#add_language" + expect(page).not_to have_link "Remove language" + end + end end diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 62e851e6d..426f13a0a 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -604,6 +604,21 @@ describe "Proposals" do expect(page).to have_content unfeasible.title expect(page).not_to have_content duplicated.title end + + context "Special interface translation behaviour" do + before { Setting["feature.translation_interface"] = true } + after { Setting["feature.translation_interface"] = nil } + + scenario "Cant manage translations" do + proposal = create(:proposal) + login_as(proposal.author) + + visit retire_form_proposal_path(proposal) + + expect(page).not_to have_css "#add_language" + expect(page).not_to have_link "Remove language" + end + end end scenario "Update should not be posible if logged user is not the author" do