From 591a7aa17dd8b11746051c58501cb99eeaa5d4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 22 Feb 2024 18:31:13 +0100 Subject: [PATCH] Fixes for amendments (#153) * update gemfile * fix translator config * fix translator config * update decidim * update amendments lang on accepting * update amendments lang on accepting * add test for user current locale * add test for user current locale * block chrome version * block chrome version * fix browser * fix browser * fix browser * fix browser * rename interpolations * rename interpolations * fix locale amendment forcing conf * fix locale amendment forcing conf * fix modal login window * fix modal login window * use html formatting for deepl * use html formatting for deepl * use split view by default in amendments * use split view by default in amendments * dont html escape titles * dont html escape titles * default type in proposal filtering * default type in proposal filtering * use around action instead of redirects * use around action instead of redirects * ensure reivew process uses original language too * ensure reivew process uses original language too * overrride extende menu items * overrride extende menu items * allow official proposals to be amended in any language * allow official proposals to be amended in any language * update amendment date * update amendment date * fix amendments acceptation * fix override md5 * fix decidim branch * fix decidim branch * fix decidim branch * fix test --- Gemfile.lock | 147 +++++++++--------- README.md | 1 + app/cells/decidim/diff/attribute.erb | 16 ++ app/cells/decidim/diff/diff_mode_dropdown.erb | 34 ++++ .../concerns/amendments_enforce_locale.rb | 22 +-- .../concerns/proposals_controller_override.rb | 24 +++ app/helpers/concerns/card_helper_override.rb | 1 - .../concerns/layout_helper_override.rb | 22 +++ .../add_admin_login_button.html.erb.deface | 5 + .../replace_login_box_class.html.erb.deface | 2 + .../replace_civicrm_button.html.erb.deface | 7 + .../replace_civirm_buttons.html.erb.deface | 7 + ...ilter_proposals_by_default.html.erb.deface | 10 ++ .../add_admin_login_button.html.erb.deface | 7 + .../replace_login_box_class.html.erb.deface | 3 + app/services/deepl_translator.rb | 10 +- .../_custom_omniauth_buttons.html.erb | 27 ---- .../decidim/devise/sessions/new.html.erb | 61 -------- .../shared/_omniauth_buttons_mini.html.erb | 27 ---- .../proposals/_proposal_title.html.erb | 2 +- config/i18n-tasks.yml | 1 + config/initializers/gpc_overrides.rb | 4 + config/locales/en.yml | 2 +- config/locales/fr.yml | 2 +- config/schedule.yml | 14 +- config/secrets.yml | 1 + spec/lib/overrides_spec.rb | 10 +- spec/system/limit_amendments_spec.rb | 107 +++++++++++-- 28 files changed, 354 insertions(+), 222 deletions(-) create mode 100644 app/cells/decidim/diff/attribute.erb create mode 100644 app/cells/decidim/diff/diff_mode_dropdown.erb create mode 100644 app/controllers/concerns/proposals_controller_override.rb create mode 100644 app/helpers/concerns/layout_helper_override.rb create mode 100644 app/overrides/decidim/devise/sessions/new/add_admin_login_button.html.erb.deface create mode 100644 app/overrides/decidim/devise/sessions/new/replace_login_box_class.html.erb.deface create mode 100644 app/overrides/decidim/devise/shared/_omniauth_buttons/replace_civicrm_button.html.erb.deface create mode 100644 app/overrides/decidim/devise/shared/_omniauth_buttons_mini/replace_civirm_buttons.html.erb.deface create mode 100644 app/overrides/decidim/proposals/proposals/_filters/fix_filter_proposals_by_default.html.erb.deface create mode 100644 app/overrides/decidim/shared/_login_modal/add_admin_login_button.html.erb.deface create mode 100644 app/overrides/decidim/shared/_login_modal/replace_login_box_class.html.erb.deface delete mode 100644 app/views/decidim/devise/sessions/_custom_omniauth_buttons.html.erb delete mode 100644 app/views/decidim/devise/sessions/new.html.erb delete mode 100644 app/views/decidim/devise/shared/_omniauth_buttons_mini.html.erb diff --git a/Gemfile.lock b/Gemfile.lock index be2b9a13..43136f70 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GIT GIT remote: https://github.com/decidim-ice/decidim-module-decidim_awesome.git - revision: a4d5ab306ee305d7ee109fb9371be2597e67d6be + revision: c182090ea9b09629b014b9e6625f62201651ffc8 branch: limit-amendments specs: decidim-decidim_awesome (0.10.2) @@ -47,7 +47,7 @@ GIT GIT remote: https://github.com/openpoke/decidim.git - revision: 501a1f905e0e8c7fa5de0ae7c7ab763b3bdac4f3 + revision: aee1e1488187f0af8713d6686fac819f9b9d2f33 branch: 0.27-canada specs: decidim (0.27.5) @@ -81,6 +81,7 @@ GIT devise-i18n (~> 1.2) devise_invitable (~> 2.0, >= 2.0.9) decidim-api (0.27.5) + decidim-core (= 0.27.5) graphql (~> 1.12, < 1.13) graphql-docs (~> 2.1.0) rack-cors (~> 1.0) @@ -106,12 +107,11 @@ GIT acts_as_list (~> 0.9) batch-loader (~> 1.2) browser (~> 2.7) - carrierwave (~> 2.2.1) + carrierwave (~> 2.2.5, >= 2.2.5) cells-erb (~> 0.1.0) cells-rails (~> 0.1.3) charlock_holmes (~> 0.7) date_validator (~> 0.12.0) - decidim-api (= 0.27.5) devise (~> 4.7) devise-i18n (~> 1.2) diffy (~> 3.3) @@ -226,40 +226,40 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7.6) - actionpack (= 6.1.7.6) - activesupport (= 6.1.7.6) + actioncable (6.1.7.7) + actionpack (= 6.1.7.7) + activesupport (= 6.1.7.7) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.6) - actionpack (= 6.1.7.6) - activejob (= 6.1.7.6) - activerecord (= 6.1.7.6) - activestorage (= 6.1.7.6) - activesupport (= 6.1.7.6) + actionmailbox (6.1.7.7) + actionpack (= 6.1.7.7) + activejob (= 6.1.7.7) + activerecord (= 6.1.7.7) + activestorage (= 6.1.7.7) + activesupport (= 6.1.7.7) mail (>= 2.7.1) - actionmailer (6.1.7.6) - actionpack (= 6.1.7.6) - actionview (= 6.1.7.6) - activejob (= 6.1.7.6) - activesupport (= 6.1.7.6) + actionmailer (6.1.7.7) + actionpack (= 6.1.7.7) + actionview (= 6.1.7.7) + activejob (= 6.1.7.7) + activesupport (= 6.1.7.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.7.6) - actionview (= 6.1.7.6) - activesupport (= 6.1.7.6) + actionpack (6.1.7.7) + actionview (= 6.1.7.7) + activesupport (= 6.1.7.7) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.6) - actionpack (= 6.1.7.6) - activerecord (= 6.1.7.6) - activestorage (= 6.1.7.6) - activesupport (= 6.1.7.6) + actiontext (6.1.7.7) + actionpack (= 6.1.7.7) + activerecord (= 6.1.7.7) + activestorage (= 6.1.7.7) + activesupport (= 6.1.7.7) nokogiri (>= 1.8.5) - actionview (6.1.7.6) - activesupport (= 6.1.7.6) + actionview (6.1.7.7) + activesupport (= 6.1.7.7) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -267,22 +267,22 @@ GEM active_link_to (1.0.5) actionpack addressable - activejob (6.1.7.6) - activesupport (= 6.1.7.6) + activejob (6.1.7.7) + activesupport (= 6.1.7.7) globalid (>= 0.3.6) - activemodel (6.1.7.6) - activesupport (= 6.1.7.6) - activerecord (6.1.7.6) - activemodel (= 6.1.7.6) - activesupport (= 6.1.7.6) - activestorage (6.1.7.6) - actionpack (= 6.1.7.6) - activejob (= 6.1.7.6) - activerecord (= 6.1.7.6) - activesupport (= 6.1.7.6) + activemodel (6.1.7.7) + activesupport (= 6.1.7.7) + activerecord (6.1.7.7) + activemodel (= 6.1.7.7) + activesupport (= 6.1.7.7) + activestorage (6.1.7.7) + actionpack (= 6.1.7.7) + activejob (= 6.1.7.7) + activerecord (= 6.1.7.7) + activesupport (= 6.1.7.7) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7.6) + activesupport (6.1.7.7) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -294,8 +294,8 @@ GEM public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) aws-eventstream (1.3.0) - aws-partitions (1.888.0) - aws-sdk-core (3.191.1) + aws-partitions (1.894.0) + aws-sdk-core (3.191.3) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -309,7 +309,7 @@ GEM aws-sigv4 (~> 1.8) aws-sigv4 (1.8.0) aws-eventstream (~> 1, >= 1.0.2) - axe-core-api (4.8.1) + axe-core-api (4.8.2) dumb_delegator virtus axe-core-rspec (4.1.0) @@ -382,7 +382,7 @@ GEM commonmarker (0.23.10) concurrent-ruby (1.2.3) connection_pool (2.4.1) - crack (0.4.6) + crack (1.0.0) bigdecimal rexml crass (1.0.6) @@ -420,11 +420,11 @@ GEM devise (>= 4.6) diff-lcs (1.5.1) diffy (3.4.2) - doc2text (0.4.6) - nokogiri (>= 1.13.2, < 1.15.0) + doc2text (0.4.7) + nokogiri (>= 1.13.2, < 1.17.0) rubyzip (~> 2.3.0) docile (1.4.0) - doorkeeper (5.6.8) + doorkeeper (5.6.9) railties (>= 5) doorkeeper-i18n (4.0.1) dumb_delegator (1.0.0) @@ -474,7 +474,7 @@ GEM activemodel (>= 4.1, < 7.1) activesupport (>= 4.1, < 7.1) railties (>= 4.1, < 7.1) - fugit (1.9.0) + fugit (1.10.0) et-orbi (~> 1, >= 1.2.7) raabro (~> 1.4) gemoji (3.0.1) @@ -522,7 +522,8 @@ GEM rails (>= 3.2.0) jmespath (1.6.2) json (2.7.1) - jwt (2.7.1) + jwt (2.8.0) + base64 kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -541,7 +542,7 @@ GEM kramdown (~> 2.0) launchy (2.5.2) addressable (~> 2.8) - letter_opener (1.8.1) + letter_opener (1.9.0) launchy (>= 2.2, < 3) letter_opener_web (2.0.0) actionmailer (>= 5.2) @@ -594,7 +595,7 @@ GEM net-smtp (0.4.0.1) net-protocol nio4r (2.7.0) - nokogiri (1.14.5-x86_64-linux) + nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) oauth (1.1.0) oauth-tty (~> 1.0, >= 1.0.1) @@ -660,7 +661,7 @@ GEM nio4r (~> 2.0) raabro (1.4.0) racc (1.7.3) - rack (2.2.8) + rack (2.2.8.1) rack-attack (6.7.0) rack (>= 1.0, < 4) rack-cors (1.1.1) @@ -672,20 +673,20 @@ GEM rack rack-test (2.1.0) rack (>= 1.3) - rails (6.1.7.6) - actioncable (= 6.1.7.6) - actionmailbox (= 6.1.7.6) - actionmailer (= 6.1.7.6) - actionpack (= 6.1.7.6) - actiontext (= 6.1.7.6) - actionview (= 6.1.7.6) - activejob (= 6.1.7.6) - activemodel (= 6.1.7.6) - activerecord (= 6.1.7.6) - activestorage (= 6.1.7.6) - activesupport (= 6.1.7.6) + rails (6.1.7.7) + actioncable (= 6.1.7.7) + actionmailbox (= 6.1.7.7) + actionmailer (= 6.1.7.7) + actionpack (= 6.1.7.7) + actiontext (= 6.1.7.7) + actionview (= 6.1.7.7) + activejob (= 6.1.7.7) + activemodel (= 6.1.7.7) + activerecord (= 6.1.7.7) + activestorage (= 6.1.7.7) + activesupport (= 6.1.7.7) bundler (>= 1.15.0) - railties (= 6.1.7.6) + railties (= 6.1.7.7) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -700,9 +701,9 @@ GEM rails-i18n (6.0.0) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 7) - railties (6.1.7.6) - actionpack (= 6.1.7.6) - activesupport (= 6.1.7.6) + railties (6.1.7.7) + actionpack (= 6.1.7.7) + activesupport (= 6.1.7.7) method_source rake (>= 12.2) thor (~> 1.0) @@ -717,7 +718,7 @@ GEM ffi (~> 1.0) redcarpet (3.6.0) redis (4.8.1) - redis-client (0.19.1) + redis-client (0.20.0) connection_pool regexp_parser (2.9.0) request_store (1.5.1) @@ -778,7 +779,7 @@ GEM rubocop-rspec (2.11.1) rubocop (~> 1.19) ruby-progressbar (1.13.0) - ruby-vips (2.2.0) + ruby-vips (2.2.1) ffi (~> 1.12) rubyXL (3.4.25) nokogiri (>= 1.10.8) @@ -797,7 +798,7 @@ GEM rubyzip (>= 1.2.2) semantic_range (3.0.0) seven_zip_ruby (1.3.0) - sidekiq (7.2.1) + sidekiq (7.2.2) concurrent-ruby (< 2) connection_pool (>= 2.3.0) rack (>= 2.2.4) @@ -869,7 +870,7 @@ GEM activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webmock (3.20.0) + webmock (3.22.0) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) diff --git a/README.md b/README.md index aa5daf90..94b2ebe4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ These ENV vars modifies the behavior of the application in some ways: | ENV | Description | | --- | --- | +| `SUBMENU_MAX_ITEMS` | Number of items before the button "more" appears in a submenu of a participatory space (defaults to `6`) | | `DONATE_BUTTON` | If present, it will show a button with the text "donate" linked to this url. Currently in the process sidebar and when creating a proposal. Locale can be handled with interpolations (ie: `http://some.thing/%{locale}/pay_here`) | | `CHAT_BUTTON` | If present, it will show a button with the text "AGM Chat (beta)" linked to this url. Currently in the process sidebar. Locale can be handled with interpolations (ie: `http://some.thing/%{locale}/chat_here`) | | `REDIRECT_SIGN_UP` | If present and sign up is enabled, it redirects user registration to the URL specified in it. Can process some variable interpolation like `%{locale}` that would be replace by the current users' locale | diff --git a/app/cells/decidim/diff/attribute.erb b/app/cells/decidim/diff/attribute.erb new file mode 100644 index 00000000..bc5d2561 --- /dev/null +++ b/app/cells/decidim/diff/attribute.erb @@ -0,0 +1,16 @@ +
+
+

+ <%= data[:label] %> +

+
+ +
+ <%= diff_split(data, "left", format) %> + <%= diff_split(data, "right", format) %> +
+ +
+ <%= diff_unified(data, format) %> +
+
diff --git a/app/cells/decidim/diff/diff_mode_dropdown.erb b/app/cells/decidim/diff/diff_mode_dropdown.erb new file mode 100644 index 00000000..7be74c15 --- /dev/null +++ b/app/cells/decidim/diff/diff_mode_dropdown.erb @@ -0,0 +1,34 @@ +
+
+ + <%= t("versions.dropdown.choose_diff_view_mode") %> + + + +
+
diff --git a/app/controllers/concerns/amendments_enforce_locale.rb b/app/controllers/concerns/amendments_enforce_locale.rb index ed4e4b5f..86603d1a 100644 --- a/app/controllers/concerns/amendments_enforce_locale.rb +++ b/app/controllers/concerns/amendments_enforce_locale.rb @@ -5,20 +5,22 @@ module AmendmentsEnforceLocale included do # rubocop:disable Rails/LexicallyScopedActionFilter - before_action :enforce_locale, only: [:new, :create] + around_action :enforce_amendment_locale, except: [:reject, :accept, :withdraw] # rubocop:enable Rails/LexicallyScopedActionFilter - def enforce_locale - return unless amendable.component.settings.try(:amendments_enabled) - return unless amendable.component.current_settings.try(:amendment_creation_enabled) - return unless Rails.application.secrets.enforce_original_amendments_locale + def enforce_amendment_locale(&action) + if amendable.component.settings.try(:amendments_enabled) && + amendable.component.current_settings.try(:amendment_creation_enabled) && + !amendable&.official? && + Rails.application.secrets.gpc[:enforce_original_amendments_locale] + amendable_locale = (amendable.title.keys - ["machine_translations"]).first - amendable_locale = amendable.title.keys.first - return if locale.to_s == amendable_locale + flash[:alert] = I18n.t("gpc.amendments.enforced_locale", lang: I18n.t("locale.name", locale: amendable_locale)) if current_locale.to_s != amendable_locale - # flash[:alert] = t("pending_limit_reached", scope: "decidim.decidim_awesome.amendments", emendation: translated_attribute(emendation.title)) - flash[:alert] = t("gpc.amendments.enforced_locale", locale: amendable_locale) - redirect_to new_amend_path(amendable_gid: amendable_gid, locale: amendable.title.keys.first) + I18n.with_locale(amendable_locale, &action) + else + action.call + end end end end diff --git a/app/controllers/concerns/proposals_controller_override.rb b/app/controllers/concerns/proposals_controller_override.rb new file mode 100644 index 00000000..12a07de5 --- /dev/null +++ b/app/controllers/concerns/proposals_controller_override.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module ProposalsControllerOverride + extend ActiveSupport::Concern + + included do + before_action only: [:index] do + session[:proposals_filter_default_type] = params.dig(:filter, :type) if params.dig(:filter, :type).present? + end + + def default_filter_params + { + search_text_cont: "", + with_any_origin: default_filter_origin_params, + activity: "all", + with_any_category: default_filter_category_params, + with_any_state: %w(accepted evaluating state_not_published), + with_any_scope: default_filter_scope_params, + related_to: "", + type: session[:proposals_filter_default_type] || "proposals" + } + end + end +end diff --git a/app/helpers/concerns/card_helper_override.rb b/app/helpers/concerns/card_helper_override.rb index d5a56f90..3d61aa91 100644 --- a/app/helpers/concerns/card_helper_override.rb +++ b/app/helpers/concerns/card_helper_override.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# A command with all the business logic to create a user from omniauth module CardHelperOverride extend ActiveSupport::Concern include ApplicationHelper diff --git a/app/helpers/concerns/layout_helper_override.rb b/app/helpers/concerns/layout_helper_override.rb new file mode 100644 index 00000000..af12ff2a --- /dev/null +++ b/app/helpers/concerns/layout_helper_override.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module LayoutHelperOverride + extend ActiveSupport::Concern + include ApplicationHelper + + included do + def extended_navigation_bar(items, max_items: Rails.application.secrets.gpc[:submenu_max_items] || 5) + return unless items.any? + + extra_items = items.slice((max_items + 1)..-1) || [] + active_item = items.find { |item| item[:active] } + + controller.view_context.render partial: "decidim/shared/extended_navigation_bar", locals: { + items: items, + extra_items: extra_items, + active_item: active_item, + max_items: max_items + } + end + end +end diff --git a/app/overrides/decidim/devise/sessions/new/add_admin_login_button.html.erb.deface b/app/overrides/decidim/devise/sessions/new/add_admin_login_button.html.erb.deface new file mode 100644 index 00000000..af983df1 --- /dev/null +++ b/app/overrides/decidim/devise/sessions/new/add_admin_login_button.html.erb.deface @@ -0,0 +1,5 @@ + + +
+ <%= button_tag t("gpc.login.admin_login"), class: "button expanded hollow", onclick: "$('.login_box').toggleClass('hide');$(this).toggleClass('hollow');" %> +
diff --git a/app/overrides/decidim/devise/sessions/new/replace_login_box_class.html.erb.deface b/app/overrides/decidim/devise/sessions/new/replace_login_box_class.html.erb.deface new file mode 100644 index 00000000..32a24343 --- /dev/null +++ b/app/overrides/decidim/devise/sessions/new/replace_login_box_class.html.erb.deface @@ -0,0 +1,2 @@ + diff --git a/app/overrides/decidim/devise/shared/_omniauth_buttons/replace_civicrm_button.html.erb.deface b/app/overrides/decidim/devise/shared/_omniauth_buttons/replace_civicrm_button.html.erb.deface new file mode 100644 index 00000000..00149f92 --- /dev/null +++ b/app/overrides/decidim/devise/shared/_omniauth_buttons/replace_civicrm_button.html.erb.deface @@ -0,0 +1,7 @@ + + +<% if provider == :civicrm %> + <%= t("gpc.login.sign_in_civicrm") %> +<% else %> + <%= t("devise.shared.links.sign_in_with_provider", provider: normalize_provider_name(provider).titleize) %> +<% end %> diff --git a/app/overrides/decidim/devise/shared/_omniauth_buttons_mini/replace_civirm_buttons.html.erb.deface b/app/overrides/decidim/devise/shared/_omniauth_buttons_mini/replace_civirm_buttons.html.erb.deface new file mode 100644 index 00000000..00149f92 --- /dev/null +++ b/app/overrides/decidim/devise/shared/_omniauth_buttons_mini/replace_civirm_buttons.html.erb.deface @@ -0,0 +1,7 @@ + + +<% if provider == :civicrm %> + <%= t("gpc.login.sign_in_civicrm") %> +<% else %> + <%= t("devise.shared.links.sign_in_with_provider", provider: normalize_provider_name(provider).titleize) %> +<% end %> diff --git a/app/overrides/decidim/proposals/proposals/_filters/fix_filter_proposals_by_default.html.erb.deface b/app/overrides/decidim/proposals/proposals/_filters/fix_filter_proposals_by_default.html.erb.deface new file mode 100644 index 00000000..b1240572 --- /dev/null +++ b/app/overrides/decidim/proposals/proposals/_filters/fix_filter_proposals_by_default.html.erb.deface @@ -0,0 +1,10 @@ + + +<% +@proposals_without_proposals_filter = Decidim::Proposals::Proposal.where(component: current_component). + with_availability(params[:filter].try(:[], :with_availability)) + .published + .not_hidden + +if @proposals_without_proposals_filter.only_emendations.any? +%> diff --git a/app/overrides/decidim/shared/_login_modal/add_admin_login_button.html.erb.deface b/app/overrides/decidim/shared/_login_modal/add_admin_login_button.html.erb.deface new file mode 100644 index 00000000..327d4911 --- /dev/null +++ b/app/overrides/decidim/shared/_login_modal/add_admin_login_button.html.erb.deface @@ -0,0 +1,7 @@ + + +
+
+ <%= button_tag t("gpc.login.admin_login"), class: "button expanded hollow", onclick: "$('.login_box').toggleClass('hide');$(this).toggleClass('hollow');" %> +
+
diff --git a/app/overrides/decidim/shared/_login_modal/replace_login_box_class.html.erb.deface b/app/overrides/decidim/shared/_login_modal/replace_login_box_class.html.erb.deface new file mode 100644 index 00000000..0c2ea073 --- /dev/null +++ b/app/overrides/decidim/shared/_login_modal/replace_login_box_class.html.erb.deface @@ -0,0 +1,3 @@ + diff --git a/app/services/deepl_translator.rb b/app/services/deepl_translator.rb index d5949f40..5bea0498 100644 --- a/app/services/deepl_translator.rb +++ b/app/services/deepl_translator.rb @@ -12,7 +12,7 @@ def initialize(resource, field_name, text, target_locale, source_locale) end def translate - translation = DeepL.translate text, source_locale, target_locale + translation = DeepL.translate text, source_locale, target_locale, tag_handling: tag_handling Decidim::MachineTranslationSaveJob.perform_later( resource, @@ -21,4 +21,12 @@ def translate translation.text ) end + + def tag_handling + "html" if organization&.rich_text_editor_in_public_views + end + + def organization + resource.try(:organization) || resource.try(:participatory_space).try(:organization) || resource.try(:component).try(:organization) + end end diff --git a/app/views/decidim/devise/sessions/_custom_omniauth_buttons.html.erb b/app/views/decidim/devise/sessions/_custom_omniauth_buttons.html.erb deleted file mode 100644 index 915cf9fd..00000000 --- a/app/views/decidim/devise/sessions/_custom_omniauth_buttons.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<% if Devise.mappings[:user].omniauthable? && current_organization.enabled_omniauth_providers.any? %> -
-
- <%- current_organization.enabled_omniauth_providers.keys.each do |provider| %> - - <% end %> - <%- if current_organization.sign_in_enabled? %> - - <%= t("or", scope: "decidim.devise.shared.omniauth_buttons") %> - - <%- end %> -
-
-<% end %> diff --git a/app/views/decidim/devise/sessions/new.html.erb b/app/views/decidim/devise/sessions/new.html.erb deleted file mode 100644 index 27b17242..00000000 --- a/app/views/decidim/devise/sessions/new.html.erb +++ /dev/null @@ -1,61 +0,0 @@ -<% add_decidim_page_title(t("devise.sessions.new.sign_in")) %> - -
-
-
-
-

<%= t("devise.sessions.new.sign_in") %>

- <% if current_organization.sign_up_enabled? %> -

- <%= t(".are_you_new?") %> - <%= link_to t(".register"), new_user_registration_path %> -

- <% elsif current_organization.sign_in_enabled? %> -

- <%= t(".sign_up_disabled") %> -

- <% else %> -

- <%= t(".sign_in_disabled") %> -

- <% end %> -
-
- <% cache current_organization do %> - <%= render "decidim/devise/sessions/custom_omniauth_buttons" %> - <% end %> - - <% if current_organization.sign_in_enabled? %> -
-
- <%= button_tag t("gpc.login.admin_login"), class: "button expanded hollow", onclick: "$('.login_box').toggleClass('hide');$(this).toggleClass('hollow');" %> -
-
- -
-
- <% end %> -
-
diff --git a/app/views/decidim/devise/shared/_omniauth_buttons_mini.html.erb b/app/views/decidim/devise/shared/_omniauth_buttons_mini.html.erb deleted file mode 100644 index 8d02ac36..00000000 --- a/app/views/decidim/devise/shared/_omniauth_buttons_mini.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<% if Devise.mappings[:user].omniauthable? && current_organization.enabled_omniauth_providers.any? %> -
-
-
- <%- current_organization.enabled_omniauth_providers.keys.each do |provider| %> - - <% end %> -
- - <%= t("or", scope: "decidim.devise.shared.omniauth_buttons") %> - -
-
-<% end %> diff --git a/app/views/decidim/proposals/proposals/_proposal_title.html.erb b/app/views/decidim/proposals/proposals/_proposal_title.html.erb index 9d0655fb..5bc7fd69 100644 --- a/app/views/decidim/proposals/proposals/_proposal_title.html.erb +++ b/app/views/decidim/proposals/proposals/_proposal_title.html.erb @@ -8,7 +8,7 @@
"> <% if @proposal.emendation? %> -

<%= t("changes_at_title", scope: "decidim.proposals.proposals.show", title: present(@proposal.amendable).title(links: true, html_escape: true)) %>

+

<%= t("changes_at_title", scope: "decidim.proposals.proposals.show", title: present(@proposal.amendable).title(links: true, html_escape: false)) %>

<% else %>

<%= present(@proposal).title(links: true, html_escape: true) %>

<% end %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index efbbc4ff..db8937b5 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -108,6 +108,7 @@ ignore_unused: # - 'simple_form.{placeholders,hints,labels}.*' # - 'simple_form.{error_notification,required}.:' - gpc.* + - decidim.events.ready_to_amend.* - devise.* - decidim.calendar.* ## Exclude these keys from the `i18n-tasks eq-base' report: diff --git a/config/initializers/gpc_overrides.rb b/config/initializers/gpc_overrides.rb index 4bf3bfbc..390ef07d 100644 --- a/config/initializers/gpc_overrides.rb +++ b/config/initializers/gpc_overrides.rb @@ -11,12 +11,16 @@ # disables inviting external users if enabled Decidim::Meetings::Admin::InvitesController.include(InvitesControllerOverride) + # makes "type" proposals in the filter the default + Decidim::Proposals::ProposalsController.include(ProposalsControllerOverride) # ensures same language is enforce on amendments to proposals Decidim::AmendmentsController.include(AmendmentsEnforceLocale) # sends notifications for answering surveys Decidim::Forms::AnswerQuestionnaire.include(AnswerQuestionnaireOverride) + # sets the number of items in a submenu from configuration + Decidim::LayoutHelper.include(LayoutHelperOverride) # detect custom cards for leadership campaigns Decidim::CardHelper.include(CardHelperOverride) diff --git a/config/locales/en.yml b/config/locales/en.yml index 1f40bae7..55ad4337 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -26,7 +26,7 @@ en: email_not_registered: Sorry, the email %{email} is not registered. Only existing users are allowed to login. gpc: amendments: - enforced_locale: This proposal was originally created in %{locale}. You can only submit amendments in the same language. + enforced_locale: This proposal was originally created in %{lang}. You can only submit amendments in the same language. limit_modal: extra_html: You can also be notified when the current amendment is accepted or rejected by following this proposal (you will receive a notification/email when the amendment is accepted or rejected depending on your notification preferences). campaign_space: "%{name} Campaign" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 03842d75..ac420c9d 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -34,7 +34,7 @@ fr: email_not_registered: Désolé, l'email %{email} n'est pas enregistré. Seuls les utilisateurs existants sont autorisés à se connecter. gpc: amendments: - enforced_locale: Cette proposition a été initialement créée dans %{locale}. Vous ne pouvez soumettre des amendements que dans la même langue. + enforced_locale: Cette proposition a été initialement créée dans %{lang}. Vous ne pouvez soumettre des amendements que dans la même langue. limit_modal: extra_html: Vous pouvez également être informé de l'acceptation ou du rejet de l'amendement en cours en suivant cette proposition (vous recevrez une notification/un courriel lorsque l'amendement sera accepté ou rejeté, en fonction de vos préférences de notification). campaign_space: Campagne de %{name} diff --git a/config/schedule.yml b/config/schedule.yml index eb4e9ab5..3dd72650 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -1,10 +1,10 @@ -hourly_active_step_job: - cron: "0 * * * *" - class: "InvokeRakeTaskJob" - queue: default - status: <%= ENV.fetch("CHANGE_ACTIVE_STEP", "enabled") %> # enabled by default - args: - task: decidim_participatory_processes:change_active_step +# hourly_active_step_job: +# cron: "0 * * * *" +# class: "InvokeRakeTaskJob" +# queue: default +# status: <%= ENV.fetch("CHANGE_ACTIVE_STEP", "enabled") %> # enabled by default +# args: +# task: decidim_participatory_processes:change_active_step daily_open_data_job: cron: "3 3 * * *" diff --git a/config/secrets.yml b/config/secrets.yml index d5ffb16b..aab1b99b 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -113,6 +113,7 @@ storage_default: &storage_default default: &default gpc: + submenu_max_items: <%= ENV.fetch("SUBMENU_MAX_ITEMS", 6) %> donate_button: <%= ENV["DONATE_BUTTON"] %> chat_button: <%= ENV["CHAT_BUTTON"] %> redirect_sign_up: <%= ENV["REDIRECT_SIGN_UP"] %> diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index 59714d5e..0d9ca052 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -16,7 +16,7 @@ package: "decidim-core", files: { # controllers - "/app/controllers/decidim/devise/omniauth_registrations_controller.rb" => "05bc35af4b5f855736f14efbd22e439b", + "/app/controllers/decidim/devise/omniauth_registrations_controller.rb" => "d2470bf88b509572affa7f225f6ee424", "/app/controllers/decidim/devise/registrations_controller.rb" => "f519953daa03df46b98d34b3311a17d0", "/app/controllers/decidim/devise/invitations_controller.rb" => "32ef1da80ec9dd20b884e5829c3307e6", # layouts @@ -25,9 +25,11 @@ "/app/views/decidim/devise/shared/_omniauth_buttons_mini.html.erb" => "d3a413ce7c64959eee3b912406075f84", # cells "/app/cells/decidim/date_range/show.erb" => "7e050b942e447386fc96ef6528039cec", + "/app/cells/decidim/diff/attribute.erb" => "d648bc8e71e27c404d82132d6e3c3241", + "/app/cells/decidim/diff/diff_mode_dropdown.erb" => "770563c121c875159a88cd5e142658e3", # other overrides "/app/helpers/decidim/card_helper.rb" => "b9e7f943ae7c289b2855d328de7b371b", - "/app/commands/decidim/amendable/accept.rb" => "c561b69a7bd5b68dfc4684c11001cb2c", + "/app/commands/decidim/amendable/accept.rb" => "25b86fc0e881251dbda0a176b4c8a9af", "/app/commands/decidim/amendable/reject.rb" => "efd7062b0942b0ec80e336345ffca62f" } @@ -75,11 +77,13 @@ { package: "decidim-proposals", files: { + "/app/controllers/decidim/proposals/proposals_controller.rb" => "b263741e3335110fa0e37c488c777190", "/app/views/decidim/proposals/proposals/index.html.erb" => "48fbf7a8332f5f4c026b793e7922bdbc", "/app/views/decidim/proposals/proposals/show.html.erb" => "f27bbec257eb6da28dbdd07ac0a224a5", "/app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb" => "b8a9a1b573b2f888b293d10a7fab6577", "/app/views/decidim/proposals/proposals/_proposals.html.erb" => "a4057670154210aff98e5f206d0fdfc2", - "/app/views/decidim/proposals/proposals/_wizard_aside.html.erb" => "45dc17085fabc549bee6474b8a3e79df" + "/app/views/decidim/proposals/proposals/_wizard_aside.html.erb" => "45dc17085fabc549bee6474b8a3e79df", + "/app/views/decidim/proposals/proposals/_filters.html.erb" => "ab4fe3f5b9237d786595374fbb6b729c" } } ] diff --git a/spec/system/limit_amendments_spec.rb b/spec/system/limit_amendments_spec.rb index 89fb122e..3c59a670 100644 --- a/spec/system/limit_amendments_spec.rb +++ b/spec/system/limit_amendments_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "Custom proposals fields", type: :system, versioning: true do - let(:organization) { create :organization } + let(:organization) { create :organization, enable_machine_translations: true, machine_translation_display_priority: "translation" } let(:participatory_process) do create(:participatory_process, :with_steps, organization: organization) end @@ -32,9 +32,15 @@ let(:amendment_creation_enabled) { true } let(:logged_user) { user } let(:enforce_locale) { true } + let(:gpc_conf) do + { + enforce_original_amendments_locale: enforce_locale + } + end before do - allow(Rails.application.secrets).to receive(:enforce_original_amendments_locale).and_return(enforce_locale) + allow(Rails.application.secrets).to receive(:gpc).and_return(gpc_conf) + allow(Decidim).to receive(:machine_translation_service_klass).and_return(nil) switch_to_host(organization.host) login_as logged_user, scope: :user visit_component @@ -109,26 +115,109 @@ def amendment_path context "when amendments are not limited" do let(:limit_pending_amendments) { false } - context "when proposal original locale is not the users locale" do - let(:proposal) { create :proposal, users: [creator], component: component, title: { fr: "Proposal in french" } } - - it "Enforces the original locale" do - click_link proposal.title["fr"] + context "when proposal original locale is not the organization locale" do + before do + click_link "Proposal in french language" click_link "Amend" + end + + let(:proposal) { create :proposal, users: [creator], component: component, title: { fr: "Proposition en langue française", machine_translations: { en: "Proposal in french language" } } } + it "Enforces the original locale" do + expect(page).to have_content("This proposal was originally created in Français") expect(page).not_to have_content("CREATE AMENDMENT DRAFT") expect(page).to have_content("CRÉER UN PROJET D'AMENDEMENT") + expect(page).to have_field(with: "Proposition en langue française") + expect(page).not_to have_field(with: "Proposal in french language") end context "and not enforced" do let(:enforce_locale) { false } it "does not enforce the original locale" do - click_link proposal.title["fr"] - click_link "Amend" + expect(page).not_to have_content("This proposal was originally created in Français") + expect(page).to have_content("CREATE AMENDMENT DRAFT") + expect(page).not_to have_content("CRÉER UN PROJET D'AMENDEMENT") + expect(page).not_to have_field(with: "Proposition en langue française") + expect(page).to have_field(with: "Proposal in french language") + end + end + + context "and user has as preference the translated locale" do + let(:user) { create(:user, :confirmed, organization: organization, locale: "en") } + + it "Enforces the original locale" do + expect(page).to have_content("This proposal was originally created in Français") + expect(page).not_to have_content("CREATE AMENDMENT DRAFT") + expect(page).to have_content("CRÉER UN PROJET D'AMENDEMENT") + expect(page).to have_field(with: "Proposition en langue française") + expect(page).not_to have_field(with: "Proposal in french language") + end + end + end + + context "when proposal original locale is the organization locale" do + let(:creator) { create(:user, :confirmed, organization: organization, locale: "fr") } + let(:proposal) { create :proposal, users: [creator], component: component, title: { en: "Proposal in english language", machine_translations: { fr: "Proposition en langue anglaise" } } } + let(:amendment) { nil } + let(:emendation) { nil } + + before do + within_language_menu do + click_link "Français" + end + + click_link "Proposition en langue anglaise" + click_link "Modifier Proposition" + end + + it "Enforces the original locale" do + expect(page).to have_content("Cette proposition a été initialement créée dans English") + expect(page).to have_content("CREATE AMENDMENT DRAFT") + expect(page).not_to have_content("CRÉER UN PROJET D'AMENDEMENT") + expect(page).to have_field(with: "Proposal in english language") + expect(page).not_to have_field(with: "Proposition en langue anglaise") + fill_in "Title", with: "New Proposal in english language" + click_button "Create" + expect(page).to have_content("EDIT AMENDMENT DRAFT") + end + + context "and is an official proposal" do + let(:proposal) { create :proposal, :official, users: [creator], component: component, title: { en: "Proposal in english language", machine_translations: { fr: "Proposition en langue anglaise" } } } + + it "Does not enforce the original locale" do + expect(page).not_to have_content("Cette proposition a été initialement créée dans English") + expect(page).not_to have_content("CREATE AMENDMENT DRAFT") + expect(page).to have_content("CRÉER UN PROJET D'AMENDEMENT") + expect(page).not_to have_field(with: "Proposal in english language") + expect(page).to have_field(with: "Proposition en langue anglaise") + fill_in "Titre", with: "Nouveau proposition en langue anglaise" + click_button "Créer" + expect(page).to have_content("Aucune modification similaire trouvé.") + end + end + + context "and not enforced" do + let(:enforce_locale) { false } + + it "does not enforce the original locale" do + expect(page).not_to have_content("Cette proposition a été initialement créée dans English") + expect(page).not_to have_content("CREATE AMENDMENT DRAFT") + expect(page).to have_content("CRÉER UN PROJET D'AMENDEMENT") + expect(page).not_to have_field(with: "Proposal in english language") + expect(page).to have_field(with: "Proposition en langue anglaise") + end + end + + context "and user has as preference the translated locale" do + let(:user) { create(:user, :confirmed, organization: organization, locale: "fr") } + it "Enforces the original locale" do + expect(page).to have_content("Cette proposition a été initialement créée dans English") expect(page).to have_content("CREATE AMENDMENT DRAFT") expect(page).not_to have_content("CRÉER UN PROJET D'AMENDEMENT") + expect(page).to have_field(with: "Proposal in english language") + expect(page).not_to have_field(with: "Proposition en langue anglaise") end end end