From cb466cb68a7dda105e64fd6cf550bf4a61bfa490 Mon Sep 17 00:00:00 2001 From: Alexandru Emil Lupu Date: Tue, 21 May 2024 12:39:52 +0300 Subject: [PATCH 01/15] Multilingual organization name (#12681) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial commit * More mailers fixed * Fix more specs * Lint * Fix more specs * refactor * Fix Specs * Fix specs * Fix more specs * Fix specs * lint * Remove helper methods * Add organization uniqueness validator * mark name as translattable * Fix more specs * Fix specs * Running lint * Fix specs * Apply suggestions from code review Co-authored-by: Andrés Pereira de Lucena * use current_organization_name helper * Fis current_organization_name usage * Apply review recommendations * Update decidim-core/db/migrate/20240401192628_change_name_on_decidim_organizations.rb Co-authored-by: Andrés Pereira de Lucena * Apply review recommendation * Apply review recommendations * Lint * Fix specs * Update decidim-system/app/forms/decidim/system/update_organization_form.rb Co-authored-by: Andrés Pereira de Lucena * Fix failing specs * Fix edge case when Organization name is empty in update * Fix edge case --------- Co-authored-by: Andrés Pereira de Lucena --- .../forms/decidim/admin/organization_form.rb | 4 +- .../admin/moderations/reports_helper.rb | 2 + .../decidim/admin/dashboard/show.html.erb | 2 +- .../decidim/admin/organization/_form.html.erb | 2 +- .../decidim/admin/_application.html.erb | 6 +- .../layouts/decidim/admin/_title_bar.html.erb | 2 +- .../admin/_title_bar_responsive.html.erb | 2 +- .../decidim/admin/update_organization_spec.rb | 6 +- ...spec.rb => base_organization_form_spec.rb} | 2 +- .../decidim/api/documentation/show.html.erb | 2 +- .../decidim/api/documentation.html.erb | 2 +- decidim-api/spec/system/documentation_spec.rb | 2 +- .../decidim/blogs/admin/posts_helper.rb | 2 +- .../decidim/blogs/admin/posts/index.html.erb | 2 +- .../decidim/blogs/admin/post_helper_spec.rb | 8 +- .../spec/shared/manage_posts_examples.rb | 12 +- .../spec/system/explore_posts_spec.rb | 2 +- .../spec/types/integration_schema_spec.rb | 6 +- .../budgets/order_summary_mailer_spec.rb | 2 +- decidim-budgets/spec/system/orders_spec.rb | 2 +- .../invite.html.erb | 2 +- .../devise/mailer/join_conference.html.erb | 2 +- .../devise/mailer/join_conference.text.erb | 2 +- .../content_blocks/footer_sub_hero/show.erb | 2 +- .../decidim/content_blocks/hero/show.erb | 2 +- .../how_to_participate/show.erb | 2 +- .../decidim/content_blocks/stats/show.erb | 2 +- .../basic_only_text/show.erb | 4 +- .../image_text_cta/show.erb | 4 +- .../app/cells/decidim/pad_iframe/show.erb | 2 +- .../decidim/report_button/flag_modal.erb | 2 +- .../concerns/decidim/payload_info.rb | 3 +- .../decidim/welcome_notification_event.rb | 2 +- .../app/helpers/decidim/layout_helper.rb | 37 +----- .../helpers/decidim/organization_helper.rb | 55 ++++++++ .../app/mailers/decidim/application_mailer.rb | 8 +- .../app/mailers/decidim/block_user_mailer.rb | 2 +- .../mailers/decidim/decidim_devise_mailer.rb | 8 +- .../app/mailers/decidim/newsletter_mailer.rb | 3 - .../decidim/newsletters_opt_in_mailer.rb | 2 +- .../mailers/decidim/notification_mailer.rb | 1 - .../decidim/notifications_digest_mailer.rb | 1 - .../app/mailers/decidim/reported_mailer.rb | 1 - .../app/mailers/decidim/user_report_mailer.rb | 2 +- .../app/models/decidim/organization.rb | 25 +++- .../decidim/organization_presenter.rb | 2 +- .../decidim/block_user_mailer/notify.html.erb | 4 +- .../decidim/devise/invitations/edit.html.erb | 2 +- .../omniauth_registrations/new.html.erb | 2 +- .../doorkeeper/authorizations/new.html.erb | 2 +- .../gamification/badges/index.html.erb | 2 +- .../newsletter_mailer/newsletter.html.erb | 2 +- .../views/decidim/newsletters/show.html.erb | 2 +- .../newsletters_opt_in_mailer/notify.html.erb | 4 +- .../app/views/decidim/pages/index.html.erb | 2 +- .../decidim/reported_mailer/report.html.erb | 6 +- .../user_report_mailer/notify.html.erb | 4 +- .../user_update_mailer/notify.html.erb | 2 +- .../mailer/invitation_instructions.html.erb | 2 +- .../mailer/invitation_instructions.text.erb | 2 +- .../views/devise/mailer/invite_admin.html.erb | 4 +- .../views/devise/mailer/invite_admin.text.erb | 4 +- .../mailer/invite_collaborator.html.erb | 4 +- .../mailer/invite_collaborator.text.erb | 4 +- .../mailer/invite_private_user.html.erb | 4 +- .../mailer/invite_private_user.text.erb | 4 +- ...ion_admin_invitation_instructions.html.erb | 2 +- ...ion_admin_invitation_instructions.text.erb | 2 +- .../app/views/layouts/decidim/_logo.html.erb | 4 +- .../layouts/decidim/_mailer_logo.html.erb | 4 +- .../decidim/_meta_tags_config.html.erb | 2 +- .../decidim/footer/_main_intro.html.erb | 4 +- .../footer/_main_social_media_links.html.erb | 10 +- ...breadcrumb_main_dropdown_top_left.html.erb | 2 +- .../app/views/layouts/decidim/mailer.html.erb | 4 +- ...28_change_name_on_decidim_organizations.rb | 31 +++++ .../api/interfaces/author_interface.rb | 2 +- .../decidim/api/types/organization_type.rb | 2 +- .../lib/decidim/api/types/user_group_type.rb | 2 +- .../lib/decidim/api/types/user_type.rb | 2 +- decidim-core/lib/decidim/authorable.rb | 5 + decidim-core/lib/decidim/core/seeds.rb | 2 +- .../lib/decidim/core/test/factories.rb | 6 +- .../core/test/shared_examples/logo_email.rb | 2 +- .../download_your_data_user_serializer.rb | 3 +- .../lib/decidim/events/simple_event.rb | 1 + .../lib/tasks/decidim_metrics_tasks.rake | 4 +- .../decidim/content_blocks/hero_cell_spec.rb | 4 +- .../controllers/manifests_controller_spec.rb | 6 +- .../welcome_notification_event_spec.rb | 4 +- ...download_your_data_user_serializer_spec.rb | 2 +- .../spec/lib/events/email_event_spec.rb | 2 +- .../spec/lib/query_extensions_spec.rb | 4 +- .../lib/welcome_notification_event_spec.rb | 4 +- .../spec/mailers/application_mailer_spec.rb | 2 +- .../spec/mailers/block_user_mailer_spec.rb | 2 +- .../mailers/decidim_devise_mailer_spec.rb | 8 +- .../messaging/conversation_mailer_spec.rb | 2 +- .../mailers/newsletters_opt_in_mailer_spec.rb | 2 +- .../notification_digest_mailer_spec.rb | 2 +- .../spec/mailers/notification_mailer_spec.rb | 4 +- .../spec/mailers/reported_mailer_spec.rb | 8 +- .../spec/mailers/user_report_mailer_spec.rb | 2 +- .../spec/mailers/user_update_mailer_spec.rb | 2 +- .../spec/models/decidim/organization_spec.rb | 27 ++++ decidim-core/spec/models/decidim/user_spec.rb | 2 +- .../decidim/organization_presenter_spec.rb | 2 +- decidim-core/spec/system/accesslist_spec.rb | 4 +- .../spec/system/authentication_spec.rb | 4 +- decidim-core/spec/system/homepage_spec.rb | 8 +- decidim-core/spec/system/static_pages_spec.rb | 2 +- decidim-core/spec/types/organization_spec.rb | 4 +- .../spec/types/organization_type_spec.rb | 4 +- .../spec/types/user_group_type_spec.rb | 4 +- decidim-core/spec/types/user_type_spec.rb | 4 +- .../app/models/decidim/debates/debate.rb | 2 +- .../initiatives/initiatives/print.html.erb | 4 +- .../app/models/decidim/meetings/meeting.rb | 2 +- .../invite.html.erb | 4 +- .../meetings/admin/meetings/_form.html.erb | 2 +- .../close_meeting_reminder.html.erb | 2 +- .../meetings/layouts/live_event.html.erb | 2 +- .../decidim/meetings/meetings/_form.html.erb | 2 +- .../views/devise/mailer/join_meeting.html.erb | 4 +- .../views/devise/mailer/join_meeting.text.erb | 4 +- .../system/participatory_processes_spec.rb | 2 +- .../lib/decidim/api/proposal_type.rb | 1 + .../spec/types/integration_schema_spec.rb | 6 +- .../commands/decidim/system/populate_help.rb | 14 +- .../decidim/system/register_organization.rb | 2 +- .../system/organizations_controller.rb | 1 + .../decidim/system/base_organization_form.rb | 123 ++++++++++++++++++ .../system/register_organization_form.rb | 26 +++- .../system/update_organization_form.rb | 115 +++------------- .../decidim/system/application.scss | 57 ++++++++ .../system/oauth_applications/_form.html.erb | 2 +- .../system/organizations/edit.html.erb | 6 +- .../shared/_organizations_list.html.erb | 2 +- .../system/register_organization_spec.rb | 5 +- .../system/update_organization_spec.rb | 48 +++++-- .../system/update_organization_form_spec.rb | 2 +- decidim-system/spec/system/dashboard_spec.rb | 2 +- .../system/manage_oauth_applications_spec.rb | 2 +- .../spec/system/organizations_spec.rb | 34 ++++- .../proposal_answer_templates_controller.rb | 2 +- ..._manages_proposal_answer_templates_spec.rb | 2 +- 146 files changed, 662 insertions(+), 351 deletions(-) rename decidim-admin/spec/forms/{organization_form_spec.rb => base_organization_form_spec.rb} (98%) create mode 100644 decidim-core/app/helpers/decidim/organization_helper.rb create mode 100644 decidim-core/db/migrate/20240401192628_change_name_on_decidim_organizations.rb create mode 100644 decidim-system/app/forms/decidim/system/base_organization_form.rb diff --git a/decidim-admin/app/forms/decidim/admin/organization_form.rb b/decidim-admin/app/forms/decidim/admin/organization_form.rb index e236019f1f5c0..d3d73ee01c3d5 100644 --- a/decidim-admin/app/forms/decidim/admin/organization_form.rb +++ b/decidim-admin/app/forms/decidim/admin/organization_form.rb @@ -10,7 +10,7 @@ class OrganizationForm < Form mimic :organization - attribute :name, String + translatable_attribute :name, String attribute :reference_prefix, String attribute :time_zone, String attribute :twitter_handler, String @@ -37,7 +37,7 @@ class OrganizationForm < Form validates :welcome_notification_subject, :welcome_notification_body, translatable_presence: true, if: proc { |form| form.customize_welcome_notification } - validates :name, presence: true + validates :name, translatable_presence: true validates :time_zone, presence: true validates :time_zone, time_zone: true validates :default_locale, :reference_prefix, presence: true diff --git a/decidim-admin/app/helpers/decidim/admin/moderations/reports_helper.rb b/decidim-admin/app/helpers/decidim/admin/moderations/reports_helper.rb index 63501b2ad5ce0..d317b432963e8 100644 --- a/decidim-admin/app/helpers/decidim/admin/moderations/reports_helper.rb +++ b/decidim-admin/app/helpers/decidim/admin/moderations/reports_helper.rb @@ -28,6 +28,8 @@ def reportable_author_name(reportable) decidim_sanitize_translated(author.title) end end + when Decidim::Organization + content_tag :li, organization_name(author) else content_tag(:li, author.name) end diff --git a/decidim-admin/app/views/decidim/admin/dashboard/show.html.erb b/decidim-admin/app/views/decidim/admin/dashboard/show.html.erb index 37df63b39532c..693224472b8c7 100644 --- a/decidim-admin/app/views/decidim/admin/dashboard/show.html.erb +++ b/decidim-admin/app/views/decidim/admin/dashboard/show.html.erb @@ -2,7 +2,7 @@

- <%= t "decidim.admin.titles.dashboard" %> <%= current_organization.name %> + <%= t "decidim.admin.titles.dashboard" %> <%= current_organization_name %>

diff --git a/decidim-admin/app/views/decidim/admin/organization/_form.html.erb b/decidim-admin/app/views/decidim/admin/organization/_form.html.erb index b39b9ce6d3114..b125717189b0f 100644 --- a/decidim-admin/app/views/decidim/admin/organization/_form.html.erb +++ b/decidim-admin/app/views/decidim/admin/organization/_form.html.erb @@ -3,7 +3,7 @@
- <%= form.text_field :name %> + <%= form.translated :text_field, :name %>
diff --git a/decidim-admin/app/views/layouts/decidim/admin/_application.html.erb b/decidim-admin/app/views/layouts/decidim/admin/_application.html.erb index b6ec73b70a3fa..6f2fa4e1aaad7 100644 --- a/decidim-admin/app/views/layouts/decidim/admin/_application.html.erb +++ b/decidim-admin/app/views/layouts/decidim/admin/_application.html.erb @@ -1,5 +1,5 @@ <% add_decidim_page_title(t("titles.panel", scope: "decidim.admin")) %> -<% add_decidim_page_title(current_organization.name) %> +<% add_decidim_page_title(current_organization_name) %> @@ -21,9 +21,9 @@
- <%= link_to decidim_admin.root_path, class: "logo hidden md:block", data: { "external-link": false }, aria: { label: t("decidim.accessibility.logo", organization: current_organization.name) } do %> + <%= link_to decidim_admin.root_path, class: "logo hidden md:block", data: { "external-link": false }, aria: { label: t("decidim.accessibility.logo", organization: current_organization_name) } do %> <% if current_organization.logo.present? %> - <%= image_tag current_organization.attached_uploader(:logo).path, alt: current_organization.name %> + <%= image_tag current_organization.attached_uploader(:logo).path, alt: current_organization_name %> <% else %> diff --git a/decidim-admin/app/views/layouts/decidim/admin/_title_bar.html.erb b/decidim-admin/app/views/layouts/decidim/admin/_title_bar.html.erb index 6233037b54a77..97d72b9220b49 100644 --- a/decidim-admin/app/views/layouts/decidim/admin/_title_bar.html.erb +++ b/decidim-admin/app/views/layouts/decidim/admin/_title_bar.html.erb @@ -1,7 +1,7 @@
- <%= current_organization.name %> + <%= current_organization_name %>
<%= link_to decidim.root_path, class: "button__site", target: "_blank", data: { "external-link": false } do %> diff --git a/decidim-admin/app/views/layouts/decidim/admin/_title_bar_responsive.html.erb b/decidim-admin/app/views/layouts/decidim/admin/_title_bar_responsive.html.erb index b64c3f394c443..8237ced6b28dd 100644 --- a/decidim-admin/app/views/layouts/decidim/admin/_title_bar_responsive.html.erb +++ b/decidim-admin/app/views/layouts/decidim/admin/_title_bar_responsive.html.erb @@ -2,7 +2,7 @@
<%= icon "menu-line", class: "fill-black" %> - <%= current_organization.name %> + <%= current_organization_name %>
<%= link_to decidim.root_path, class: "button__site", target: "_blank", data: { "external-link": false } do %> diff --git a/decidim-admin/spec/commands/decidim/admin/update_organization_spec.rb b/decidim-admin/spec/commands/decidim/admin/update_organization_spec.rb index 7887d5059c012..710fbb1b74301 100644 --- a/decidim-admin/spec/commands/decidim/admin/update_organization_spec.rb +++ b/decidim-admin/spec/commands/decidim/admin/update_organization_spec.rb @@ -10,7 +10,7 @@ module Decidim::Admin let(:params) do { organization: { - name: "My super organization", + name: { en: "My super organization" }, reference_prefix: "MSO", time_zone: "Hawaii", default_locale: "en", @@ -48,7 +48,7 @@ module Decidim::Admin command.call organization.reload - expect(organization.name).not_to eq("My super organization") + expect(translated(organization.name)).not_to eq("My super organization") end end @@ -74,7 +74,7 @@ module Decidim::Admin expect { command.call }.to broadcast(:ok) organization.reload - expect(organization.name).to eq("My super organization") + expect(translated(organization.name)).to eq("My super organization") expect(organization.rich_text_editor_in_public_views).to be(true) expect(organization.enable_machine_translations).to be(true) end diff --git a/decidim-admin/spec/forms/organization_form_spec.rb b/decidim-admin/spec/forms/base_organization_form_spec.rb similarity index 98% rename from decidim-admin/spec/forms/organization_form_spec.rb rename to decidim-admin/spec/forms/base_organization_form_spec.rb index b5da645503de7..91a32cf2e0179 100644 --- a/decidim-admin/spec/forms/organization_form_spec.rb +++ b/decidim-admin/spec/forms/base_organization_form_spec.rb @@ -11,7 +11,7 @@ module Admin ) end - let(:name) { "My super organization" } + let(:name) { { ca: "", en: "My super organization", es: "" } } let(:reference_prefix) { "MSO" } let(:time_zone) { "UTC" } let(:twitter_handler) { "My twitter awesome handler" } diff --git a/decidim-api/app/views/decidim/api/documentation/show.html.erb b/decidim-api/app/views/decidim/api/documentation/show.html.erb index a6367c1a8fbaf..f1b0a9cae7df0 100644 --- a/decidim-api/app/views/decidim/api/documentation/show.html.erb +++ b/decidim-api/app/views/decidim/api/documentation/show.html.erb @@ -1,7 +1,7 @@
Decidim <%= Decidim.version %>
-

<%= current_organization.name %> API documentation

+

<%= current_organization_name %> API documentation

<% if defined?(graphiql_path) %> <%= link_to "Explore the API interactively with GraphiQL", graphiql_path %> <% end %> diff --git a/decidim-api/app/views/layouts/decidim/api/documentation.html.erb b/decidim-api/app/views/layouts/decidim/api/documentation.html.erb index 29eba32fa7fd8..c26265c72d850 100644 --- a/decidim-api/app/views/layouts/decidim/api/documentation.html.erb +++ b/decidim-api/app/views/layouts/decidim/api/documentation.html.erb @@ -1,6 +1,6 @@ - <%= current_organization.name %> - API Documentation + <%= current_organization_name %> - API Documentation <%= stylesheet_pack_tag("decidim_api_docs") %> diff --git a/decidim-api/spec/system/documentation_spec.rb b/decidim-api/spec/system/documentation_spec.rb index d995788b278b8..0680b00503695 100644 --- a/decidim-api/spec/system/documentation_spec.rb +++ b/decidim-api/spec/system/documentation_spec.rb @@ -14,7 +14,7 @@ visit decidim_api.documentation_path within "h1" do - expect(page).to have_content(organization.name) + expect(page).to have_content(translated(organization.name)) end expect(page).to have_content("About the GraphQL API") end diff --git a/decidim-blogs/app/helpers/decidim/blogs/admin/posts_helper.rb b/decidim-blogs/app/helpers/decidim/blogs/admin/posts_helper.rb index 206bcabbeb102..96fe9d3990f69 100644 --- a/decidim-blogs/app/helpers/decidim/blogs/admin/posts_helper.rb +++ b/decidim-blogs/app/helpers/decidim/blogs/admin/posts_helper.rb @@ -22,7 +22,7 @@ def post_description_admin(post, max_length = 100) def post_author_select_field(form, name, _options = {}) select_options = [ - [current_organization.name, ""], + [current_organization_name, ""], [current_user.name, current_user.id] ] current_user_groups = Decidim::UserGroups::ManageableUserGroups.for(current_user).verified diff --git a/decidim-blogs/app/views/decidim/blogs/admin/posts/index.html.erb b/decidim-blogs/app/views/decidim/blogs/admin/posts/index.html.erb index af173981775e5..6c571e9eb4463 100644 --- a/decidim-blogs/app/views/decidim/blogs/admin/posts/index.html.erb +++ b/decidim-blogs/app/views/decidim/blogs/admin/posts/index.html.erb @@ -33,7 +33,7 @@ <%= decidim_sanitize_editor post_description_admin(post) %> - <%= post.try(:author).try(:name) %> + <%= translated_attribute(post.try(:author).try(:name)) %> <% publish_data = publish_data(post.published_at) %> diff --git a/decidim-blogs/spec/helpers/decidim/blogs/admin/post_helper_spec.rb b/decidim-blogs/spec/helpers/decidim/blogs/admin/post_helper_spec.rb index 94226f441770b..2506adef8739f 100644 --- a/decidim-blogs/spec/helpers/decidim/blogs/admin/post_helper_spec.rb +++ b/decidim-blogs/spec/helpers/decidim/blogs/admin/post_helper_spec.rb @@ -20,7 +20,7 @@ module Decidim::Blogs::Admin let(:all_fields) do [ - [organization.name, ""], + [translated(organization.name), ""], [user.name, user.id], [user_group.name, user_group.id] ] @@ -28,7 +28,7 @@ module Decidim::Blogs::Admin let(:extra_user_fields) do [ - [organization.name, ""], + [translated(organization.name), ""], [user.name, user.id], [user_group.name, user_group.id], [another_user.name, another_user.id] @@ -37,7 +37,7 @@ module Decidim::Blogs::Admin let(:extra_group_fields) do [ - [organization.name, ""], + [translated(organization.name), ""], [user.name, user.id], [user_group.name, user_group.id], [another_user_group.name, another_user_group.id] @@ -46,7 +46,7 @@ module Decidim::Blogs::Admin let(:basic_fields) do [ - [organization.name, ""], + [translated(organization.name), ""], [user.name, user.id] ] end diff --git a/decidim-blogs/spec/shared/manage_posts_examples.rb b/decidim-blogs/spec/shared/manage_posts_examples.rb index 38c5afa6de593..5c4e363393c58 100644 --- a/decidim-blogs/spec/shared/manage_posts_examples.rb +++ b/decidim-blogs/spec/shared/manage_posts_examples.rb @@ -15,7 +15,7 @@ end within ".edit_post" do - expect(page).to have_select("post_decidim_author_id", selected: author.name) + expect(page).to have_select("post_decidim_author_id", selected: translated(author.name)) fill_in_i18n( :post_title, @@ -40,7 +40,7 @@ within "table" do expect(page).to have_content("My new title") expect(page).to have_content("Post title 2") - expect(page).to have_content(author.name) + expect(page).to have_content(translated(author.name)) end end @@ -158,7 +158,7 @@ it "can set organization as posts author" do click_on "New post" - select organization.name, from: "post_decidim_author_id" + select translated(organization.name), from: "post_decidim_author_id" fill_in_i18n( :post_title, @@ -183,7 +183,7 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content(author.name) + expect(page).to have_content(translated(organization.name)) expect(page).to have_content("My post") expect(page).to have_content("Post title 1") expect(page).to have_content("Post title 2") @@ -196,14 +196,14 @@ end within ".edit_post" do - select organization.name, from: "post_decidim_author_id" + select translated(organization.name), from: "post_decidim_author_id" find("*[type=submit]").click end expect(page).to have_admin_callout("successfully") within "tr", text: translated(post1.title) do - expect(page).to have_content(author.name) + expect(page).to have_content(translated(organization.name)) end end end diff --git a/decidim-blogs/spec/system/explore_posts_spec.rb b/decidim-blogs/spec/system/explore_posts_spec.rb index 443e51db913e9..44f3f2ea1e276 100644 --- a/decidim-blogs/spec/system/explore_posts_spec.rb +++ b/decidim-blogs/spec/system/explore_posts_spec.rb @@ -112,7 +112,7 @@ it "show post info" do expect(page).to have_i18n_content(post.title) expect(page).to have_i18n_content(post.body) - expect(page).to have_content(post.author.name) + expect(page).to have_content(translated(post.author.name)) expect(page).to have_content(post.created_at.strftime("%d/%m/%Y %H:%M")) end diff --git a/decidim-blogs/spec/types/integration_schema_spec.rb b/decidim-blogs/spec/types/integration_schema_spec.rb index cfb058eee54ff..6f8f0e83a89d5 100644 --- a/decidim-blogs/spec/types/integration_schema_spec.rb +++ b/decidim-blogs/spec/types/integration_schema_spec.rb @@ -29,7 +29,7 @@ "id" => endo.author.id.to_s, "name" => endo.author.name, "nickname" => "@#{endo.author.nickname}", - "organizationName" => endo.author.organization.name, + "organizationName" => { "translation" => translated(endo.author.organization.name) }, "profilePath" => "/profiles/#{endo.author.nickname}" } end, @@ -98,7 +98,7 @@ deleted name nickname - organizationName + organizationName { translation(locale:"#{locale}") } profilePath __typename } @@ -278,7 +278,7 @@ deleted name nickname - organizationName + organizationName { translation(locale:"#{locale}") } profilePath __typename } diff --git a/decidim-budgets/spec/mailers/decidim/budgets/order_summary_mailer_spec.rb b/decidim-budgets/spec/mailers/decidim/budgets/order_summary_mailer_spec.rb index 46add71a955e3..54917fc6dcb7e 100644 --- a/decidim-budgets/spec/mailers/decidim/budgets/order_summary_mailer_spec.rb +++ b/decidim-budgets/spec/mailers/decidim/budgets/order_summary_mailer_spec.rb @@ -19,7 +19,7 @@ module Decidim::Budgets end it "includes the organization data" do - expect(mail.body.encoded).to include(user.organization.name) + expect(mail.body.encoded).to include(translated(user.organization.name)) end it "includes the budget title" do diff --git a/decidim-budgets/spec/system/orders_spec.rb b/decidim-budgets/spec/system/orders_spec.rb index 642165c304900..b39a890afa513 100644 --- a/decidim-budgets/spec/system/orders_spec.rb +++ b/decidim-budgets/spec/system/orders_spec.rb @@ -305,7 +305,7 @@ expect(page).to have_content "€25,000,000" - page.find("header a", text: organization.name).click + page.find("header a", text: translated(organization.name)).click expect(page).to have_content "You have not yet voted" diff --git a/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb b/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb index 25dccb02ac011..9deb89650b5a6 100644 --- a/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/admin/invite_join_conference_mailer/invite.html.erb @@ -1,7 +1,7 @@ diff --git a/decidim-conferences/app/views/devise/mailer/join_conference.text.erb b/decidim-conferences/app/views/devise/mailer/join_conference.text.erb index 7de23b44a2957..453545bd3a54d 100644 --- a/decidim-conferences/app/views/devise/mailer/join_conference.text.erb +++ b/decidim-conferences/app/views/devise/mailer/join_conference.text.erb @@ -1,6 +1,6 @@ <%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %> -<%= t("decidim.conferences.admin.invite_join_conference_mailer.invite.invited_existing_user_to_join_a_conference", invited_by: @resource.invited_by.name, application: @resource.organization.name) %> +<%= t("decidim.conferences.admin.invite_join_conference_mailer.invite.invited_existing_user_to_join_a_conference", invited_by: @resource.invited_by.name, application: organization_name(@user.organization)) %> <%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:conference]).conference_registration_type_conference_registration_path(conference_slug: @opts[:conference], registration_type_id: @opts[:registration_type]), host: @resource.organization.host) %> diff --git a/decidim-core/app/cells/decidim/content_blocks/footer_sub_hero/show.erb b/decidim-core/app/cells/decidim/content_blocks/footer_sub_hero/show.erb index 05792e12b1eb7..aad342d17c23d 100644 --- a/decidim-core/app/cells/decidim/content_blocks/footer_sub_hero/show.erb +++ b/decidim-core/app/cells/decidim/content_blocks/footer_sub_hero/show.erb @@ -1,7 +1,7 @@
<%= link_to decidim.pages_path, class: "button button__sm md:button__lg button__secondary mt-6" do %> - <%= t("more_info", scope: "decidim.pages.home.extended", resource_name: translated_attribute(current_organization.name, current_organization)) %> + <%= t("more_info", scope: "decidim.pages.home.extended", resource_name: current_organization_name) %> <%= icon "arrow-right-line", class: "fill-current" %> <% end %> diff --git a/decidim-core/app/cells/decidim/content_blocks/stats/show.erb b/decidim-core/app/cells/decidim/content_blocks/stats/show.erb index 2b81899ad08cd..0b53bc559487c 100644 --- a/decidim-core/app/cells/decidim/content_blocks/stats/show.erb +++ b/decidim-core/app/cells/decidim/content_blocks/stats/show.erb @@ -1,6 +1,6 @@

- <%= t("decidim.pages.home.statistics.headline", organization: current_organization.name) %> + <%= t("decidim.pages.home.statistics.headline", organization: current_organization_name) %>

<%= cell("decidim/statistics", stats.highlighted + stats.not_highlighted) %> diff --git a/decidim-core/app/cells/decidim/newsletter_templates/basic_only_text/show.erb b/decidim-core/app/cells/decidim/newsletter_templates/basic_only_text/show.erb index e5d7578db4e7c..f2bb9bc120177 100644 --- a/decidim-core/app/cells/decidim/newsletter_templates/basic_only_text/show.erb +++ b/decidim-core/app/cells/decidim/newsletter_templates/basic_only_text/show.erb @@ -62,9 +62,9 @@ diff --git a/decidim-core/app/cells/decidim/newsletter_templates/image_text_cta/show.erb b/decidim-core/app/cells/decidim/newsletter_templates/image_text_cta/show.erb index b85d85c2104a6..cb1f9ed7bb2ec 100644 --- a/decidim-core/app/cells/decidim/newsletter_templates/image_text_cta/show.erb +++ b/decidim-core/app/cells/decidim/newsletter_templates/image_text_cta/show.erb @@ -101,9 +101,9 @@ table.button table td { diff --git a/decidim-core/app/cells/decidim/pad_iframe/show.erb b/decidim-core/app/cells/decidim/pad_iframe/show.erb index 8ce2389c18c67..7cff5330d34b5 100644 --- a/decidim-core/app/cells/decidim/pad_iframe/show.erb +++ b/decidim-core/app/cells/decidim/pad_iframe/show.erb @@ -8,7 +8,7 @@ src="<%= iframe_url %>" style="border: solid 4px #fff; border-radius: 4px; box-shadow: 0 0 0 1px #e8e8e8; width: 100%; height: 600px"> -

<%= t("decidim.pad_iframe.disclaimer", organization: current_organization.name) %>

+

<%= t("decidim.pad_iframe.disclaimer", organization: current_organization_name) %>

diff --git a/decidim-core/app/cells/decidim/report_button/flag_modal.erb b/decidim-core/app/cells/decidim/report_button/flag_modal.erb index b7d1b981b5c81..5dff59d7d98ed 100644 --- a/decidim-core/app/cells/decidim/report_button/flag_modal.erb +++ b/decidim-core/app/cells/decidim/report_button/flag_modal.erb @@ -10,7 +10,7 @@ <%= f.collection_radio_buttons :reason, [ [:spam, t("decidim.shared.flag_modal.spam")], [:offensive, t("decidim.shared.flag_modal.offensive")], - [:does_not_belong, t("decidim.shared.flag_modal.does_not_belong", organization_name: current_organization.name)] + [:does_not_belong, t("decidim.shared.flag_modal.does_not_belong", organization_name: current_organization_name)] ], :first, :last do |builder| builder.label(for: nil, class: "form__wrapper-checkbox-label") { builder.radio_button(id: nil) + builder.text } end %> diff --git a/decidim-core/app/controllers/concerns/decidim/payload_info.rb b/decidim-core/app/controllers/concerns/decidim/payload_info.rb index c9adfac3fe518..cdb768b5149bf 100644 --- a/decidim-core/app/controllers/concerns/decidim/payload_info.rb +++ b/decidim-core/app/controllers/concerns/decidim/payload_info.rb @@ -5,13 +5,14 @@ module Decidim module PayloadInfo extend ActiveSupport::Concern + include Decidim::TranslatableAttributes included do def append_info_to_payload(payload) super payload[:user_id] = try(:current_user).try(:id) payload[:organization_id] = try(:current_organization).try(:id) - payload[:app] = try(:current_organization).try(:name) + payload[:app] = translated_attribute(try(:current_organization).try(:name)) payload[:remote_ip] = request.remote_ip payload[:referer] = request.referer.to_s payload[:request_id] = request.uuid diff --git a/decidim-core/app/events/decidim/welcome_notification_event.rb b/decidim-core/app/events/decidim/welcome_notification_event.rb index b5ee5994955ba..42188a17eb2cd 100644 --- a/decidim-core/app/events/decidim/welcome_notification_event.rb +++ b/decidim-core/app/events/decidim/welcome_notification_event.rb @@ -44,7 +44,7 @@ def resource_title def interpolate(template) template .gsub("{{name}}", user.name) - .gsub("{{organization}}", organization.name) + .gsub("{{organization}}", organization_name(organization)) .gsub("{{help_url}}", url_helpers.pages_url(host: organization.host)) .gsub("{{badges_url}}", url_helpers.gamification_badges_url(host: organization.host)) .html_safe diff --git a/decidim-core/app/helpers/decidim/layout_helper.rb b/decidim-core/app/helpers/decidim/layout_helper.rb index 458e494f62657..52c3262571ef7 100644 --- a/decidim-core/app/helpers/decidim/layout_helper.rb +++ b/decidim-core/app/helpers/decidim/layout_helper.rb @@ -3,6 +3,7 @@ module Decidim # View helpers related to the layout. module LayoutHelper + include Decidim::OrganizationHelper include Decidim::ModalHelper include Decidim::TooltipHelper @@ -129,28 +130,6 @@ def extended_navigation_bar(items, max_items: 5) } end - # Renders a view with the customizable CSS variables in two flavours: - # 1. as a hexadecimal valid CSS color (ie: #ff0000) - # 2. as a disassembled RGB components (ie: 255 0 0) - # - # Example: - # - # --primary: #ff0000; - # --primary-rgb: 255 0 0 - # - # Hexadecimal variables can be used as a normal CSS color: - # - # color: var(--primary) - # - # While the disassembled variant can be used where you need to manipulate - # the color somehow (ie: adding a background transparency): - # - # background-color: rgba(var(--primary-rgb), 0.5) - def organization_colors - css = current_organization.colors.each.map { |k, v| "--#{k}: #{v};--#{k}-rgb: #{v[1..2].hex} #{v[3..4].hex} #{v[5..6].hex};" }.join - render partial: "layouts/decidim/organization_colors", locals: { css: } - end - def current_user_unread_data return {} if current_user.blank? @@ -161,22 +140,8 @@ def current_user_unread_data end end - def organization_description_label - @organization_description_label ||= if empty_organization_description? - t("decidim.pages.home.footer_sub_hero.footer_sub_hero_body_html") - else - decidim_sanitize_admin(translated_attribute(current_organization.description)) - end - end - private - def empty_organization_description? - organization_description = translated_attribute(current_organization.description) - - organization_description.blank? || organization_description == "

" - end - def tag_builder @tag_builder ||= ActionView::Helpers::TagHelper::TagBuilder.new(self) end diff --git a/decidim-core/app/helpers/decidim/organization_helper.rb b/decidim-core/app/helpers/decidim/organization_helper.rb new file mode 100644 index 0000000000000..722929c0eb703 --- /dev/null +++ b/decidim-core/app/helpers/decidim/organization_helper.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +module Decidim + # View helpers related to the organization. + + module OrganizationHelper + include Decidim::TranslatableAttributes + + # Renders a view with the customizable CSS variables in two flavours: + # 1. as a hexadecimal valid CSS color (ie: #ff0000) + # 2. as a disassembled RGB components (ie: 255 0 0) + # + # Example: + # + # --primary: #ff0000; + # --primary-rgb: 255 0 0 + # + # Hexadecimal variables can be used as a normal CSS color: + # + # color: var(--primary) + # + # While the disassembled variant can be used where you need to manipulate + # the color somehow (ie: adding a background transparency): + # + # background-color: rgba(var(--primary-rgb), 0.5) + def organization_colors + css = current_organization.colors.each.map { |k, v| "--#{k}: #{v};--#{k}-rgb: #{v[1..2].hex} #{v[3..4].hex} #{v[5..6].hex};" }.join + render partial: "layouts/decidim/organization_colors", locals: { css: } + end + + def organization_description_label + @organization_description_label ||= if empty_organization_description? + t("decidim.pages.home.footer_sub_hero.footer_sub_hero_body_html") + else + decidim_sanitize_admin(translated_attribute(current_organization.description)) + end + end + + def organization_name(organization = current_organization) + translated_attribute(organization.name, organization) + end + + def current_organization_name + organization_name(current_organization) + end + + private + + def empty_organization_description? + organization_description = translated_attribute(current_organization.description) + + organization_description.blank? || organization_description == "

" + end + end +end diff --git a/decidim-core/app/mailers/decidim/application_mailer.rb b/decidim-core/app/mailers/decidim/application_mailer.rb index f334811eec2a3..3a6c5cc79adcd 100644 --- a/decidim-core/app/mailers/decidim/application_mailer.rb +++ b/decidim-core/app/mailers/decidim/application_mailer.rb @@ -6,6 +6,10 @@ module Decidim class ApplicationMailer < ActionMailer::Base include LocalisedMailer include MultitenantAssetHost + include Decidim::SanitizeHelper + include Decidim::OrganizationHelper + helper_method :organization_name, :decidim_escape_translated, :decidim_sanitize_translated, :translated_attribute, :decidim_sanitize, :decidim_sanitize_newsletter + after_action :set_smtp after_action :set_from @@ -44,11 +48,11 @@ def sender smtp_settings_from = organization.smtp_settings["from"] return smtp_settings_from if already_defined_name_in_mail?(smtp_settings_from) - email_address_with_name(smtp_settings_from, organization.name) + email_address_with_name(smtp_settings_from, organization_name(organization)) end def default_sender - email_address_with_name(Decidim.config.mailer_sender, organization.name) + email_address_with_name(Decidim.config.mailer_sender, organization_name(organization)) end def already_defined_name_in_mail?(mail_address) diff --git a/decidim-core/app/mailers/decidim/block_user_mailer.rb b/decidim-core/app/mailers/decidim/block_user_mailer.rb index 5591246e03b0c..142d367a87781 100644 --- a/decidim-core/app/mailers/decidim/block_user_mailer.rb +++ b/decidim-core/app/mailers/decidim/block_user_mailer.rb @@ -11,7 +11,7 @@ def notify(user, justification) @justification = justification subject = I18n.t( "decidim.block_user_mailer.notify.subject", - organization_name: @organization.name, + organization_name: organization_name(@organization), justification: @justification ) diff --git a/decidim-core/app/mailers/decidim/decidim_devise_mailer.rb b/decidim-core/app/mailers/decidim/decidim_devise_mailer.rb index fcbd26a9401c5..48e04822f3842 100644 --- a/decidim-core/app/mailers/decidim/decidim_devise_mailer.rb +++ b/decidim-core/app/mailers/decidim/decidim_devise_mailer.rb @@ -5,6 +5,8 @@ module Decidim # each role and use a localised version. class DecidimDeviseMailer < ::Devise::Mailer include LocalisedMailer + include Decidim::SanitizeHelper + helper_method :decidim_escape_translated, :decidim_sanitize_translated, :translated_attribute layout "decidim/mailer" @@ -19,7 +21,11 @@ def invitation_instructions(user, token, opts = {}) @organization = user.organization @opts = opts - opts[:subject] = I18n.t("devise.mailer.#{opts[:invitation_instructions]}.subject", organization: user.organization.name) if opts[:invitation_instructions] + if opts[:invitation_instructions] + opts[:subject] = + I18n.t("devise.mailer.#{opts[:invitation_instructions]}.subject", + organization: organization_name(user.organization)) + end end devise_mail(user, opts[:invitation_instructions] || :invitation_instructions, opts) diff --git a/decidim-core/app/mailers/decidim/newsletter_mailer.rb b/decidim-core/app/mailers/decidim/newsletter_mailer.rb index cee715ed79a16..72b8ca59450ac 100644 --- a/decidim-core/app/mailers/decidim/newsletter_mailer.rb +++ b/decidim-core/app/mailers/decidim/newsletter_mailer.rb @@ -2,9 +2,6 @@ module Decidim class NewsletterMailer < ApplicationMailer - helper Decidim::SanitizeHelper - helper Decidim::TranslationsHelper - include Decidim::NewslettersHelper layout "decidim/newsletter_base" diff --git a/decidim-core/app/mailers/decidim/newsletters_opt_in_mailer.rb b/decidim-core/app/mailers/decidim/newsletters_opt_in_mailer.rb index 81e2e65733bb1..e5e0020c0be7b 100644 --- a/decidim-core/app/mailers/decidim/newsletters_opt_in_mailer.rb +++ b/decidim-core/app/mailers/decidim/newsletters_opt_in_mailer.rb @@ -10,7 +10,7 @@ def notify(user, token) @organization = user.organization @token = token - mail(to: user.email, subject: I18n.t("decidim.newsletters_opt_in_mailer.notify.subject", organization_name: @organization.name)) + mail(to: user.email, subject: I18n.t("decidim.newsletters_opt_in_mailer.notify.subject", organization_name: organization_name(@organization))) end end end diff --git a/decidim-core/app/mailers/decidim/notification_mailer.rb b/decidim-core/app/mailers/decidim/notification_mailer.rb index c9060132614fa..c744280fcf075 100644 --- a/decidim-core/app/mailers/decidim/notification_mailer.rb +++ b/decidim-core/app/mailers/decidim/notification_mailer.rb @@ -5,7 +5,6 @@ module Decidim # a events are received. class NotificationMailer < Decidim::ApplicationMailer helper Decidim::ResourceHelper - helper Decidim::SanitizeHelper def event_received(event, event_class_name, resource, user, user_role, extra) # rubocop:disable Metrics/ParameterLists with_user(user) do diff --git a/decidim-core/app/mailers/decidim/notifications_digest_mailer.rb b/decidim-core/app/mailers/decidim/notifications_digest_mailer.rb index 53d14210b6df5..62c5b6792fe57 100644 --- a/decidim-core/app/mailers/decidim/notifications_digest_mailer.rb +++ b/decidim-core/app/mailers/decidim/notifications_digest_mailer.rb @@ -5,7 +5,6 @@ module Decidim # a events are received. class NotificationsDigestMailer < Decidim::ApplicationMailer helper Decidim::ResourceHelper - helper Decidim::SanitizeHelper SIZE_LIMIT = 10 def digest_mail(user, notification_ids) diff --git a/decidim-core/app/mailers/decidim/reported_mailer.rb b/decidim-core/app/mailers/decidim/reported_mailer.rb index 5bb27a75ca0a7..d3aaa937395fd 100644 --- a/decidim-core/app/mailers/decidim/reported_mailer.rb +++ b/decidim-core/app/mailers/decidim/reported_mailer.rb @@ -4,7 +4,6 @@ module Decidim # A custom mailer for sending notifications to an admin when a report is created. class ReportedMailer < Decidim::ApplicationMailer helper Decidim::ResourceHelper - helper Decidim::TranslationsHelper helper_method :reported_content_url, :report_url, :manage_moderations_url, :author_profile_url, :reported_content_cell diff --git a/decidim-core/app/mailers/decidim/user_report_mailer.rb b/decidim-core/app/mailers/decidim/user_report_mailer.rb index 59377fb899834..c2334aecc0e08 100644 --- a/decidim-core/app/mailers/decidim/user_report_mailer.rb +++ b/decidim-core/app/mailers/decidim/user_report_mailer.rb @@ -11,7 +11,7 @@ def notify(admin, report) with_user(admin) do mail(to: admin.email, subject: I18n.t( "decidim.user_report_mailer.notify.subject", - organization_name: report.moderation.user.organization.name, + organization_name: organization_name(report.moderation.user.organization), reason: @report.reason )) end diff --git a/decidim-core/app/models/decidim/organization.rb b/decidim-core/app/models/decidim/organization.rb index 893eb956a7d63..9215737ddf4ef 100644 --- a/decidim-core/app/models/decidim/organization.rb +++ b/decidim-core/app/models/decidim/organization.rb @@ -15,7 +15,7 @@ class Organization < ApplicationRecord SOCIAL_HANDLERS = [:twitter, :facebook, :instagram, :youtube, :github].freeze AVAILABLE_MACHINE_TRANSLATION_DISPLAY_PRIORITIES = %w(original translation).freeze - translatable_fields :description, :cta_button_text, :omnipresent_banner_title, :omnipresent_banner_short_description, + translatable_fields :name, :description, :cta_button_text, :omnipresent_banner_title, :omnipresent_banner_short_description, :highlighted_content_banner_title, :highlighted_content_banner_short_description, :highlighted_content_banner_action_title, :highlighted_content_banner_action_subtitle, :welcome_notification_subject, :welcome_notification_body, :id_documents_explanation_text, :admin_terms_of_service_body @@ -41,7 +41,7 @@ class Organization < ApplicationRecord # disable: Users cannot register or sign in. enum users_registration_mode: [:enabled, :existing, :disabled], _prefix: true - validates :name, :host, uniqueness: true + validates :host, uniqueness: true validates :reference_prefix, presence: true validates :time_zone, presence: true, time_zone: true validates :default_locale, inclusion: { in: :available_locales } @@ -60,6 +60,27 @@ class Organization < ApplicationRecord has_one_attached :open_data_file + validate :unique_name + + def unique_name + base_query = new_record? ? Decidim::Organization.all : Decidim::Organization.where.not(id:).all + + organization_names = [] + + base_query.pluck(:name).each do |value| + organization_names += value.except("machine_translations").values + organization_names += value.fetch("machine_translations", {}).values + end + + organization_names = organization_names.map(&:downcase).compact_blank + + name.each do |language, value| + next if value.is_a?(Hash) + + errors.add("name_#{language}", :taken) if organization_names.include?(value.downcase) + end + end + def self.log_presenter_class_for(_log) Decidim::AdminLog::OrganizationPresenter end diff --git a/decidim-core/app/presenters/decidim/organization_presenter.rb b/decidim-core/app/presenters/decidim/organization_presenter.rb index fd275dd3bd93a..1b542a8afdb70 100644 --- a/decidim-core/app/presenters/decidim/organization_presenter.rb +++ b/decidim-core/app/presenters/decidim/organization_presenter.rb @@ -4,7 +4,7 @@ module Decidim # A general presenter to render organization logic to build a manifest class OrganizationPresenter < SimpleDelegator def html_name - name.html_safe + translated_attribute(name).html_safe end def translated_description diff --git a/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb b/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb index 230a4e9b5ad18..ed0ec06fb7207 100644 --- a/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb +++ b/decidim-core/app/views/decidim/block_user_mailer/notify.html.erb @@ -1,7 +1,7 @@ - + - + diff --git a/decidim-core/app/views/decidim/devise/invitations/edit.html.erb b/decidim-core/app/views/decidim/devise/invitations/edit.html.erb index 265b15674a805..37b3ddad15556 100644 --- a/decidim-core/app/views/decidim/devise/invitations/edit.html.erb +++ b/decidim-core/app/views/decidim/devise/invitations/edit.html.erb @@ -14,7 +14,7 @@
<%= f.hidden_field :invitation_token %> - <%= f.text_field :nickname, help_text: t("devise.invitations.edit.nickname_help", organization: current_organization.name), required: "required", autocomplete: "nickname" %> + <%= f.text_field :nickname, help_text: t("devise.invitations.edit.nickname_help", organization: current_organization_name), required: "required", autocomplete: "nickname" %> <% if f.object.class.require_password_on_accepting %> <%= render partial: "decidim/account/password_fields", locals: { form: f, user: :user } %> diff --git a/decidim-core/app/views/decidim/devise/omniauth_registrations/new.html.erb b/decidim-core/app/views/decidim/devise/omniauth_registrations/new.html.erb index d70f83672100f..9565e5089ecd9 100644 --- a/decidim-core/app/views/decidim/devise/omniauth_registrations/new.html.erb +++ b/decidim-core/app/views/decidim/devise/omniauth_registrations/new.html.erb @@ -18,7 +18,7 @@
<%= f.text_field :name, help_text: t("decidim.devise.omniauth_registrations.new.username_help"), autocomplete: "name", placeholder: "John Doe" %> - <%= f.text_field :nickname, help_text: t("decidim.devise.omniauth_registrations.new.nickname_help", organization: current_organization.name), autocomplete: "nickname", placeholder: "johndoe" %> + <%= f.text_field :nickname, help_text: t("decidim.devise.omniauth_registrations.new.nickname_help", organization: current_organization_name), autocomplete: "nickname", placeholder: "johndoe" %> <%= f.email_field :email, autocomplete: "email", placeholder: t("placeholder_email", scope: "decidim.devise.shared") %> diff --git a/decidim-core/app/views/decidim/doorkeeper/authorizations/new.html.erb b/decidim-core/app/views/decidim/doorkeeper/authorizations/new.html.erb index 5b95a35da23af..c1acab5045da7 100644 --- a/decidim-core/app/views/decidim/doorkeeper/authorizations/new.html.erb +++ b/decidim-core/app/views/decidim/doorkeeper/authorizations/new.html.erb @@ -8,7 +8,7 @@ diff --git a/decidim-core/app/views/decidim/reported_mailer/report.html.erb b/decidim-core/app/views/decidim/reported_mailer/report.html.erb index 306bb62235e66..701a3c48c9e79 100644 --- a/decidim-core/app/views/decidim/reported_mailer/report.html.erb +++ b/decidim-core/app/views/decidim/reported_mailer/report.html.erb @@ -13,7 +13,7 @@

<%= link_to translated_attribute(@participatory_space.title), resource_locator(@participatory_space).url %>

<%= t(".reason") %>

-

<%= t(@report.reason, organization_name: @participatory_space.organization.name, scope: "decidim.shared.flag_modal") %>

+

<%= t(@report.reason, organization_name: organization_name(@participatory_space.organization), scope: "decidim.shared.flag_modal") %>

<% if @report.details.present? %>

<%= t(".details") %>

@@ -37,7 +37,9 @@ <% else %>

<%= - if @author.respond_to?(:name) + if @author.is_a?(Decidim::Organization) + organization_name(@author) + elsif @author.respond_to?(:name) @author.name elsif @author.respond_to?(:title) translated_attribute(@author.title) diff --git a/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb b/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb index d3aad1353df87..bb078a6f68eb8 100644 --- a/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb +++ b/decidim-core/app/views/decidim/user_report_mailer/notify.html.erb @@ -2,7 +2,7 @@

- + <% if @report.details.present? %> @@ -11,4 +11,4 @@ <% end %> - + diff --git a/decidim-core/app/views/decidim/user_update_mailer/notify.html.erb b/decidim-core/app/views/decidim/user_update_mailer/notify.html.erb index 7915502c211fa..4e099d7dbbb19 100644 --- a/decidim-core/app/views/decidim/user_update_mailer/notify.html.erb +++ b/decidim-core/app/views/decidim/user_update_mailer/notify.html.erb @@ -6,4 +6,4 @@ - + diff --git a/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb b/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb index e518af3508f8d..6b0da4e6b237d 100644 --- a/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb +++ b/decidim-core/app/views/devise/mailer/invitation_instructions.html.erb @@ -1,7 +1,7 @@ diff --git a/decidim-core/app/views/devise/mailer/invitation_instructions.text.erb b/decidim-core/app/views/devise/mailer/invitation_instructions.text.erb index 33887fcf34677..151078176dc43 100644 --- a/decidim-core/app/views/devise/mailer/invitation_instructions.text.erb +++ b/decidim-core/app/views/devise/mailer/invitation_instructions.text.erb @@ -1,6 +1,6 @@ <%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %> -<%= t("devise.mailer.invitation_instructions.someone_invited_you", application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.someone_invited_you", application: organization_name(@resource.organization)) %> <%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim.root_path, host: @resource.organization.host) %> diff --git a/decidim-core/app/views/devise/mailer/invite_admin.html.erb b/decidim-core/app/views/devise/mailer/invite_admin.html.erb index d0733210c7e4f..3a660c0884767 100644 --- a/decidim-core/app/views/devise/mailer/invite_admin.html.erb +++ b/decidim-core/app/views/devise/mailer/invite_admin.html.erb @@ -2,9 +2,9 @@ diff --git a/decidim-core/app/views/devise/mailer/invite_admin.text.erb b/decidim-core/app/views/devise/mailer/invite_admin.text.erb index 2da16effaec97..52775b1aed59c 100644 --- a/decidim-core/app/views/devise/mailer/invite_admin.text.erb +++ b/decidim-core/app/views/devise/mailer/invite_admin.text.erb @@ -1,9 +1,9 @@ <%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %> <% if @resource.invited_by.present? %> -<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", invited_by: @resource.invited_by.name, application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", invited_by: @resource.invited_by.name, application: organization_name(@resource.organization)) %> <% else %> -<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", application: organization_name(@resource.organization)) %> <% end %> <%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %> diff --git a/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb b/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb index d0733210c7e4f..3a660c0884767 100644 --- a/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb +++ b/decidim-core/app/views/devise/mailer/invite_collaborator.html.erb @@ -2,9 +2,9 @@ diff --git a/decidim-core/app/views/devise/mailer/invite_collaborator.text.erb b/decidim-core/app/views/devise/mailer/invite_collaborator.text.erb index 2da16effaec97..52775b1aed59c 100644 --- a/decidim-core/app/views/devise/mailer/invite_collaborator.text.erb +++ b/decidim-core/app/views/devise/mailer/invite_collaborator.text.erb @@ -1,9 +1,9 @@ <%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %> <% if @resource.invited_by.present? %> -<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", invited_by: @resource.invited_by.name, application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.invited_you_as_admin", invited_by: @resource.invited_by.name, application: organization_name(@resource.organization)) %> <% else %> -<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_admin", application: organization_name(@resource.organization)) %> <% end %> <%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %> diff --git a/decidim-core/app/views/devise/mailer/invite_private_user.html.erb b/decidim-core/app/views/devise/mailer/invite_private_user.html.erb index 3b5e9029e09c1..3694d05a6827d 100644 --- a/decidim-core/app/views/devise/mailer/invite_private_user.html.erb +++ b/decidim-core/app/views/devise/mailer/invite_private_user.html.erb @@ -2,9 +2,9 @@ diff --git a/decidim-core/app/views/devise/mailer/invite_private_user.text.erb b/decidim-core/app/views/devise/mailer/invite_private_user.text.erb index e34ff1d366585..8f572859214a1 100644 --- a/decidim-core/app/views/devise/mailer/invite_private_user.text.erb +++ b/decidim-core/app/views/devise/mailer/invite_private_user.text.erb @@ -1,9 +1,9 @@ <%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %> <% if @resource.invited_by.present? %> -<%= t("devise.mailer.invitation_instructions.invited_you_as_private_user", invited_by: @resource.invited_by.name, application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.invited_you_as_private_user", invited_by: @resource.invited_by.name, application: organization_name(@resource.organization)) %> <% else %> -<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_private_user", application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.someone_invited_you_as_private_user", application: organization_name(@resource.organization)) %> <% end %> <%= accept_invitation_url(@resource, invitation_token: @token, host: @resource.organization.host) %> diff --git a/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb b/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb index 68198d936fb5a..4c1de528295ac 100644 --- a/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb +++ b/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb @@ -1,6 +1,6 @@ - + diff --git a/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.text.erb b/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.text.erb index 26d0644bb6c75..812882ca2802e 100644 --- a/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.text.erb +++ b/decidim-core/app/views/devise/mailer/organization_admin_invitation_instructions.text.erb @@ -1,6 +1,6 @@ <%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %> -<%= t("devise.mailer.invitation_instructions.someone_invited_you", application: @resource.organization.name) %> +<%= t("devise.mailer.invitation_instructions.someone_invited_you", application: organization_name(@resource.organization)) %> <%= accept_invitation_url(@resource, invitation_token: @token, invite_redirect: decidim_admin.root_path, host: @resource.organization.host) %> diff --git a/decidim-core/app/views/layouts/decidim/_logo.html.erb b/decidim-core/app/views/layouts/decidim/_logo.html.erb index 539fab122601d..e1b0ccaa1c868 100644 --- a/decidim-core/app/views/layouts/decidim/_logo.html.erb +++ b/decidim-core/app/views/layouts/decidim/_logo.html.erb @@ -1,9 +1,9 @@ <% if organization %> <%= link_to decidim.root_url(host: organization.host), "aria-label": t("front_page_link", scope: "decidim.accessibility") do %> <% if organization.logo.attached? %> - <%= image_tag organization.attached_uploader(:logo).variant_path(:medium), alt: t("logo", scope: "decidim.accessibility", organization: organization.name) %> + <%= image_tag organization.attached_uploader(:logo).variant_path(:medium), alt: t("logo", scope: "decidim.accessibility", organization: current_organization_name) %> <% else %> - <%= organization.name %> + <%= current_organization_name %> <% end %> <% end %> <% else %> diff --git a/decidim-core/app/views/layouts/decidim/_mailer_logo.html.erb b/decidim-core/app/views/layouts/decidim/_mailer_logo.html.erb index ae5c7f4a70ea9..105bd94463566 100644 --- a/decidim-core/app/views/layouts/decidim/_mailer_logo.html.erb +++ b/decidim-core/app/views/layouts/decidim/_mailer_logo.html.erb @@ -9,10 +9,10 @@ <%= image_tag( organization.attached_uploader(:logo).variant_url(:medium, host: organization.host), style: "max-height: 50px", - alt: "#{organization.name}" + alt: organization_name(organization) ) %> <% else %> - <%= organization.name %> + <%= organization_name(organization) %> <% end %> <% end %> <% else %> diff --git a/decidim-core/app/views/layouts/decidim/_meta_tags_config.html.erb b/decidim-core/app/views/layouts/decidim/_meta_tags_config.html.erb index 73b0152564945..69725992dc4be 100644 --- a/decidim-core/app/views/layouts/decidim/_meta_tags_config.html.erb +++ b/decidim-core/app/views/layouts/decidim/_meta_tags_config.html.erb @@ -1,6 +1,6 @@ <% add_decidim_meta_tags({ description: strip_tags(translated_attribute(current_organization.description)), - title: current_organization.name, + title: current_organization_name, url: request.original_url, twitter_handler: current_organization.twitter_handler, image_url: Decidim::ContentBlock.published.find_by( diff --git a/decidim-core/app/views/layouts/decidim/footer/_main_intro.html.erb b/decidim-core/app/views/layouts/decidim/footer/_main_intro.html.erb index 783804d77e1eb..1bd2fada7cd76 100644 --- a/decidim-core/app/views/layouts/decidim/footer/_main_intro.html.erb +++ b/decidim-core/app/views/layouts/decidim/footer/_main_intro.html.erb @@ -1,9 +1,9 @@ <% if current_organization.official_img_footer.attached? %> <%= link_to current_organization.official_url, class: "block mb-6" do %> - <%= image_tag current_organization.attached_uploader(:official_img_footer).path, alt: current_organization.name, class: "max-h-16" %> + <%= image_tag current_organization.attached_uploader(:official_img_footer).path, alt: current_organization_name, class: "max-h-16" %> <% end %> <% end %>
-

<%= t("decidim.pages.home.footer_sub_hero.footer_sub_hero_headline", organization: current_organization.name) %>

+

<%= t("decidim.pages.home.footer_sub_hero.footer_sub_hero_headline", organization: current_organization_name) %>

<%= organization_description_label %>

diff --git a/decidim-core/app/views/layouts/decidim/footer/_main_social_media_links.html.erb b/decidim-core/app/views/layouts/decidim/footer/_main_social_media_links.html.erb index c7b86f444c8c8..7e6a8e52cfaf4 100644 --- a/decidim-core/app/views/layouts/decidim/footer/_main_social_media_links.html.erb +++ b/decidim-core/app/views/layouts/decidim/footer/_main_social_media_links.html.erb @@ -2,7 +2,7 @@ <% if current_organization.twitter_handler.present? %>
  • - <%= t("layouts.decidim.social_media_links.x", organization: translated_attribute(current_organization.name)) %> + <%= t("layouts.decidim.social_media_links.x", organization: current_organization_name) %> <%= icon "twitter-x-line", class: "w-8 h-8 fill-current", "aria-label": "X" %>
  • @@ -10,7 +10,7 @@ <% if current_organization.facebook_handler.present? %>
  • - <%= t("layouts.decidim.social_media_links.facebook", organization: translated_attribute(current_organization.name)) %> + <%= t("layouts.decidim.social_media_links.facebook", organization: current_organization_name) %> <%= icon "facebook-fill", class: "w-8 h-8 fill-current", "aria-label": "Facebook" %>
  • @@ -18,7 +18,7 @@ <% if current_organization.instagram_handler.present? %>
  • - <%= t("layouts.decidim.social_media_links.instagram", organization: translated_attribute(current_organization.name)) %> + <%= t("layouts.decidim.social_media_links.instagram", organization: current_organization_name) %> <%= icon "instagram-line", class: "w-8 h-8 fill-current", "aria-label": "Instagram" %>
  • @@ -26,7 +26,7 @@ <% if current_organization.youtube_handler.present? %>
  • - <%= t("layouts.decidim.social_media_links.youtube", organization: translated_attribute(current_organization.name)) %> + <%= t("layouts.decidim.social_media_links.youtube", organization: current_organization_name) %> <%= icon "youtube-line", class: "w-8 h-8 fill-current", "aria-label": "YouTube" %>
  • @@ -34,7 +34,7 @@ <% if current_organization.github_handler.present? %>
  • - <%= t("layouts.decidim.social_media_links.github", organization: translated_attribute(current_organization.name)) %> + <%= t("layouts.decidim.social_media_links.github", organization: current_organization_name) %> <%= icon "github-fill", class: "w-8 h-8 fill-current", "aria-label": "GitHub" %>
  • diff --git a/decidim-core/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown_top_left.html.erb b/decidim-core/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown_top_left.html.erb index 5267087180a90..f7dde44f3d1ba 100644 --- a/decidim-core/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown_top_left.html.erb +++ b/decidim-core/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown_top_left.html.erb @@ -1,2 +1,2 @@ - + diff --git a/decidim-core/app/views/layouts/decidim/mailer.html.erb b/decidim-core/app/views/layouts/decidim/mailer.html.erb index 87b5f9d7899f4..c51fa305838b1 100644 --- a/decidim-core/app/views/layouts/decidim/mailer.html.erb +++ b/decidim-core/app/views/layouts/decidim/mailer.html.erb @@ -83,9 +83,9 @@ diff --git a/decidim-core/db/migrate/20240401192628_change_name_on_decidim_organizations.rb b/decidim-core/db/migrate/20240401192628_change_name_on_decidim_organizations.rb new file mode 100644 index 0000000000000..f2d2f5abb01f3 --- /dev/null +++ b/decidim-core/db/migrate/20240401192628_change_name_on_decidim_organizations.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class ChangeNameOnDecidimOrganizations < ActiveRecord::Migration[6.1] + class Organization < ApplicationRecord + self.table_name = :decidim_organizations + end + + def up + rename_column :decidim_organizations, :name, :old_name + add_column :decidim_organizations, :name, :jsonb, null: false, default: {} + + Organization.reset_column_information + + Organization.find_each do |organization| + organization.update(name: { organization.default_locale => organization.old_name }) + end + remove_column :decidim_organizations, :old_name + end + + def down + rename_column :decidim_organizations, :name, :old_name + add_column :decidim_organizations, :name, :string, null: false, default: "" + + Organization.reset_column_information + + Organization.find_each do |organization| + organization.update(name: organization.old_name[organization.default_locale]) + end + remove_column :decidim_organizations, :old_name + end +end diff --git a/decidim-core/lib/decidim/api/interfaces/author_interface.rb b/decidim-core/lib/decidim/api/interfaces/author_interface.rb index 7c6ad1653b8c8..a82aad94742fe 100644 --- a/decidim-core/lib/decidim/api/interfaces/author_interface.rb +++ b/decidim-core/lib/decidim/api/interfaces/author_interface.rb @@ -15,7 +15,7 @@ module AuthorInterface field :avatar_url, String, "The author's avatar url", null: false field :profile_path, String, "The author's profile path", null: false field :badge, String, "The author's badge icon", null: false - field :organization_name, String, "The authors's organization name", null: false + field :organization_name, Decidim::Core::TranslatedFieldType, "The authors's organization name", null: false def organization_name object.organization.name diff --git a/decidim-core/lib/decidim/api/types/organization_type.rb b/decidim-core/lib/decidim/api/types/organization_type.rb index 42836d71df294..daab328d62677 100644 --- a/decidim-core/lib/decidim/api/types/organization_type.rb +++ b/decidim-core/lib/decidim/api/types/organization_type.rb @@ -5,7 +5,7 @@ module Core class OrganizationType < Decidim::Api::Types::BaseObject description "The current organization" - field :name, GraphQL::Types::String, "The name of the current organization", null: true + field :name, Decidim::Core::TranslatedFieldType, "The name of the current organization", null: true field :stats, [Core::StatisticType, { null: true }], description: "The statistics associated to this object", null: true diff --git a/decidim-core/lib/decidim/api/types/user_group_type.rb b/decidim-core/lib/decidim/api/types/user_group_type.rb index 2e9b1d7ebb593..3e94a4fbbf5e0 100644 --- a/decidim-core/lib/decidim/api/types/user_group_type.rb +++ b/decidim-core/lib/decidim/api/types/user_group_type.rb @@ -30,7 +30,7 @@ def profile_path object.presenter.profile_path end - field :organization_name, GraphQL::Types::String, "The user group's organization name", null: false + field :organization_name, Decidim::Core::TranslatedFieldType, "The user group's organization name", null: false def organization_name object.organization.name diff --git a/decidim-core/lib/decidim/api/types/user_type.rb b/decidim-core/lib/decidim/api/types/user_type.rb index e6649bf1f5723..1795653040a53 100644 --- a/decidim-core/lib/decidim/api/types/user_type.rb +++ b/decidim-core/lib/decidim/api/types/user_type.rb @@ -23,7 +23,7 @@ class UserType < Decidim::Api::Types::BaseObject description: ["If the user making the request is logged in, it will return whether this recipient accepts a conversation or not.", " It will return false for non-logged requests."].join - field :organization_name, GraphQL::Types::String, "The user's organization name", null: false + field :organization_name, Decidim::Core::TranslatedFieldType, "The user's organization name", null: false field :deleted, GraphQL::Types::Boolean, "Whether the user's account has been deleted or not", null: false diff --git a/decidim-core/lib/decidim/authorable.rb b/decidim-core/lib/decidim/authorable.rb index a704bbff8aa88..970c14517468b 100644 --- a/decidim-core/lib/decidim/authorable.rb +++ b/decidim-core/lib/decidim/authorable.rb @@ -7,6 +7,7 @@ module Decidim # this latest case the Coauthorable concern should be used instead of Authorable. module Authorable extend ActiveSupport::Concern + include Decidim::TranslatableAttributes included do belongs_to :author, polymorphic: true, foreign_key: "decidim_author_id", foreign_type: "decidim_author_type" @@ -68,6 +69,10 @@ def official? decidim_author_type == Decidim::Organization.name end + def author_name + translated_attribute(normalized_author.name) + end + private def verified_user_group diff --git a/decidim-core/lib/decidim/core/seeds.rb b/decidim-core/lib/decidim/core/seeds.rb index 0c9e726cc9466..a83d2eade5f14 100644 --- a/decidim-core/lib/decidim/core/seeds.rb +++ b/decidim-core/lib/decidim/core/seeds.rb @@ -124,7 +124,7 @@ def create_organization! } Decidim::Organization.first || Decidim::Organization.create!( - name: ::Faker::Company.name, + name: Decidim::Faker::Localized.company, twitter_handler: ::Faker::Hipster.word, facebook_handler: ::Faker::Hipster.word, instagram_handler: ::Faker::Hipster.word, diff --git a/decidim-core/lib/decidim/core/test/factories.rb b/decidim-core/lib/decidim/core/test/factories.rb index e550c087aaa29..0c735187ea13c 100644 --- a/decidim-core/lib/decidim/core/test/factories.rb +++ b/decidim-core/lib/decidim/core/test/factories.rb @@ -112,7 +112,11 @@ def generate_localized_title(field = nil, skip_injection: false) create_static_pages { true } end - name { Faker::Company.unique.name } + # we do not want machine translation here + name do + Decidim.available_locales.index_with { |_locale| Faker::Company.unique.name } + end + reference_prefix { Faker::Name.suffix } time_zone { "UTC" } twitter_handler { Faker::Hipster.word } diff --git a/decidim-core/lib/decidim/core/test/shared_examples/logo_email.rb b/decidim-core/lib/decidim/core/test/shared_examples/logo_email.rb index 41ef089f78657..44739a5cb401c 100644 --- a/decidim-core/lib/decidim/core/test/shared_examples/logo_email.rb +++ b/decidim-core/lib/decidim/core/test/shared_examples/logo_email.rb @@ -5,7 +5,7 @@ shared_examples "email with logo" do context "when organization has a logo" do let(:organization_logo) { Decidim::Dev.test_file("city.jpeg", "image/jpeg") } - let(:organization) { create(:organization, name: "O'Higgins", logo: organization_logo) } + let(:organization) { create(:organization, name: { en: "O'Higgins" }, logo: organization_logo) } let(:mail) { described_class.event_received(event, event_class_name, resource, user, :follower, extra) } let(:logo_path) { Rails.application.routes.url_helpers.rails_representation_path(organization.logo.variant(resize_to_fit: [600, 160]), only_path: true) } diff --git a/decidim-core/lib/decidim/download_your_data_serializers/download_your_data_user_serializer.rb b/decidim-core/lib/decidim/download_your_data_serializers/download_your_data_user_serializer.rb index ec8048065db63..79552cc5da91d 100644 --- a/decidim-core/lib/decidim/download_your_data_serializers/download_your_data_user_serializer.rb +++ b/decidim-core/lib/decidim/download_your_data_serializers/download_your_data_user_serializer.rb @@ -5,6 +5,7 @@ module Decidim module DownloadYourDataSerializers class DownloadYourDataUserSerializer < Decidim::Exporters::Serializer include Decidim::ResourceHelper + include Decidim::TranslatableAttributes # Public: Exports a hash with the serialized data for this user. def serialize @@ -16,7 +17,7 @@ def serialize locale: resource.locale, organization: { id: resource.organization.try(:id), - name: resource.organization.try(:name) + name: translated_attribute(resource.organization.try(:name)) }, newsletter_notifications_at: resource.newsletter_notifications_at, notifications_sending_frequency: resource.notifications_sending_frequency, diff --git a/decidim-core/lib/decidim/events/simple_event.rb b/decidim-core/lib/decidim/events/simple_event.rb index a8e202dc6c591..c8f8b527f7f8c 100644 --- a/decidim-core/lib/decidim/events/simple_event.rb +++ b/decidim-core/lib/decidim/events/simple_event.rb @@ -11,6 +11,7 @@ class SimpleEvent < BaseEvent include Decidim::Events::EmailEvent include Decidim::Events::NotificationEvent include Decidim::ComponentPathHelper + include Decidim::OrganizationHelper delegate :created_at, to: :resource diff --git a/decidim-core/lib/tasks/decidim_metrics_tasks.rake b/decidim-core/lib/tasks/decidim_metrics_tasks.rake index e06d15ae901b5..b9c01d5398d31 100644 --- a/decidim-core/lib/tasks/decidim_metrics_tasks.rake +++ b/decidim-core/lib/tasks/decidim_metrics_tasks.rake @@ -47,10 +47,10 @@ namespace :decidim do Decidim::Organization.find_each do |organization| if metric m_manifest = Decidim.metrics_registry.for(metric) - log_info "[#{organization.name}]: rebuilding metric [#{metric}] for day [#{current_day}]" + log_info "[#{organization.name[organization.default_locale.to_s]}]: rebuilding metric [#{metric}] for day [#{current_day}]" call_metric_job(m_manifest, organization, current_day) else - log_info "[#{organization.name}]: rebuilding all metrics for day [#{current_day}]" + log_info "[#{organization.name[organization.default_locale.to_s]}]: rebuilding all metrics for day [#{current_day}]" Decidim.metrics_registry.all.each do |metric_manifest| call_metric_job(metric_manifest, organization, current_day) end diff --git a/decidim-core/spec/cells/decidim/content_blocks/hero_cell_spec.rb b/decidim-core/spec/cells/decidim/content_blocks/hero_cell_spec.rb index e8ce7e666f5a9..69dbe2da4a491 100644 --- a/decidim-core/spec/cells/decidim/content_blocks/hero_cell_spec.rb +++ b/decidim-core/spec/cells/decidim/content_blocks/hero_cell_spec.rb @@ -13,7 +13,7 @@ context "when the content block has no settings" do it "shows the default welcome text" do - expect(subject).to have_text("Welcome to #{organization.name}") + expect(subject).to have_text("Welcome to #{translated(organization.name)}") end end @@ -70,7 +70,7 @@ context "when organization is updated" do it "generates a different hash" do old_hash = cell(content_block.cell, content_block).send(:cache_hash) - controller.current_organization.update!(name: "New name") + controller.current_organization.update!(name: { en: "New name" }) controller.current_organization.reload expect(cell(content_block.cell, content_block).send(:cache_hash)).not_to eq(old_hash) diff --git a/decidim-core/spec/controllers/manifests_controller_spec.rb b/decidim-core/spec/controllers/manifests_controller_spec.rb index 56073c73bd9dc..fe78101fe4c55 100644 --- a/decidim-core/spec/controllers/manifests_controller_spec.rb +++ b/decidim-core/spec/controllers/manifests_controller_spec.rb @@ -6,7 +6,7 @@ module Decidim describe ManifestsController do routes { Decidim::Core::Engine.routes } - let(:organization) { create(:organization, name: "Organization's name") } + let(:organization) { create(:organization, name: { en: "Organization's name" }) } before do Decidim::Organization.destroy_all @@ -22,9 +22,9 @@ module Decidim expect(response).to be_successful manifest = JSON.parse(response.body) - expect(manifest["name"]).to eq(organization.name) + expect(manifest["name"]).to eq(translated(organization.name)) expect(manifest["lang"]).to eq(organization.default_locale) - expect(manifest["description"]).to eq(ActionView::Base.full_sanitizer.sanitize(organization.description["en"])) + expect(manifest["description"]).to eq(ActionView::Base.full_sanitizer.sanitize(translated(organization.description))) expect(manifest["background_color"]).to eq("#e02d2d") expect(manifest["theme_color"]).to eq("#e02d2d") expect(manifest["display"]).to eq("standalone") diff --git a/decidim-core/spec/events/decidim/welcome_notification_event_spec.rb b/decidim-core/spec/events/decidim/welcome_notification_event_spec.rb index eebb888f39a89..07af83f29aa08 100644 --- a/decidim-core/spec/events/decidim/welcome_notification_event_spec.rb +++ b/decidim-core/spec/events/decidim/welcome_notification_event_spec.rb @@ -17,7 +17,7 @@ let(:organization) { create(:organization, name: organization_name) } context "with a normal organization name" do - let(:organization_name) { "My Organization" } + let(:organization_name) { { ca: "", en: "My Organization", es: "" } } describe "#email_subject" do subject { event_instance.email_subject } @@ -33,7 +33,7 @@ end context "with an organization with an apostrophe" do - let(:organization_name) { "My ol'Organization" } + let(:organization_name) { { ca: "", en: "My ol'Organization", es: "" } } describe "#email_subject" do subject { event_instance.email_subject } diff --git a/decidim-core/spec/lib/download_your_data_serializers/download_your_data_user_serializer_spec.rb b/decidim-core/spec/lib/download_your_data_serializers/download_your_data_user_serializer_spec.rb index cfe6021832a27..e1238d4b0e936 100644 --- a/decidim-core/spec/lib/download_your_data_serializers/download_your_data_user_serializer_spec.rb +++ b/decidim-core/spec/lib/download_your_data_serializers/download_your_data_user_serializer_spec.rb @@ -35,7 +35,7 @@ module Decidim include(id: resource.organization.id) ) expect(serialized[:organization]).to( - include(name: resource.organization.name) + include(name: translated(resource.organization.name)) ) end diff --git a/decidim-core/spec/lib/events/email_event_spec.rb b/decidim-core/spec/lib/events/email_event_spec.rb index ee96c19c4c8c7..37911ccbf1017 100644 --- a/decidim-core/spec/lib/events/email_event_spec.rb +++ b/decidim-core/spec/lib/events/email_event_spec.rb @@ -21,7 +21,7 @@ class TestEvent < Decidim::Events::BaseEvent TestEvent.new(resource:, event_name: "test", user:) end - let(:organization) { create(:organization, name: "O'Connor") } + let(:organization) { create(:organization, name: { en: "O'Connor" }) } let(:user) { create(:user, name: "Sarah Connor", organization:) } let(:resource) { user } diff --git a/decidim-core/spec/lib/query_extensions_spec.rb b/decidim-core/spec/lib/query_extensions_spec.rb index aa0c1d5fe21c0..b3735bf2c7997 100644 --- a/decidim-core/spec/lib/query_extensions_spec.rb +++ b/decidim-core/spec/lib/query_extensions_spec.rb @@ -40,10 +40,10 @@ module Core end describe "organization" do - let(:query) { %({ organization { name }}) } + let(:query) { %({ organization { name { translation(locale: "en") } }}) } it "returns the current organization" do - expect(response["organization"]["name"]).to eq(current_organization.name.to_s) + expect(response["organization"]["name"]["translation"]).to eq(translated(current_organization.name)) end end diff --git a/decidim-core/spec/lib/welcome_notification_event_spec.rb b/decidim-core/spec/lib/welcome_notification_event_spec.rb index c2008ae97c650..63232c52b0fdb 100644 --- a/decidim-core/spec/lib/welcome_notification_event_spec.rb +++ b/decidim-core/spec/lib/welcome_notification_event_spec.rb @@ -6,7 +6,7 @@ module Decidim describe WelcomeNotificationEvent do subject { described_class.new(resource: user, event_name: "test", user:) } let(:user) { create(:user, organization:, name: "James") } - let(:organization) { create(:organization, name: "Awesome Town") } + let(:organization) { create(:organization, name: { en: "Awesome Town" }) } describe "subject" do it "has a default" do @@ -49,7 +49,7 @@ module Decidim end context "when the organization has customized the default welcome message" do - let(:organization) { create(:organization, name: "Awesome Town", welcome_notification_subject:, welcome_notification_body:) } + let(:organization) { create(:organization, name: { en: "Awesome Town" }, welcome_notification_subject:, welcome_notification_body:) } let(:welcome_notification_subject) do { en: "Well hello {{name}}" } end diff --git a/decidim-core/spec/mailers/application_mailer_spec.rb b/decidim-core/spec/mailers/application_mailer_spec.rb index 54349ad59f732..e2c850523951a 100644 --- a/decidim-core/spec/mailers/application_mailer_spec.rb +++ b/decidim-core/spec/mailers/application_mailer_spec.rb @@ -6,7 +6,7 @@ module Decidim describe Decidim::Dev::DummyResourceMailer do describe "smtp_settings" do let(:user) { create(:user, organization:) } - let(:organization) { create(:organization, name: "My Organization", smtp_settings:) } + let(:organization) { create(:organization, name: { en: "My Organization" }, smtp_settings:) } let(:smtp_settings) do { "address" => "mail.example.org", diff --git a/decidim-core/spec/mailers/block_user_mailer_spec.rb b/decidim-core/spec/mailers/block_user_mailer_spec.rb index f9f9133a4a7d7..05c042e27c863 100644 --- a/decidim-core/spec/mailers/block_user_mailer_spec.rb +++ b/decidim-core/spec/mailers/block_user_mailer_spec.rb @@ -14,7 +14,7 @@ module Decidim let(:mail) { described_class.notify(user, token) } it "parses the subject" do - expect(mail.subject).to eq("Your account was blocked by #{organization.name}") + expect(mail.subject).to eq("Your account was blocked by #{translated_attribute(organization.name)}") end it "parses the body" do diff --git a/decidim-core/spec/mailers/decidim_devise_mailer_spec.rb b/decidim-core/spec/mailers/decidim_devise_mailer_spec.rb index 330d0b64a5db6..9f1de622e9fc9 100644 --- a/decidim-core/spec/mailers/decidim_devise_mailer_spec.rb +++ b/decidim-core/spec/mailers/decidim_devise_mailer_spec.rb @@ -43,9 +43,13 @@ module Decidim described_class.invitation_instructions(user, "foo", invitation_instructions: "organization_admin_invitation_instructions") end - let(:mail_subject) { "T'han convidat a administrar #{user.organization.name}" } + let(:mail_subject) do + I18n.with_locale(locale) do + "T'han convidat a administrar #{translated_attribute(user.organization.name)}" + end + end let(:body) { "Acceptar invitaci" } - let(:default_subject) { "You have been invited to manage #{user.organization.name}" } + let(:default_subject) { "You have been invited to manage #{translated_attribute(user.organization.name)}" } let(:default_body) { "Accept invitation" } include_examples "localised email" diff --git a/decidim-core/spec/mailers/messaging/conversation_mailer_spec.rb b/decidim-core/spec/mailers/messaging/conversation_mailer_spec.rb index 2a896ac199c51..ffa1b548d4b20 100644 --- a/decidim-core/spec/mailers/messaging/conversation_mailer_spec.rb +++ b/decidim-core/spec/mailers/messaging/conversation_mailer_spec.rb @@ -25,7 +25,7 @@ module Messaging end it "includes the organization data" do - expect(subject.body).to include(user.organization.name) + expect(subject.body).to include(translated(user.organization.name)) end it "includes the message" do diff --git a/decidim-core/spec/mailers/newsletters_opt_in_mailer_spec.rb b/decidim-core/spec/mailers/newsletters_opt_in_mailer_spec.rb index 5d6c47fd16ec7..cd1087ef47f86 100644 --- a/decidim-core/spec/mailers/newsletters_opt_in_mailer_spec.rb +++ b/decidim-core/spec/mailers/newsletters_opt_in_mailer_spec.rb @@ -13,7 +13,7 @@ module Decidim let(:mail) { described_class.notify(user, token) } it "parses the subject" do - expect(mail.subject).to eq("Do you want to keep receiving relevant information about #{organization.name}?") + expect(mail.subject).to eq("Do you want to keep receiving relevant information about #{translated(organization.name)}?") end it "parses the body" do diff --git a/decidim-core/spec/mailers/notification_digest_mailer_spec.rb b/decidim-core/spec/mailers/notification_digest_mailer_spec.rb index a629c18815aa2..7f36293e4bcc9 100644 --- a/decidim-core/spec/mailers/notification_digest_mailer_spec.rb +++ b/decidim-core/spec/mailers/notification_digest_mailer_spec.rb @@ -4,7 +4,7 @@ module Decidim describe NotificationsDigestMailer do - let(:organization) { create(:organization, name: "O'Connor") } + let(:organization) { create(:organization) } let(:user) { create(:user, name: "Sarah Connor", organization:) } let(:notification_ids) { [notification.id] } let(:notification) { create(:notification, user:, resource:) } diff --git a/decidim-core/spec/mailers/notification_mailer_spec.rb b/decidim-core/spec/mailers/notification_mailer_spec.rb index d4d8f51026c6a..d3cd353dff9f3 100644 --- a/decidim-core/spec/mailers/notification_mailer_spec.rb +++ b/decidim-core/spec/mailers/notification_mailer_spec.rb @@ -4,7 +4,7 @@ module Decidim describe NotificationMailer do - let(:organization) { create(:organization, name: "O'Connor") } + let(:organization) { create(:organization, name: { en: "O'Connor" }) } let(:user) { create(:user, name: "Sarah Connor", organization:) } let(:resource) { user } let(:event_class_name) { "Decidim::ProfileUpdatedEvent" } @@ -26,7 +26,7 @@ module Decidim end it "includes the organization data" do - expect(mail.body.encoded).to include(user.organization.name) + expect(mail.body.encoded).to include(decidim_escape_translated(user.organization.name)) end it "includes the greeting" do diff --git a/decidim-core/spec/mailers/reported_mailer_spec.rb b/decidim-core/spec/mailers/reported_mailer_spec.rb index 3fe1c1ab3a619..642e46b8a5df5 100644 --- a/decidim-core/spec/mailers/reported_mailer_spec.rb +++ b/decidim-core/spec/mailers/reported_mailer_spec.rb @@ -4,7 +4,7 @@ module Decidim describe ReportedMailer do - let(:organization) { create(:organization, name: "Test Organization") } + let(:organization) { create(:organization) } let(:user) { create(:user, :admin, organization:) } let(:component) { create(:component, organization:) } let(:reportable) { create(:proposal, title: Decidim::Faker::Localized.sentence, body: Decidim::Faker::Localized.paragraph(sentence_count: 3)) } @@ -14,7 +14,11 @@ module Decidim let(:decidim) { Decidim::Core::Engine.routes.url_helpers } before do - reportable.coauthorships.first.author.update!(name: "O'Higgins") + if reportable.coauthorships.first.author.is_a?(Decidim::Organization) + reportable.coauthorships.first.author.update!(name: { en: "O'Higgins" }) + else + reportable.coauthorships.first.author.update!(name: "O'Higgins") + end end describe "#report" do diff --git a/decidim-core/spec/mailers/user_report_mailer_spec.rb b/decidim-core/spec/mailers/user_report_mailer_spec.rb index 1a0a2dd2afa86..2b0d590eb6e82 100644 --- a/decidim-core/spec/mailers/user_report_mailer_spec.rb +++ b/decidim-core/spec/mailers/user_report_mailer_spec.rb @@ -4,7 +4,7 @@ module Decidim describe UserReportMailer do - let(:organization) { create(:organization, name: "Test Organization") } + let(:organization) { create(:organization, name: { en: "Test Organization" }) } let(:admin) { create(:user, :admin, organization:) } let(:reporter) { create(:user, :confirmed, organization:) } let(:moderation) { create(:user_moderation, user:) } diff --git a/decidim-core/spec/mailers/user_update_mailer_spec.rb b/decidim-core/spec/mailers/user_update_mailer_spec.rb index 969c83aa593b3..205e589087aa6 100644 --- a/decidim-core/spec/mailers/user_update_mailer_spec.rb +++ b/decidim-core/spec/mailers/user_update_mailer_spec.rb @@ -4,7 +4,7 @@ module Decidim describe UserUpdateMailer do - let(:organization) { create(:organization, name: "Test Organization") } + let(:organization) { create(:organization, name: { ca: "", en: "Test Organization", es: "" }) } let(:user) { create(:user, :confirmed, organization:) } let(:updates) { %w(field1 field2 field3) } diff --git a/decidim-core/spec/models/decidim/organization_spec.rb b/decidim-core/spec/models/decidim/organization_spec.rb index f5b5c4a30649a..b5d70015c46aa 100644 --- a/decidim-core/spec/models/decidim/organization_spec.rb +++ b/decidim-core/spec/models/decidim/organization_spec.rb @@ -56,6 +56,33 @@ module Decidim subject.default_locale = :en expect(subject).not_to be_valid end + + describe "name" do + context "when name does not exists" do + it "is valid" do + expect(described_class.count).to eq(0) + expect(subject).to be_valid + end + end + + context "when name exists for same locale" do + let!(:dummy_organization) { create(:organization, name: { en: "Dummy Random 22" }) } + + it "is invalid" do + subject.name = { en: "Dummy Random 22" } + expect(subject).not_to be_valid + end + end + + context "when name exists for different locale" do + let!(:dummy_organization) { create(:organization, name: { ca: "Dummy Random 22", en: "Dummy" }) } + + it "is invalid" do + subject.name = { en: "Dummy Random 22" } + expect(subject).not_to be_valid + end + end + end end describe "enabled omniauth providers" do diff --git a/decidim-core/spec/models/decidim/user_spec.rb b/decidim-core/spec/models/decidim/user_spec.rb index d5106fea277f3..b5f262c9ee02a 100644 --- a/decidim-core/spec/models/decidim/user_spec.rb +++ b/decidim-core/spec/models/decidim/user_spec.rb @@ -328,7 +328,7 @@ module Decidim it "sends the email" do expect(last_email.to).to eq([user.email]) - expect(last_email.subject).to eq("Thanks for joining #{organization.name}!") + expect(last_email.subject).to eq("Thanks for joining #{translated(organization.name)}!") end context "when the organization does not send welcome notifications" do diff --git a/decidim-core/spec/presenters/decidim/organization_presenter_spec.rb b/decidim-core/spec/presenters/decidim/organization_presenter_spec.rb index f38a3f7bbe829..e49025934bb7d 100644 --- a/decidim-core/spec/presenters/decidim/organization_presenter_spec.rb +++ b/decidim-core/spec/presenters/decidim/organization_presenter_spec.rb @@ -5,7 +5,7 @@ module Decidim describe OrganizationPresenter, type: :helper do let(:description) { { "en" => "

    A necessitatibus quo. 1

    " } } - let(:organization) { create(:organization, name: "Organization's name", description:) } + let(:organization) { create(:organization, name: { en: "Organization's name" }, description:) } subject { described_class.new(organization) } diff --git a/decidim-core/spec/system/accesslist_spec.rb b/decidim-core/spec/system/accesslist_spec.rb index 20d52e999ff86..d2adeba37e1f8 100644 --- a/decidim-core/spec/system/accesslist_spec.rb +++ b/decidim-core/spec/system/accesslist_spec.rb @@ -15,7 +15,7 @@ it "allows access to participants side" do visit decidim.root_path - expect(page).to have_content(organization.name) + expect(page).to have_content(translated(organization.name)) end it "allows access to admin side page" do @@ -32,7 +32,7 @@ it "allows access to participants side" do visit decidim.root_path - expect(page).to have_content(organization.name) + expect(page).to have_content(translated(organization.name)) end it "allows access to admin side page" do diff --git a/decidim-core/spec/system/authentication_spec.rb b/decidim-core/spec/system/authentication_spec.rb index dbdb3b621f8df..67b5f724ee5f3 100644 --- a/decidim-core/spec/system/authentication_spec.rb +++ b/decidim-core/spec/system/authentication_spec.rb @@ -286,10 +286,10 @@ end within "#notifications" do - expect(page).to have_content("thanks for joining #{organization.name}") + expect(page).to have_content("thanks for joining #{translated(organization.name)}") end - expect(last_email_body).to include("thanks for joining #{organization.name}") + expect(last_email_body).to include("thanks for joining #{translated(organization.name)}") end end diff --git a/decidim-core/spec/system/homepage_spec.rb b/decidim-core/spec/system/homepage_spec.rb index 1f2166afd2ce8..d1efee0eae42e 100644 --- a/decidim-core/spec/system/homepage_spec.rb +++ b/decidim-core/spec/system/homepage_spec.rb @@ -148,7 +148,7 @@ end it "welcomes the user" do - expect(page).to have_content(organization.name) + expect(page).to have_content(translated(organization.name)) end context "when there are static pages" do @@ -179,7 +179,7 @@ expect(page).to have_css("#footer_sub_hero") within "#footer_sub_hero" do - expect(page).to have_content(organization.name) + expect(page).to have_content(translated(organization.name)) end end @@ -349,7 +349,7 @@ let(:organization) { create(:organization) } it "does not show the statistics block" do - expect(page).to have_no_content("Current state of #{organization.name}") + expect(page).to have_no_content("Current state of #{translated(organization.name)}") end end @@ -363,7 +363,7 @@ it "shows the statistics block" do within "#statistics" do - expect(page).to have_content("Current state of #{organization.name}") + expect(page).to have_content("Current state of #{translated(organization.name)}") expect(page).to have_content("Processes") expect(page).to have_content("Participants") end diff --git a/decidim-core/spec/system/static_pages_spec.rb b/decidim-core/spec/system/static_pages_spec.rb index 77440b8e44cf0..6f58fbb8d6cab 100644 --- a/decidim-core/spec/system/static_pages_spec.rb +++ b/decidim-core/spec/system/static_pages_spec.rb @@ -108,7 +108,7 @@ # ActionDispatch::Cookies::CookieOverflow exception visit "#{decidim.pages_path}?#{long_parameters}" - expect(page).to have_content(organization.name) + expect(page).to have_content(translated(organization.name)) end end diff --git a/decidim-core/spec/types/organization_spec.rb b/decidim-core/spec/types/organization_spec.rb index ea6a124a9d5b5..c2db84947cec7 100644 --- a/decidim-core/spec/types/organization_spec.rb +++ b/decidim-core/spec/types/organization_spec.rb @@ -13,7 +13,7 @@ %( query { organization{ - name + name { translation(locale: "#{locale}") } stats{ name value @@ -29,7 +29,7 @@ end it "has name" do - expect(response["organization"]["name"]).to eq(current_organization.name) + expect(response["organization"]["name"]["translation"]).to eq(translated(current_organization.name)) end %w( diff --git a/decidim-core/spec/types/organization_type_spec.rb b/decidim-core/spec/types/organization_type_spec.rb index 8fe65df1b254c..ce682fffff284 100644 --- a/decidim-core/spec/types/organization_type_spec.rb +++ b/decidim-core/spec/types/organization_type_spec.rb @@ -15,10 +15,10 @@ module Core end describe "name" do - let(:query) { "{ name }" } + let(:query) { %({ name { translation(locale: "en") }}) } it "returns the organization's name" do - expect(response).to eq("name" => model.name) + expect(response["name"]["translation"]).to eq(translated(model.name)) end end diff --git a/decidim-core/spec/types/user_group_type_spec.rb b/decidim-core/spec/types/user_group_type_spec.rb index 72e2f06ed4217..a54a4f61972d4 100644 --- a/decidim-core/spec/types/user_group_type_spec.rb +++ b/decidim-core/spec/types/user_group_type_spec.rb @@ -71,10 +71,10 @@ module Core end describe "organizationName" do - let(:query) { "{ organizationName }" } + let(:query) { '{ organizationName { translation(locale: "en") } } ' } it "returns the group's organization name" do - expect(response).to include("organizationName" => model.organization.name) + expect(response["organizationName"]["translation"]).to eq(translated(model.organization.name)) end end diff --git a/decidim-core/spec/types/user_type_spec.rb b/decidim-core/spec/types/user_type_spec.rb index 60354fde067e1..79613a22a8c27 100644 --- a/decidim-core/spec/types/user_type_spec.rb +++ b/decidim-core/spec/types/user_type_spec.rb @@ -87,10 +87,10 @@ module Core end describe "organizationName" do - let(:query) { "{ organizationName }" } + let(:query) { '{ organizationName { translation(locale: "en") } } ' } it "returns the user's organization name" do - expect(response).to include("organizationName" => model.organization.name) + expect(response["organizationName"]["translation"]).to eq(translated(model.organization.name)) end end diff --git a/decidim-debates/app/models/decidim/debates/debate.rb b/decidim-debates/app/models/decidim/debates/debate.rb index 92db7e43f7653..99478aba824c2 100644 --- a/decidim-debates/app/models/decidim/debates/debate.rb +++ b/decidim-debates/app/models/decidim/debates/debate.rb @@ -80,7 +80,7 @@ def reported_attributes # Public: Overrides the `reported_searchable_content_extras` Reportable concern method. def reported_searchable_content_extras - [normalized_author.name] + [author_name] end # Public: Calculates whether the current debate is an AMA-styled one or not. diff --git a/decidim-initiatives/app/views/decidim/initiatives/initiatives/print.html.erb b/decidim-initiatives/app/views/decidim/initiatives/initiatives/print.html.erb index d636983fe9d3d..3248134129874 100644 --- a/decidim-initiatives/app/views/decidim/initiatives/initiatives/print.html.erb +++ b/decidim-initiatives/app/views/decidim/initiatives/initiatives/print.html.erb @@ -2,10 +2,10 @@
    <% if current_organization.logo.present? %> - <%= image_tag current_organization.attached_uploader(:logo).path(variant: :medium), title: current_organization.name %> + <%= image_tag current_organization.attached_uploader(:logo).path(variant: :medium), title: current_organization_name %> <% end %> - <%= current_organization.name %> + <%= current_organization_name %>
    diff --git a/decidim-meetings/app/models/decidim/meetings/meeting.rb b/decidim-meetings/app/models/decidim/meetings/meeting.rb index eea2f507fa4e1..22001216f0405 100644 --- a/decidim-meetings/app/models/decidim/meetings/meeting.rb +++ b/decidim-meetings/app/models/decidim/meetings/meeting.rb @@ -325,7 +325,7 @@ def reported_attributes # Public: Overrides the `reported_searchable_content_extras` Reportable concern method. def reported_searchable_content_extras - [normalized_author.name] + [author_name] end def has_contributions? diff --git a/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb b/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb index ae49ad0c6a892..7bd4b3bdcec45 100644 --- a/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb +++ b/decidim-meetings/app/views/decidim/meetings/admin/invite_join_meeting_mailer/invite.html.erb @@ -1,7 +1,9 @@
    <%= form.text_field :registration_url, help_text: t(".registration_url_help") %> - <%= cell("decidim/announcement", t(".disclaimer", organization: current_component.organization.name), callout_class: "alert" ) %> + <%= cell("decidim/announcement", t(".disclaimer", organization: organization_name(current_component.organization)), callout_class: "alert" ) %>
    diff --git a/decidim-meetings/app/views/decidim/meetings/close_meeting_reminder_mailer/close_meeting_reminder.html.erb b/decidim-meetings/app/views/decidim/meetings/close_meeting_reminder_mailer/close_meeting_reminder.html.erb index 78a55efd46fbe..1929bdb3b80dc 100644 --- a/decidim-meetings/app/views/decidim/meetings/close_meeting_reminder_mailer/close_meeting_reminder.html.erb +++ b/decidim-meetings/app/views/decidim/meetings/close_meeting_reminder_mailer/close_meeting_reminder.html.erb @@ -2,4 +2,4 @@ - + diff --git a/decidim-meetings/app/views/decidim/meetings/layouts/live_event.html.erb b/decidim-meetings/app/views/decidim/meetings/layouts/live_event.html.erb index 87d100aa61835..3fdfdd81ef623 100644 --- a/decidim-meetings/app/views/decidim/meetings/layouts/live_event.html.erb +++ b/decidim-meetings/app/views/decidim/meetings/layouts/live_event.html.erb @@ -27,7 +27,7 @@ <% end %>
    - <%= current_organization.name %> / <%= present(meeting).title(links: true, html_escape: true ) %> + <%= current_organization_name %> / <%= present(meeting).title(links: true, html_escape: true ) %>
    diff --git a/decidim-meetings/app/views/decidim/meetings/meetings/_form.html.erb b/decidim-meetings/app/views/decidim/meetings/meetings/_form.html.erb index 4668b9d53cb93..353c3199a9f48 100644 --- a/decidim-meetings/app/views/decidim/meetings/meetings/_form.html.erb +++ b/decidim-meetings/app/views/decidim/meetings/meetings/_form.html.erb @@ -80,7 +80,7 @@
    <%= form.text_field :registration_url, help_text: t(".registration_url_help") %> -
    +
    diff --git a/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb b/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb index 78a4967549fee..795f1f4ec78ff 100644 --- a/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb +++ b/decidim-meetings/app/views/devise/mailer/join_meeting.html.erb @@ -1,7 +1,9 @@ diff --git a/decidim-meetings/app/views/devise/mailer/join_meeting.text.erb b/decidim-meetings/app/views/devise/mailer/join_meeting.text.erb index 541ba5126a0bd..94fc66f3a388e 100644 --- a/decidim-meetings/app/views/devise/mailer/join_meeting.text.erb +++ b/decidim-meetings/app/views/devise/mailer/join_meeting.text.erb @@ -1,6 +1,8 @@ <%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %> -<%= t("decidim.meetings.admin.invite_join_meeting_mailer.invite.invited_you_to_join_a_meeting", invited_by: @resource.invited_by.name, application: @resource.organization.name) %> +<%= t("decidim.meetings.admin.invite_join_meeting_mailer.invite.invited_you_to_join_a_meeting", + invited_by: @resource.invited_by.name, + application: translated_attribute(@resource.organization.name)) %> <%= t("devise.mailer.invitation_instructions.decline") %>: <% accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:meeting].component).decline_invitation_meeting_registration_path(meeting_id: @opts[:meeting], participatory_space_id: @opts[:meeting].component.participatory_space), host: @resource.organization.host) %> diff --git a/decidim-participatory_processes/spec/system/participatory_processes_spec.rb b/decidim-participatory_processes/spec/system/participatory_processes_spec.rb index 9685d6f6ec776..15dc2d9879903 100644 --- a/decidim-participatory_processes/spec/system/participatory_processes_spec.rb +++ b/decidim-participatory_processes/spec/system/participatory_processes_spec.rb @@ -220,7 +220,7 @@ it "has the participatory process title in the show page" do visit decidim_participatory_processes.participatory_process_path(participatory_process) - expect(page).to have_title("#{translated(participatory_process.title)} - #{organization.name}") + expect(page).to have_title("#{translated(participatory_process.title)} - #{translated(organization.name)}") end end diff --git a/decidim-proposals/lib/decidim/api/proposal_type.rb b/decidim-proposals/lib/decidim/api/proposal_type.rb index 89b7c42e1358d..ef84dc1a261f6 100644 --- a/decidim-proposals/lib/decidim/api/proposal_type.rb +++ b/decidim-proposals/lib/decidim/api/proposal_type.rb @@ -26,6 +26,7 @@ class ProposalType < Decidim::Api::Types::BaseObject def coordinates [object.latitude, object.longitude] end + field :reference, GraphQL::Types::String, "This proposal's unique reference", null: true field :state, GraphQL::Types::String, "The answer status in which proposal is in", null: true field :answer, Decidim::Core::TranslatedFieldType, "The answer feedback for the status for this proposal", null: true diff --git a/decidim-proposals/spec/types/integration_schema_spec.rb b/decidim-proposals/spec/types/integration_schema_spec.rb index 3e08c4ba2ece0..18393a7a2a752 100644 --- a/decidim-proposals/spec/types/integration_schema_spec.rb +++ b/decidim-proposals/spec/types/integration_schema_spec.rb @@ -46,7 +46,7 @@ "id" => e.author.id.to_s, "name" => e.author.name, "nickname" => "@#{e.author.nickname}", - "organizationName" => e.author.organization.name, + "organizationName" => { "translation" => translated(e.author.organization.name) }, "profilePath" => "/profiles/#{e.author.nickname}" } end, "endorsementsCount" => proposal.endorsements.size, @@ -144,7 +144,7 @@ deleted name nickname - organizationName + organizationName { translation(locale: "en") } profilePath } endorsementsCount @@ -249,7 +249,7 @@ deleted name nickname - organizationName + organizationName { translation(locale: "en") } profilePath } endorsementsCount diff --git a/decidim-system/app/commands/decidim/system/populate_help.rb b/decidim-system/app/commands/decidim/system/populate_help.rb index 12d2a931e7c89..6d4473e22ed03 100644 --- a/decidim-system/app/commands/decidim/system/populate_help.rb +++ b/decidim-system/app/commands/decidim/system/populate_help.rb @@ -4,6 +4,8 @@ module Decidim module System # A command that will create default help pages for an organization. class PopulateHelp < Decidim::Command + include Decidim::TranslatableAttributes + # Public: Initializes the command. # # organization - An organization @@ -17,8 +19,8 @@ def initialize(organization) def call ActiveRecord::Base.transaction do topic = Decidim::StaticPageTopic.create!( - title: multi_translation("decidim.help.main_topic.title", organization: @organization.name), - description: multi_translation("decidim.help.main_topic.description", organization: @organization.name), + title: multi_translation("decidim.help.main_topic.title", organization: organization_name), + description: multi_translation("decidim.help.main_topic.description", organization: organization_name), organization: @organization, show_in_footer: true, weight: 0 @@ -26,8 +28,8 @@ def call Decidim::StaticPage.create!( slug: "help", - title: multi_translation("decidim.help.main_topic.default_page.title", organization: @organization.name), - content: multi_translation("decidim.help.main_topic.default_page.content", organization: @organization.name), + title: multi_translation("decidim.help.main_topic.default_page.title", organization: organization_name), + content: multi_translation("decidim.help.main_topic.default_page.content", organization: organization_name), topic:, organization: @organization, weight: 0 @@ -53,6 +55,10 @@ def call def multi_translation(key, **) Decidim::TranslationsHelper.multi_translation(key, @organization.available_locales, **) end + + def organization_name + translated_attribute(@organization.name) + end end end end diff --git a/decidim-system/app/commands/decidim/system/register_organization.rb b/decidim-system/app/commands/decidim/system/register_organization.rb index 0621309436ba6..82daac9d90543 100644 --- a/decidim-system/app/commands/decidim/system/register_organization.rb +++ b/decidim-system/app/commands/decidim/system/register_organization.rb @@ -49,7 +49,7 @@ def call def create_organization Decidim::Organization.create!( - name: form.name, + name: { form.default_locale => form.name }, host: form.host, secondary_hosts: form.clean_secondary_hosts, reference_prefix: form.reference_prefix, diff --git a/decidim-system/app/controllers/decidim/system/organizations_controller.rb b/decidim-system/app/controllers/decidim/system/organizations_controller.rb index 7c98a238b0664..183d5dac8bbdb 100644 --- a/decidim-system/app/controllers/decidim/system/organizations_controller.rb +++ b/decidim-system/app/controllers/decidim/system/organizations_controller.rb @@ -39,6 +39,7 @@ def edit end def update + @organization = Organization.find(params[:id]) @form = form(UpdateOrganizationForm).from_params(params) UpdateOrganization.call(params[:id], @form) do diff --git a/decidim-system/app/forms/decidim/system/base_organization_form.rb b/decidim-system/app/forms/decidim/system/base_organization_form.rb new file mode 100644 index 0000000000000..34c71ea4cab24 --- /dev/null +++ b/decidim-system/app/forms/decidim/system/base_organization_form.rb @@ -0,0 +1,123 @@ +# frozen_string_literal: true + +require "decidim/translatable_attributes" + +module Decidim + module System + # A form object to be inherited to create and update organizations from the system dashboard. + # + class BaseOrganizationForm < Form + include TranslatableAttributes + include JsonbAttributes + + mimic :organization + + attribute :host, String + attribute :secondary_hosts, String + attribute :force_users_to_authenticate_before_access_organization, Boolean + attribute :available_authorizations, Array[String] + attribute :users_registration_mode, String + attribute :default_locale, String + + jsonb_attribute :smtp_settings, [ + [:from, String], + [:from_email, String], + [:from_label, String], + [:user_name, String], + [:encrypted_password, String], + [:address, String], + [:port, Integer], + [:authentication, String], + [:enable_starttls_auto, Boolean] + ] + + jsonb_attribute :content_security_policy, [ + [:"default-src", String], + [:"img-src", String], + [:"media-src", String], + [:"script-src", String], + [:"style-src", String], + [:"frame-src", String], + [:"font-src", String], + [:"connect-src", String] + ] + + attribute :password, String + attribute :file_upload_settings, FileUploadSettingsForm + + OMNIATH_PROVIDERS_ATTRIBUTES = Decidim::OmniauthProvider.available.keys.map do |provider| + Rails.application.secrets.dig(:omniauth, provider).keys.map do |setting| + if setting == :enabled + ["omniauth_settings_#{provider}_enabled".to_sym, Boolean] + else + ["omniauth_settings_#{provider}_#{setting}".to_sym, String] + end + end + end.flatten(1) + + jsonb_attribute :omniauth_settings, OMNIATH_PROVIDERS_ATTRIBUTES + + validates :host, :users_registration_mode, presence: true + validate :validate_organization_uniqueness + validate :validate_secret_key_base_for_encryption + validates :users_registration_mode, inclusion: { in: Decidim::Organization.users_registration_modes } + + def map_model(model) + self.default_locale = model.default_locale + self.secondary_hosts = model.secondary_hosts.join("\n") + self.omniauth_settings = (model.omniauth_settings || {}).transform_values do |v| + Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.decrypt(v) : v + end + self.file_upload_settings = FileUploadSettingsForm.from_model(model.file_upload_settings) + end + + def clean_secondary_hosts + return unless secondary_hosts + + secondary_hosts.split("\n").map(&:chomp).select(&:present?) + end + + def clean_available_authorizations + return unless available_authorizations + + available_authorizations.select(&:present?) + end + + def password + encrypted_password.nil? ? super : Decidim::AttributeEncryptor.decrypt(encrypted_password) + end + + def encrypted_smtp_settings + smtp_settings["from"] = set_from + + smtp_settings.merge(encrypted_password: Decidim::AttributeEncryptor.encrypt(password)) + end + + def set_from + return from_email if from_label.blank? + + "#{from_label} <#{from_email}>" + end + + def encrypted_omniauth_settings + omniauth_settings.transform_values do |v| + Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.encrypt(v) : v + end + end + + private + + # We need a valid secret key base for encrypting the SMTP password with it + # It is also necessary for other things in Rails (like Cookies encryption) + def validate_secret_key_base_for_encryption + return if Rails.application.secrets.secret_key_base&.length == 128 + + errors.add(:password, I18n.t("activemodel.errors.models.organization.attributes.password.secret_key")) + end + + def validate_organization_uniqueness + raise "#{self.class.name} is expected to implement #validate_organization_uniqueness" + end + end + end +end diff --git a/decidim-system/app/forms/decidim/system/register_organization_form.rb b/decidim-system/app/forms/decidim/system/register_organization_form.rb index 5f36993ed7eee..169a34db7ad8f 100644 --- a/decidim-system/app/forms/decidim/system/register_organization_form.rb +++ b/decidim-system/app/forms/decidim/system/register_organization_form.rb @@ -6,10 +6,12 @@ module Decidim module System # A form object used to create organizations from the system dashboard. # - class RegisterOrganizationForm < UpdateOrganizationForm + class RegisterOrganizationForm < BaseOrganizationForm include JsonbAttributes mimic :organization + attribute :name, String + attribute :organization_admin_email, String attribute :organization_admin_name, String attribute :available_locales, Array @@ -18,11 +20,29 @@ class RegisterOrganizationForm < UpdateOrganizationForm attribute :users_registration_mode, String attribute :force_users_to_authenticate_before_access_organization, Boolean - validates :organization_admin_email, :organization_admin_name, :name, :host, :reference_prefix, :users_registration_mode, presence: true + validates :organization_admin_email, :organization_admin_name, :name, :reference_prefix, presence: true + validates :name, presence: true validates :available_locales, presence: true validates :default_locale, presence: true validates :default_locale, inclusion: { in: :available_locales } - validates :users_registration_mode, inclusion: { in: Decidim::Organization.users_registration_modes } + + private + + def validate_organization_uniqueness + base_query = Decidim::Organization.pluck(:name) + + organization_names = [] + + base_query.each do |value| + organization_names += value.except("machine_translations").values + organization_names += value.fetch("machine_translations", {}).values + end + + organization_names = organization_names.map(&:downcase) + + errors.add(:name, :taken) if organization_names.include?(name&.downcase) + errors.add(:host, :taken) if Decidim::Organization.where(host:).where.not(id:).exists? + end end end end diff --git a/decidim-system/app/forms/decidim/system/update_organization_form.rb b/decidim-system/app/forms/decidim/system/update_organization_form.rb index 710a3472f5ab7..437a86fdb6d12 100644 --- a/decidim-system/app/forms/decidim/system/update_organization_form.rb +++ b/decidim-system/app/forms/decidim/system/update_organization_form.rb @@ -6,117 +6,38 @@ module Decidim module System # A form object used to update organizations from the system dashboard. # - class UpdateOrganizationForm < Form - include TranslatableAttributes - include JsonbAttributes + class UpdateOrganizationForm < BaseOrganizationForm + translatable_attribute :name, String - mimic :organization + validate :validate_organization_name_presence - attribute :name, String - attribute :host, String - attribute :secondary_hosts, String - attribute :force_users_to_authenticate_before_access_organization, Boolean - attribute :available_authorizations, Array[String] - attribute :users_registration_mode, String - jsonb_attribute :smtp_settings, [ - [:from, String], - [:from_email, String], - [:from_label, String], - [:user_name, String], - [:encrypted_password, String], - [:address, String], - [:port, Integer], - [:authentication, String], - [:enable_starttls_auto, Boolean] - ] - - jsonb_attribute :content_security_policy, [ - [:"default-src", String], - [:"img-src", String], - [:"media-src", String], - [:"script-src", String], - [:"style-src", String], - [:"frame-src", String], - [:"font-src", String], - [:"connect-src", String] - ] - - attribute :password, String - attribute :file_upload_settings, FileUploadSettingsForm - - OMNIATH_PROVIDERS_ATTRIBUTES = Decidim::OmniauthProvider.available.keys.map do |provider| - Rails.application.secrets.dig(:omniauth, provider).keys.map do |setting| - if setting == :enabled - ["omniauth_settings_#{provider}_enabled".to_sym, Boolean] - else - ["omniauth_settings_#{provider}_#{setting}".to_sym, String] - end - end - end.flatten(1) - - jsonb_attribute :omniauth_settings, OMNIATH_PROVIDERS_ATTRIBUTES - - validates :name, :host, :users_registration_mode, presence: true - validate :validate_organization_uniqueness - validate :validate_secret_key_base_for_encryption - validates :users_registration_mode, inclusion: { in: Decidim::Organization.users_registration_modes } - - def map_model(model) - self.secondary_hosts = model.secondary_hosts.join("\n") - self.omniauth_settings = (model.omniauth_settings || {}).transform_values do |v| - Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.decrypt(v) : v - end - self.file_upload_settings = FileUploadSettingsForm.from_model(model.file_upload_settings) - end - - def clean_secondary_hosts - return unless secondary_hosts - - secondary_hosts.split("\n").map(&:chomp).select(&:present?) - end - - def clean_available_authorizations - return unless available_authorizations + private - available_authorizations.select(&:present?) + def validate_organization_name_presence + translated_attr = "name_#{current_organization.try(:default_locale) || Decidim.default_locale.to_s}".to_sym + errors.add(translated_attr, :blank) if send(translated_attr).blank? end - def password - encrypted_password.nil? ? super : Decidim::AttributeEncryptor.decrypt(encrypted_password) - end + def validate_organization_uniqueness + base_query = persisted? ? Decidim::Organization.where.not(id:).all : Decidim::Organization.all - def encrypted_smtp_settings - smtp_settings["from"] = set_from + organization_names = [] - smtp_settings.merge(encrypted_password: Decidim::AttributeEncryptor.encrypt(password)) - end + base_query.pluck(:name).each do |value| + organization_names += value.except("machine_translations").values + organization_names += value.fetch("machine_translations", {}).values + end - def set_from - return from_email if from_label.blank? + organization_names = organization_names.map(&:downcase).compact_blank - "#{from_label} <#{from_email}>" - end + name.each do |language, value| + next if value.is_a?(Hash) - def encrypted_omniauth_settings - omniauth_settings.transform_values do |v| - Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.encrypt(v) : v + errors.add("name_#{language}", :taken) if organization_names.include?(value.downcase) end - end - private - - def validate_organization_uniqueness - errors.add(:name, :taken) if Decidim::Organization.where(name:).where.not(id:).exists? errors.add(:host, :taken) if Decidim::Organization.where(host:).where.not(id:).exists? end - - # We need a valid secret key base for encrypting the SMTP password with it - # It is also necessary for other things in Rails (like Cookies encryption) - def validate_secret_key_base_for_encryption - return if Rails.application.secrets.secret_key_base&.length == 128 - - errors.add(:password, I18n.t("activemodel.errors.models.organization.attributes.password.secret_key")) - end end end end diff --git a/decidim-system/app/packs/stylesheets/decidim/system/application.scss b/decidim-system/app/packs/stylesheets/decidim/system/application.scss index ef45f4c4e1e1e..d7f93399f2bd0 100644 --- a/decidim-system/app/packs/stylesheets/decidim/system/application.scss +++ b/decidim-system/app/packs/stylesheets/decidim/system/application.scss @@ -107,3 +107,60 @@ dl { .ts-dropdown { margin: 0; } + +.tabs--lang { + @apply bg-transparent flex items-center gap-x-1; + + li { + @apply p-0.5 rounded-t-sm text-secondary text-xs; + + background-color: rgba(243, 244, 247, 1); + + &.is-active, + &:hover { + @apply border-b border-secondary; + } + + &:hover { + background-color: rgba(243, 244, 247, 1); + } + } + + a { + @apply text-xs p-0; + + &::before { + @apply content-[''] w-2 h-2 inline-block bg-white rounded-full mr-2 border; + + border-color: rgba(116, 129, 144, 1); + } + } + + .tabs-title > a[aria-selected="true"] { + @apply font-bold text-secondary; + + background-color: rgba(243, 244, 247, 1); + + &::before { + @apply border-white; + + background-color: rgba(40, 167, 69, 1); + } + } + + a.is-tab-error { + color: red; + } +} + +.label--tabs { + @apply flex justify-between items-end; + + label { + @apply inline-block; + } +} + +.tabs-panel[aria-hidden="true"] { + @apply hidden; +} diff --git a/decidim-system/app/views/decidim/system/oauth_applications/_form.html.erb b/decidim-system/app/views/decidim/system/oauth_applications/_form.html.erb index ca5e2d4767a65..531da09567a24 100644 --- a/decidim-system/app/views/decidim/system/oauth_applications/_form.html.erb +++ b/decidim-system/app/views/decidim/system/oauth_applications/_form.html.erb @@ -2,7 +2,7 @@ <%= form.text_field :name %> <%= form.text_field :redirect_uri %> <%= form.select :decidim_organization_id, - Decidim::Organization.pluck(:name, :id), + Decidim::Organization.all.map { |o| [organization_name(o), o.id] }, { include_blank: t(".select_organization") }, { multiple: false } %> <%= form.text_field :organization_name %> diff --git a/decidim-system/app/views/decidim/system/organizations/edit.html.erb b/decidim-system/app/views/decidim/system/organizations/edit.html.erb index 01c5f92efebd0..db75497023d4c 100644 --- a/decidim-system/app/views/decidim/system/organizations/edit.html.erb +++ b/decidim-system/app/views/decidim/system/organizations/edit.html.erb @@ -4,9 +4,11 @@

    <%= t ".title" %>

    <% end %> -<%= decidim_form_for(@form) do |f| %> +<%= decidim_form_for(@form, url: organization_path(@organization)) do |f| %>
    - <%= f.text_field :name, autofocus: true %> +
    + <%= f.translated :text_field, :name, autofocus: true %> +
    <%= f.text_field :host %> diff --git a/decidim-system/app/views/decidim/system/shared/_organizations_list.html.erb b/decidim-system/app/views/decidim/system/shared/_organizations_list.html.erb index a0e63a7d0fc20..1330fe389dc32 100644 --- a/decidim-system/app/views/decidim/system/shared/_organizations_list.html.erb +++ b/decidim-system/app/views/decidim/system/shared/_organizations_list.html.erb @@ -10,7 +10,7 @@ <% organizations.each do |organization| %> - <%= link_to organization.name, edit_organization_path(organization) %>
    + <%= link_to organization_name(organization), edit_organization_path(organization) %>
    <%= organization.host %> diff --git a/decidim-system/spec/commands/decidim/system/register_organization_spec.rb b/decidim-system/spec/commands/decidim/system/register_organization_spec.rb index 3801904b90ac6..b8fdc2a90fb48 100644 --- a/decidim-system/spec/commands/decidim/system/register_organization_spec.rb +++ b/decidim-system/spec/commands/decidim/system/register_organization_spec.rb @@ -51,8 +51,7 @@ module System it "creates a new organization" do expect { command.call }.to change(Organization, :count).by(1) organization = Organization.last - - expect(organization.name).to eq("Gotham City") + expect(translated(organization.name)).to eq("Gotham City") expect(organization.host).to eq("decide.example.org") expect(organization.secondary_hosts).to contain_exactly("foo.example.org", "bar.example.org") expect(organization.external_domain_allowlist).to contain_exactly("decidim.org", "github.com") @@ -73,7 +72,7 @@ module System admin = User.last expect(admin.email).to eq("f.laguardia@example.org") - expect(admin.organization.name).to eq("Gotham City") + expect(translated(admin.organization.name)).to eq("Gotham City") expect(admin).to be_admin expect(admin).to be_created_by_invite expect(admin).to be_valid diff --git a/decidim-system/spec/commands/decidim/system/update_organization_spec.rb b/decidim-system/spec/commands/decidim/system/update_organization_spec.rb index 52a63f1920a78..9bd7b89a8f463 100644 --- a/decidim-system/spec/commands/decidim/system/update_organization_spec.rb +++ b/decidim-system/spec/commands/decidim/system/update_organization_spec.rb @@ -9,7 +9,7 @@ module System let(:form) do UpdateOrganizationForm.new(params) end - let(:organization) { create(:organization, name: "My organization") } + let(:organization) { create(:organization, name: { en: "My organization" }) } let(:command) { described_class.new(organization.id, form) } @@ -17,7 +17,7 @@ module System let(:from_label) { "Decide Gotham" } let(:params) do { - name: "Gotham City", + name: { en: "Gotham City" }, host: "decide.example.org", secondary_hosts: "foo.example.org\r\n\r\nbar.example.org", force_users_to_authenticate_before_access_organization: false, @@ -48,7 +48,7 @@ module System expect { command.call }.to change(Organization, :count).by(1) organization = Organization.last - expect(organization.name).to eq("Gotham City") + expect(translated(organization.name)).to eq("Gotham City") expect(organization.host).to eq("decide.example.org") expect(organization.secondary_hosts).to contain_exactly("foo.example.org", "bar.example.org") expect(organization.users_registration_mode).to eq("existing") @@ -80,15 +80,43 @@ module System end context "when the form is invalid" do - let(:params) do - { - name: nil, - host: "foo.com" - } + context "and the name is empty" do + let(:params) do + { + name: { en: "" }, + host: "foo.com" + } + end + + it "returns an invalid response" do + expect { command.call }.to broadcast(:invalid) + end + end + + context "and the name is empty hash" do + let(:params) do + { + name: {}, + host: "foo.com" + } + end + + it "returns an invalid response" do + expect { command.call }.to broadcast(:invalid) + end end - it "returns an invalid response" do - expect { command.call }.to broadcast(:invalid) + context "and the name is nil" do + let(:params) do + { + name: nil, + host: "foo.com" + } + end + + it "returns an invalid response" do + expect { command.call }.to broadcast(:invalid) + end end end diff --git a/decidim-system/spec/forms/decidim/system/update_organization_form_spec.rb b/decidim-system/spec/forms/decidim/system/update_organization_form_spec.rb index b28030cd4c75b..d146682294d9f 100644 --- a/decidim-system/spec/forms/decidim/system/update_organization_form_spec.rb +++ b/decidim-system/spec/forms/decidim/system/update_organization_form_spec.rb @@ -6,7 +6,7 @@ module Decidim::System describe UpdateOrganizationForm do subject do described_class.new( - name: "Gotham City", + name: { ca: "", en: "Gotham City", es: "" }, host: "decide.example.org", secondary_hosts: "foo.example.org\r\n\r\nbar.example.org", reference_prefix: "JKR", diff --git a/decidim-system/spec/system/dashboard_spec.rb b/decidim-system/spec/system/dashboard_spec.rb index 520e599ac6317..a6863de3b96f5 100644 --- a/decidim-system/spec/system/dashboard_spec.rb +++ b/decidim-system/spec/system/dashboard_spec.rb @@ -4,7 +4,7 @@ describe "Organizations" do let(:admin) { create(:admin, email: "system@example.org") } - let(:organization) { create(:organization, name: "Citizen Corp") } + let(:organization) { create(:organization, name: { ca: "", en: "Citizen Corp", es: "" }) } context "when an admin authenticated" do before do diff --git a/decidim-system/spec/system/manage_oauth_applications_spec.rb b/decidim-system/spec/system/manage_oauth_applications_spec.rb index 95c9a8fa55f75..1586832456517 100644 --- a/decidim-system/spec/system/manage_oauth_applications_spec.rb +++ b/decidim-system/spec/system/manage_oauth_applications_spec.rb @@ -19,7 +19,7 @@ within ".new_oauth_application" do fill_in :oauth_application_name, with: "Meta Decidim" fill_in :oauth_application_redirect_uri, with: "https://example.org/oauth/decidim" - select organization.name, from: :oauth_application_decidim_organization_id + select translated(organization.name), from: :oauth_application_decidim_organization_id fill_in :oauth_application_organization_name, with: "Ajuntament de Barcelona" fill_in :oauth_application_organization_url, with: "https://www.barcelona.cat" end diff --git a/decidim-system/spec/system/organizations_spec.rb b/decidim-system/spec/system/organizations_spec.rb index fe4dd00b1c3a2..c5fab3b1463e8 100644 --- a/decidim-system/spec/system/organizations_spec.rb +++ b/decidim-system/spec/system/organizations_spec.rb @@ -126,7 +126,7 @@ end describe "editing an organization" do - let!(:organization) { create(:organization, name: "Citizen Corp") } + let!(:organization) { create(:organization, name: { ca: "", en: "Citizen Corp", es: "" }) } before do click_on "Organizations" @@ -137,17 +137,33 @@ it_behaves_like "form hiding advanced settings" + it "properly validate name" do + create(:organization, name: { ca: "", en: "Duplicate organization", es: "" }) + + fill_in_i18n :update_organization_name, "#update_organization-name-tabs", en: "Citizens Rule!", ca: "Something", es: "Another" + click_on "Save" + + within "table tbody tr", text: "Citizens Rule!" do + click_on "Edit" + end + fill_in_i18n :update_organization_name, "#update_organization-name-tabs", en: "Citizens Rule!", ca: "", es: "" + click_on "Save" + + expect(page).to have_css("div.flash.success") + expect(page).to have_content("Citizens Rule!") + end + it "edits the data" do - fill_in "Name", with: "Citizens Rule!" + fill_in_i18n :update_organization_name, "#update_organization-name-tabs", en: "Citizens Rule!" fill_in "Host", with: "www.example.org" fill_in "Secondary hosts", with: "foobar.example.org\n\rbar.example.org" choose "Do not allow participants to register, but allow existing participants to login" check "Example authorization (Direct)" click_on "Show advanced settings" - check "organization_omniauth_settings_facebook_enabled" - fill_in "organization_omniauth_settings_facebook_app_id", with: "facebook-app-id" - fill_in "organization_omniauth_settings_facebook_app_secret", with: "facebook-app-secret" + check "update_organization_omniauth_settings_facebook_enabled" + fill_in "update_organization_omniauth_settings_facebook_app_id", with: "facebook-app-id" + fill_in "update_organization_omniauth_settings_facebook_app_secret", with: "facebook-app-secret" click_on "Save" @@ -161,7 +177,7 @@ end it "shows the error message" do - fill_in "Name", with: "Citizens Rule!" + fill_in_i18n :update_organization_name, "#update_organization-name-tabs", en: "Citizens Rule!" fill_in "Host", with: "www.example.org" click_on "Save" @@ -173,7 +189,7 @@ describe "editing an organization with disabled OmniAuth provider" do let!(:organization) do - create(:organization, name: "Citizen Corp", default_locale: :es, available_locales: ["es"], description: { es: "Un texto largo" }) + create(:organization, name: { ca: "", en: "Citizen Corp", es: "" }, default_locale: :es, available_locales: ["es"], description: { es: "Un texto largo" }) end before do @@ -205,7 +221,9 @@ ) # Reload the UpdateOrganizationForm + Decidim::System.send(:remove_const, :BaseOrganizationForm) Decidim::System.send(:remove_const, :UpdateOrganizationForm) + load "#{Decidim::System::Engine.root}/app/forms/decidim/system/base_organization_form.rb" load "#{Decidim::System::Engine.root}/app/forms/decidim/system/update_organization_form.rb" click_on "Organizations" @@ -218,7 +236,9 @@ after do # Reload the UpdateOrganizationForm + Decidim::System.send(:remove_const, :BaseOrganizationForm) Decidim::System.send(:remove_const, :UpdateOrganizationForm) + load "#{Decidim::System::Engine.root}/app/forms/decidim/system/base_organization_form.rb" load "#{Decidim::System::Engine.root}/app/forms/decidim/system/update_organization_form.rb" end diff --git a/decidim-templates/app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb b/decidim-templates/app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb index 4164a7f5a6822..dab5deae04c4f 100644 --- a/decidim-templates/app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb +++ b/decidim-templates/app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb @@ -140,7 +140,7 @@ def available_states(component_id = nil) def populate_template_interpolations(proposal) template.description.to_h do |language, value| - value.gsub!("%{organization}", proposal.organization.name) + value.gsub!("%{organization}", translated_attribute(proposal.organization.name)) value.gsub!("%{name}", author_name(proposal)) value.gsub!("%{admin}", current_user.name) diff --git a/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb b/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb index f10027341afa6..2fd1c6faa22bf 100644 --- a/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb +++ b/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb @@ -226,7 +226,7 @@ it "changes it with the organization name" do within ".edit_proposal_answer" do select template.name["en"], from: :proposal_answer_template_chooser - expect(page).to have_content("Some meaningful answer with the #{organization.name}") + expect(page).to have_content("Some meaningful answer with the #{translated(organization.name)}") end end end From c9ddbb4f47873618492bd31f9d19ccfd120fce5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Tue, 21 May 2024 21:26:57 +0200 Subject: [PATCH 02/15] Fix strings for ordering when listing budgets (#12857) --- .../app/cells/decidim/budgets/budgets_list/main_list.erb | 2 +- decidim-budgets/config/locales/en.yml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/decidim-budgets/app/cells/decidim/budgets/budgets_list/main_list.erb b/decidim-budgets/app/cells/decidim/budgets/budgets_list/main_list.erb index 9a87594bba6f4..d8a52efc26a5e 100644 --- a/decidim-budgets/app/cells/decidim/budgets/budgets_list/main_list.erb +++ b/decidim-budgets/app/cells/decidim/budgets/budgets_list/main_list.erb @@ -1,5 +1,5 @@

    <%= t(:count, scope: i18n_scope, count: budgets.length) %>

    -<%= render partial: "decidim/shared/orders", formats: [:html], locals: { orders: AVAILABLE_ORDERS, i18n_scope: "decidim.budgets.projects.orders" } %> +<%= render partial: "decidim/shared/orders", formats: [:html], locals: { orders: AVAILABLE_ORDERS, i18n_scope: "decidim.budgets.budgets_list.orders" } %> <%= render :card_list %> diff --git a/decidim-budgets/config/locales/en.yml b/decidim-budgets/config/locales/en.yml index f02650d1ca16f..a8f174dfc4aba 100644 --- a/decidim-budgets/config/locales/en.yml +++ b/decidim-budgets/config/locales/en.yml @@ -185,6 +185,11 @@ en: finished_message: You have finished the voting process. Thanks for participating! highlighted_cta: Vote on %{name} if_change_opinion: If you have changed your mind, you can + orders: + highest_cost: Highest cost + label: Order budgets by + lowest_cost: Lowest cost + random: Random order progress: Finish voting remove_vote: Remove vote show: See projects From 706ac9d5ac526137aa4d2194d40fb07e9d7979bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Tue, 21 May 2024 21:46:32 +0200 Subject: [PATCH 03/15] Remove customizations for labels on accountability (#12853) --- RELEASE_NOTES.md | 6 ++++ .../decidim/accountability/status_cell.rb | 7 +--- .../accountability/application_helper.rb | 8 ----- .../results/_home_categories.html.erb | 4 +-- decidim-accountability/config/locales/en.yml | 4 --- .../lib/decidim/accountability/component.rb | 4 --- .../lib/decidim/accountability/seeds.rb | 4 --- .../decidim/accountability/test/factories.rb | 4 --- .../lib/decidim/dev/assets/assemblies.json | 32 ------------------- .../dev/assets/participatory_processes.json | 32 ------------------- 10 files changed, 9 insertions(+), 96 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index cc5a6d00c69d9..e66b468290a1d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -47,6 +47,12 @@ We have updated the Rails version to 7.0.8.1. You do not need to do anything. You can read more about this change on PR [#12616](https://github.com/decidim/decidim/pull/12616). +## 2.3. Removal of the accountability naming customization + +We have removed the ability to customize the labels from the Accountability component, as it was not following the recommended way of handling these text customizations. If you want to migrate your current customizations, you can read about [Text customizations in Decidim Documentation](https://docs.decidim.org/en/develop/customize/texts) + +You can read more about this change on PR [#12853](https://github.com/decidim/decidim/pull/12853). + ## 3. One time actions These are one time actions that need to be done after the code is updated in the production database. diff --git a/decidim-accountability/app/cells/decidim/accountability/status_cell.rb b/decidim-accountability/app/cells/decidim/accountability/status_cell.rb index cd787ac1153af..6d9caaddab06a 100644 --- a/decidim-accountability/app/cells/decidim/accountability/status_cell.rb +++ b/decidim-accountability/app/cells/decidim/accountability/status_cell.rb @@ -75,12 +75,7 @@ def display_count(count) end def heading_parent_level_results(count) - text = translated_attribute(component_settings.heading_parent_level_results).presence - if text - pluralize(count, text) - else - t("results.count.results_count", scope: "decidim.accountability", count:) - end + t("results.count.results_count", scope: "decidim.accountability", count:) end def render_count diff --git a/decidim-accountability/app/helpers/decidim/accountability/application_helper.rb b/decidim-accountability/app/helpers/decidim/accountability/application_helper.rb index 74ee3c065d1ed..bb12d9f4c51a2 100644 --- a/decidim-accountability/app/helpers/decidim/accountability/application_helper.rb +++ b/decidim-accountability/app/helpers/decidim/accountability/application_helper.rb @@ -18,14 +18,6 @@ def component_name (defined?(current_component) && translated_attribute(current_component&.name).presence) || t("decidim.components.accountability.name") end - def categories_label - translated_attribute(component_settings.categories_label).presence || t("results.home.categories_label", scope: "decidim.accountability") - end - - def subcategories_label - translated_attribute(component_settings.subcategories_label).presence || t("results.home.subcategories_label", scope: "decidim.accountability") - end - def filter_items_for(participatory_space:, category:) [ { diff --git a/decidim-accountability/app/views/decidim/accountability/results/_home_categories.html.erb b/decidim-accountability/app/views/decidim/accountability/results/_home_categories.html.erb index f8af1c6a87702..b5938eaf01a43 100644 --- a/decidim-accountability/app/views/decidim/accountability/results/_home_categories.html.erb +++ b/decidim-accountability/app/views/decidim/accountability/results/_home_categories.html.erb @@ -9,12 +9,12 @@ ) %>
    - <%= categories_label %> + <%= t("results.home.categories_label", scope: "decidim.accountability") %> <%= subelements.call %>
    - <%= subcategories_label %> + <%= t("results.home.subcategories_label", scope: "decidim.accountability") %> <% if subelements.has_results? %>
    <% category.subcategories.each do |subcategory| %> diff --git a/decidim-accountability/config/locales/en.yml b/decidim-accountability/config/locales/en.yml index ce8764b6698cb..c5b9e008076cf 100644 --- a/decidim-accountability/config/locales/en.yml +++ b/decidim-accountability/config/locales/en.yml @@ -255,16 +255,12 @@ en: name: Accountability settings: global: - categories_label: Name for "Categories" comments_enabled: Comments enabled comments_max_length: Comments max length (Leave 0 for default value) display_progress_enabled: Display progress - heading_leaf_level_results: Name for "Projects" - heading_parent_level_results: Name for "Results" intro: Intro scope_id: Scope scopes_enabled: Scopes enabled - subcategories_label: Name for "Subcategories" step: comments_blocked: Comments blocked events: diff --git a/decidim-accountability/lib/decidim/accountability/component.rb b/decidim-accountability/lib/decidim/accountability/component.rb index 10439f0297f91..81c3848c1483f 100644 --- a/decidim-accountability/lib/decidim/accountability/component.rb +++ b/decidim-accountability/lib/decidim/accountability/component.rb @@ -30,10 +30,6 @@ settings.attribute :comments_enabled, type: :boolean, default: true settings.attribute :comments_max_length, type: :integer, required: true settings.attribute :intro, type: :text, translated: true, editor: true - settings.attribute :categories_label, type: :string, translated: true, editor: true - settings.attribute :subcategories_label, type: :string, translated: true, editor: true - settings.attribute :heading_parent_level_results, type: :string, translated: true, editor: true - settings.attribute :heading_leaf_level_results, type: :string, translated: true, editor: true settings.attribute :display_progress_enabled, type: :boolean, default: true end diff --git a/decidim-accountability/lib/decidim/accountability/seeds.rb b/decidim-accountability/lib/decidim/accountability/seeds.rb index bd3064ddbc2d3..f5e364e265d5d 100644 --- a/decidim-accountability/lib/decidim/accountability/seeds.rb +++ b/decidim-accountability/lib/decidim/accountability/seeds.rb @@ -24,10 +24,6 @@ def call participatory_space:, settings: { intro: Decidim::Faker::Localized.wrapped("

    ", "

    ") { Decidim::Faker::Localized.sentence(word_count: 4) }, - categories_label: Decidim::Faker::Localized.word, - subcategories_label: Decidim::Faker::Localized.word, - heading_parent_level_results: Decidim::Faker::Localized.word, - heading_leaf_level_results: Decidim::Faker::Localized.word, scopes_enabled: true, scope_id: participatory_space.scope&.id } diff --git a/decidim-accountability/lib/decidim/accountability/test/factories.rb b/decidim-accountability/lib/decidim/accountability/test/factories.rb index 0549daf045982..62eaeff04f09c 100644 --- a/decidim-accountability/lib/decidim/accountability/test/factories.rb +++ b/decidim-accountability/lib/decidim/accountability/test/factories.rb @@ -18,10 +18,6 @@ settings do { intro: generate_localized_description(:accountability_component_intro, skip_injection:), - categories_label: generate_localized_word(:accountability_component_categories_label, skip_injection:), - subcategories_label: generate_localized_word(:accountability_component_subcategories_label, skip_injection:), - heading_parent_level_results: generate_localized_word(:accountability_component_heading_parent_level_results, skip_injection:), - heading_leaf_level_results: generate_localized_word(:accountability_component_heading_leaf_level_results, skip_injection:), scopes_enabled: true, scope_id: participatory_space.scope&.id } diff --git a/decidim-dev/lib/decidim/dev/assets/assemblies.json b/decidim-dev/lib/decidim/dev/assets/assemblies.json index be8965c407640..d444526bc9b6a 100644 --- a/decidim-dev/lib/decidim/dev/assets/assemblies.json +++ b/decidim-dev/lib/decidim/dev/assets/assemblies.json @@ -352,38 +352,6 @@ "intro_en": "

    Praesentium iste sit dicta.

    ", "intro_ca": "

    Odit aperiam ea reiciendis.

    ", "intro_es": "

    Repudiandae magni quo sit.

    ", - "categories_label": { - "ca": "rerum", - "en": "dolores", - "es": "voluptatem" - }, - "categories_label_en": "dolores", - "categories_label_ca": "rerum", - "categories_label_es": "voluptatem", - "subcategories_label": { - "ca": "totam", - "en": "qui", - "es": "iure" - }, - "subcategories_label_en": "qui", - "subcategories_label_ca": "totam", - "subcategories_label_es": "iure", - "heading_parent_level_results": { - "ca": "pariatur", - "en": "voluptatem", - "es": "molestias" - }, - "heading_parent_level_results_en": "voluptatem", - "heading_parent_level_results_ca": "pariatur", - "heading_parent_level_results_es": "molestias", - "heading_leaf_level_results": { - "ca": "enim", - "en": "nam", - "es": "et" - }, - "heading_leaf_level_results_en": "nam", - "heading_leaf_level_results_ca": "enim", - "heading_leaf_level_results_es": "et", "display_progress_enabled": true }, "weight": 0, diff --git a/decidim-dev/lib/decidim/dev/assets/participatory_processes.json b/decidim-dev/lib/decidim/dev/assets/participatory_processes.json index 86634b68e3a2c..d4cc695c343c5 100644 --- a/decidim-dev/lib/decidim/dev/assets/participatory_processes.json +++ b/decidim-dev/lib/decidim/dev/assets/participatory_processes.json @@ -340,38 +340,6 @@ "intro_en": "

    Voluptatem praesentium maxime vitae.

    ", "intro_ca": "

    Sapiente animi quo at.

    ", "intro_es": "

    Illum veritatis porro nulla.

    ", - "categories_label": { - "ca": "alias", - "en": "aut", - "es": "omnis" - }, - "categories_label_en": "aut", - "categories_label_ca": "alias", - "categories_label_es": "omnis", - "subcategories_label": { - "ca": "rerum", - "en": "reprehenderit", - "es": "nostrum" - }, - "subcategories_label_en": "reprehenderit", - "subcategories_label_ca": "rerum", - "subcategories_label_es": "nostrum", - "heading_parent_level_results": { - "ca": "et", - "en": "explicabo", - "es": "officiis" - }, - "heading_parent_level_results_en": "explicabo", - "heading_parent_level_results_ca": "et", - "heading_parent_level_results_es": "officiis", - "heading_leaf_level_results": { - "ca": "consectetur", - "en": "illum", - "es": "sunt" - }, - "heading_leaf_level_results_en": "illum", - "heading_leaf_level_results_ca": "consectetur", - "heading_leaf_level_results_es": "sunt", "display_progress_enabled": true }, "weight": 0, From 351b8a423e10168462c1d6f51618431b1dfa442b Mon Sep 17 00:00:00 2001 From: Tom <101816158+greenwoodt@users.noreply.github.com> Date: Wed, 22 May 2024 10:59:34 +0200 Subject: [PATCH 04/15] Standardise `current_user` call within Commands tasks (Participatory Processes) (#12840) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * delgated current_user to form * returned arguement perform action command * create controller updated 2 arguements * adapted instance_double to alter form test * changed arguement in call in controller * delgate current_user to form in import * Deleted delegation method import process * re-added current_user to call * Update decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb Co-authored-by: Andrés Pereira de Lucena * reverting commit /controller_update/ * Update decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb Co-authored-by: Andrés Pereira de Lucena --------- Co-authored-by: Andrés Pereira de Lucena --- .../admin/copy_participatory_process.rb | 6 +++--- .../admin/import_participatory_process.rb | 7 ++++--- .../admin/participatory_process_copies_controller.rb | 2 +- .../spec/commands/copy_participatory_process_spec.rb | 10 +++++----- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/copy_participatory_process.rb b/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/copy_participatory_process.rb index 511355925fd57..9e3a82ccfb403 100644 --- a/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/copy_participatory_process.rb +++ b/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/copy_participatory_process.rb @@ -6,14 +6,14 @@ module Admin # A command with all the business logic when copying a new participatory # process in the system. class CopyParticipatoryProcess < Decidim::Command + delegate :current_user, to: :form # Public: Initializes the command. # # form - A form object with the params. # participatory_process - A participatory_process we want to duplicate - def initialize(form, participatory_process, current_user) + def initialize(form, participatory_process) @form = form @participatory_process = participatory_process - @current_user = current_user end # Executes the command. Broadcasts these events: @@ -25,7 +25,7 @@ def initialize(form, participatory_process, current_user) def call return broadcast(:invalid) if form.invalid? - Decidim.traceability.perform_action!("duplicate", @participatory_process, @current_user) do + Decidim.traceability.perform_action!("duplicate", @participatory_process, current_user) do ParticipatoryProcess.transaction do copy_participatory_process copy_participatory_process_attachments diff --git a/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/import_participatory_process.rb b/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/import_participatory_process.rb index af92bbdf19400..a2a5d758e683a 100644 --- a/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/import_participatory_process.rb +++ b/decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/import_participatory_process.rb @@ -6,6 +6,7 @@ module Admin # A command with all the business logic when copying a new participatory # process in the system. class ImportParticipatoryProcess < Decidim::Command + delegate :current_user, to: :form # Public: Initializes the command. # # form - A form object with the params. @@ -36,10 +37,10 @@ def call attr_reader :form def import_participatory_process - importer = Decidim::ParticipatoryProcesses::ParticipatoryProcessImporter.new(form.current_organization, form.current_user) + importer = Decidim::ParticipatoryProcesses::ParticipatoryProcessImporter.new(form.current_organization, current_user) participatory_processes.each do |original_process| - Decidim.traceability.perform_action!("import", Decidim::ParticipatoryProcess, form.current_user) do - @imported_process = importer.import(original_process, form.current_user, title: form.title, slug: form.slug) + Decidim.traceability.perform_action!("import", Decidim::ParticipatoryProcess, current_user) do + @imported_process = importer.import(original_process, current_user, title: form.title, slug: form.slug) importer.import_participatory_process_steps(original_process["participatory_process_steps"]) if form.import_steps? importer.import_categories(original_process["participatory_process_categories"]) if form.import_categories? importer.import_folders_and_attachments(original_process["attachments"]) if form.import_attachments? diff --git a/decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb b/decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb index ea2454d32b432..2f3526fb7ce23 100644 --- a/decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb +++ b/decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb @@ -17,7 +17,7 @@ def create enforce_permission_to :create, :process @form = form(ParticipatoryProcessCopyForm).from_params(params) - CopyParticipatoryProcess.call(@form, current_participatory_process, current_user) do + CopyParticipatoryProcess.call(@form, current_participatory_process) do on(:ok) do flash[:notice] = I18n.t("participatory_processes_copies.create.success", scope: "decidim.admin") redirect_to participatory_processes_path diff --git a/decidim-participatory_processes/spec/commands/copy_participatory_process_spec.rb b/decidim-participatory_processes/spec/commands/copy_participatory_process_spec.rb index e3d06bfc3b22a..e16fd8b2b7754 100644 --- a/decidim-participatory_processes/spec/commands/copy_participatory_process_spec.rb +++ b/decidim-participatory_processes/spec/commands/copy_participatory_process_spec.rb @@ -4,10 +4,10 @@ module Decidim::ParticipatoryProcesses describe Admin::CopyParticipatoryProcess do - subject { described_class.new(form, participatory_process, user) } + subject { described_class.new(form, participatory_process) } let(:organization) { create(:organization) } - let(:user) { create(:user, organization:) } + let(:current_user) { create(:user, organization:) } let(:participatory_process_group) { create(:participatory_process_group, organization:) } let(:scope) { create(:scope, organization:) } let(:errors) { double.as_null_object } @@ -21,7 +21,8 @@ module Decidim::ParticipatoryProcesses slug: "copied-slug", copy_steps?: copy_steps, copy_categories?: copy_categories, - copy_components?: copy_components + copy_components?: copy_components, + current_user: ) end let!(:category) do @@ -77,9 +78,8 @@ module Decidim::ParticipatoryProcesses it "traces the action", versioning: true do expect(Decidim.traceability) .to receive(:perform_action!) - .with("duplicate", Decidim::ParticipatoryProcess, user) + .with("duplicate", Decidim::ParticipatoryProcess, current_user) .and_call_original - expect { subject.call }.to change(Decidim::ActionLog, :count) action_log = Decidim::ActionLog.last expect(action_log.action).to eq("duplicate") From d9fd5361af1c9eef1ce7efd85822c14943b0f0f3 Mon Sep 17 00:00:00 2001 From: Tom <101816158+greenwoodt@users.noreply.github.com> Date: Fri, 24 May 2024 08:37:58 +0200 Subject: [PATCH 05/15] Rename system command names for consistency (#12852) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * renamed seed commands and create organisation calls * Rename spec file * deleted duplicate file * renamed seed commands and create organisation calls * Rename spec file * deleted duplicate file * test * reverting change * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena * Update decidim-system/app/commands/decidim/system/create_default_help_pages.rb Co-authored-by: Andrés Pereira de Lucena --------- Co-authored-by: Andrés Pereira de Lucena --- decidim-admin/spec/system/admin_invite_spec.rb | 2 +- .../system/{populate_help.rb => create_default_help_pages.rb} | 2 +- .../{register_organization.rb => create_organization.rb} | 4 ++-- .../controllers/decidim/system/organizations_controller.rb | 2 +- decidim-system/db/seeds.rb | 2 +- ...ister_organization_spec.rb => create_organization_spec.rb} | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) rename decidim-system/app/commands/decidim/system/{populate_help.rb => create_default_help_pages.rb} (97%) rename decidim-system/app/commands/decidim/system/{register_organization.rb => create_organization.rb} (96%) rename decidim-system/spec/commands/decidim/system/{register_organization_spec.rb => create_organization_spec.rb} (99%) diff --git a/decidim-admin/spec/system/admin_invite_spec.rb b/decidim-admin/spec/system/admin_invite_spec.rb index 51c0edb0d25d6..7f920ad6d8daf 100644 --- a/decidim-admin/spec/system/admin_invite_spec.rb +++ b/decidim-admin/spec/system/admin_invite_spec.rb @@ -30,7 +30,7 @@ before do expect do - perform_enqueued_jobs { Decidim::System::RegisterOrganization.new(form).call } + perform_enqueued_jobs { Decidim::System::CreateOrganization.new(form).call } end.to broadcast(:ok) switch_to_host("decide.lvh.me") diff --git a/decidim-system/app/commands/decidim/system/populate_help.rb b/decidim-system/app/commands/decidim/system/create_default_help_pages.rb similarity index 97% rename from decidim-system/app/commands/decidim/system/populate_help.rb rename to decidim-system/app/commands/decidim/system/create_default_help_pages.rb index 6d4473e22ed03..ff60154657e75 100644 --- a/decidim-system/app/commands/decidim/system/populate_help.rb +++ b/decidim-system/app/commands/decidim/system/create_default_help_pages.rb @@ -3,7 +3,7 @@ module Decidim module System # A command that will create default help pages for an organization. - class PopulateHelp < Decidim::Command + class CreateDefaultHelpPages < Decidim::Command include Decidim::TranslatableAttributes # Public: Initializes the command. diff --git a/decidim-system/app/commands/decidim/system/register_organization.rb b/decidim-system/app/commands/decidim/system/create_organization.rb similarity index 96% rename from decidim-system/app/commands/decidim/system/register_organization.rb rename to decidim-system/app/commands/decidim/system/create_organization.rb index 82daac9d90543..cc4df62d4b9a9 100644 --- a/decidim-system/app/commands/decidim/system/register_organization.rb +++ b/decidim-system/app/commands/decidim/system/create_organization.rb @@ -5,7 +5,7 @@ module System # A command with all the business logic when creating a new organization in # the system. It creates the organization and invites the admin to the # system. - class RegisterOrganization < Decidim::Command + class CreateOrganization < Decidim::Command # Public: Initializes the command. # # form - A form object with the params. @@ -29,7 +29,7 @@ def call transaction do @organization = create_organization CreateDefaultPages.call(@organization) - PopulateHelp.call(@organization) + CreateDefaultHelpPages.call(@organization) CreateDefaultContentBlocks.call(@organization) invite_form = invite_user_form(@organization) invitation_failed = invite_form.invalid? diff --git a/decidim-system/app/controllers/decidim/system/organizations_controller.rb b/decidim-system/app/controllers/decidim/system/organizations_controller.rb index 183d5dac8bbdb..f3236873b5c7f 100644 --- a/decidim-system/app/controllers/decidim/system/organizations_controller.rb +++ b/decidim-system/app/controllers/decidim/system/organizations_controller.rb @@ -16,7 +16,7 @@ def new def create @form = form(RegisterOrganizationForm).from_params(params) - RegisterOrganization.call(@form) do + CreateOrganization.call(@form) do on(:ok) do flash[:notice] = t("organizations.create.success_html", scope: "decidim.system", host: @form.host, email: @form.organization_admin_email) redirect_to organizations_path diff --git a/decidim-system/db/seeds.rb b/decidim-system/db/seeds.rb index 89b198264624b..264027517ea73 100644 --- a/decidim-system/db/seeds.rb +++ b/decidim-system/db/seeds.rb @@ -12,6 +12,6 @@ Decidim::Organization.find_each do |organization| Decidim::System::CreateDefaultPages.call(organization) - Decidim::System::PopulateHelp.call(organization) + Decidim::System::CreateDefaultHelpPages.call(organization) end end diff --git a/decidim-system/spec/commands/decidim/system/register_organization_spec.rb b/decidim-system/spec/commands/decidim/system/create_organization_spec.rb similarity index 99% rename from decidim-system/spec/commands/decidim/system/register_organization_spec.rb rename to decidim-system/spec/commands/decidim/system/create_organization_spec.rb index b8fdc2a90fb48..380e24270b5a9 100644 --- a/decidim-system/spec/commands/decidim/system/register_organization_spec.rb +++ b/decidim-system/spec/commands/decidim/system/create_organization_spec.rb @@ -4,7 +4,7 @@ module Decidim module System - describe RegisterOrganization do + describe CreateOrganization do describe "call" do let(:form) do RegisterOrganizationForm.new(params) From ffac9a563c5b571e86572f041b010fb27021294c Mon Sep 17 00:00:00 2001 From: Alexandru Emil Lupu Date: Mon, 27 May 2024 08:53:10 +0300 Subject: [PATCH 06/15] Create user notifications while seeding (#12828) * Create user notifications while seeding * Lint * Fix notification processing * Precompile assets * User finding consistency * Add rails command tracing * Split db creation * Migrate * Test check * Add assets precompile * lint * Add tracing * Investigate seed creation * change params * Fix stale objects * Fix pipeline * Add assets:precompile before db:seed * Add release notes * Fx spelling --- RELEASE_NOTES.md | 58 ++++++++++++------- .../app/models/decidim/comments/seed.rb | 7 ++- decidim-core/lib/decidim/core/seeds.rb | 3 + decidim-core/lib/decidim/seeds.rb | 4 ++ .../decidim/generators/install_generator.rb | 4 +- .../spec/runtime/full_app_generator_spec.rb | 2 +- .../lib/decidim/meetings/seeds.rb | 13 ++++- .../decidim/participatory_processes/seeds.rb | 3 + .../lib/decidim/proposals/seeds.rb | 8 +++ .../develop/pages/guide_development_app.adoc | 1 + docs/modules/install/pages/index.adoc | 2 +- docs/modules/install/pages/manual.adoc | 3 +- 12 files changed, 82 insertions(+), 26 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e66b468290a1d..4f6416f022576 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -17,14 +17,14 @@ rbenv local 3.2.2 If not, you need to adapt it to your environment. See "2.1. Ruby update to 3.2" -### 2.1. Update your Gemfile +### 1.2. Update your Gemfile ```ruby gem "decidim", github: "decidim/decidim" gem "decidim-dev", github: "decidim/decidim" ``` -### 2.2. Run these commands +### 1.3. Run these commands ```console bundle update decidim @@ -32,7 +32,7 @@ bin/rails decidim:upgrade bin/rails db:migrate ``` -### 2.3. Follow the steps and commands detailed in these notes +### 1.4. Follow the steps and commands detailed in these notes ## 2. General notes @@ -187,7 +187,41 @@ You can read more about this change on PR [\#XXXX](https://github.com/decidim/de ## 5. Changes in APIs -### 5.1. [[TITLE OF THE CHANGE]] +### 5.1 Migration of Proposal states in own table + +As of [\#12052](https://github.com/decidim/decidim/pull/12052) all the proposals states are kept in a separate database table, enabling end users to customize the states of the proposals. By default we will create for any proposal component that is being installed in the project 5 default states that cannot be disabled nor deleted. These states are: + +- Not Answered ( default state for any new created proposal ) +- Evaluating +- Accepted +- Rejected +- Withdrawn ( special states for proposals that have been withdrawn by the author ) + +For any of the above states you can customize the name, description, css class used by labels. You can also decide which states the user can receive a notification or an answer. + +You do not need to run any task to migrate the existing states, as we will automatically migrate the existing states to the new table. + +You can see more details about this change on PR [\#12052](https://github.com/decidim/decidim/pull/12052) + +### 5.2. Seeds require assets precompiling + +In order to successfully showcase the features of the application, we have added as a mandatory step the assets precompiling, as the seeds will now fire the notification system. That allows any Decidim demo instance to display user notifications. + +if you previously seeded your database using: + +```bash +bin/rails db:drop db:create db:migrate db:seed +``` + +You are required to run using: + +```bash +bin/rails db:drop db:create db:migrate assets:precompile db:seed +``` + +You can see more details about this change on PR [\#12828](https://github.com/decidim/decidim/pull/12828) + +### 5.3. [[TITLE OF THE CHANGE]] In order to [[REASONING (e.g. improve the maintenance of the code base)]] we have changed... @@ -204,19 +238,3 @@ You need to change it to: # Explain the usage of the API as it is in the new version result = 1 + 1 if after ``` - -### 5.8 Migration of Proposal states in own table - -As of [\#12052](https://github.com/decidim/decidim/pull/12052) all the proposals states are kept in a separate database table, enabling end users to customize the states of the proposals. By default we will create for any proposal component that is being installed in the project 5 default states that cannot be disabled nor deleted. These states are: - -- Not Answered ( default state for any new created proposal ) -- Evaluating -- Accepted -- Rejected -- Withdrawn ( special states for proposals that have been withdrawn by the author ) - -For any of the above states you can customize the name, description, css class used by labels. You can also decide which states the user can receive a notification or an answer. - -You do not need to run any task to migrate the existing states, as we will automatically migrate the existing states to the new table. - -You can see more details about this change on PR [\#12052](https://github.com/decidim/decidim/pull/12052) diff --git a/decidim-comments/app/models/decidim/comments/seed.rb b/decidim-comments/app/models/decidim/comments/seed.rb index 4346a6e33010a..065aca927c209 100644 --- a/decidim-comments/app/models/decidim/comments/seed.rb +++ b/decidim-comments/app/models/decidim/comments/seed.rb @@ -22,7 +22,12 @@ def comments_for(resource) rand(0..6).times do comment1 = create_comment(resource) - comment2 = create_comment(comment1, resource) if [true, false].sample + NewCommentNotificationCreator.new(comment1, [], []).create + + if [true, false].sample + comment2 = create_comment(comment1, resource) + NewCommentNotificationCreator.new(comment2, [], []).create + end next if [true, false].sample diff --git a/decidim-core/lib/decidim/core/seeds.rb b/decidim-core/lib/decidim/core/seeds.rb index a83d2eade5f14..7f69a0e01f506 100644 --- a/decidim-core/lib/decidim/core/seeds.rb +++ b/decidim-core/lib/decidim/core/seeds.rb @@ -11,8 +11,11 @@ class Seeds < Decidim::Seeds def call print "Creating seeds for decidim-core...\n" unless Rails.env.test? # rubocop:disable Rails/Output + Rails.application.reloader.reload! if Rails.application.reloader.check! reset_column_information + ActiveJob::Base.queue_adapter = :inline + organization = create_organization! if organization.top_scopes.none? diff --git a/decidim-core/lib/decidim/seeds.rb b/decidim-core/lib/decidim/seeds.rb index dca24fbfb59ce..1682e9e716aa1 100644 --- a/decidim-core/lib/decidim/seeds.rb +++ b/decidim-core/lib/decidim/seeds.rb @@ -149,5 +149,9 @@ def random_avatar create_blob!(seeds_file: "avatars/#{file_number}.jpg", filename: "#{file_number}.jpg", content_type: "image/jpeg") end + + def create_follow!(user, followable) + Decidim::Follow.create!(followable:, user:) + end end end diff --git a/decidim-generators/lib/decidim/generators/install_generator.rb b/decidim-generators/lib/decidim/generators/install_generator.rb index 4ce4640349b8a..f9cc2c92432be 100644 --- a/decidim-generators/lib/decidim/generators/install_generator.rb +++ b/decidim-generators/lib/decidim/generators/install_generator.rb @@ -184,7 +184,9 @@ def recreate_db rails "db:migrate" - rails "db:seed" if options[:seed_db] + rails "assets:precompile" + + rails "--trace", "db:seed" if options[:seed_db] rails "db:test:prepare" end diff --git a/decidim-generators/spec/runtime/full_app_generator_spec.rb b/decidim-generators/spec/runtime/full_app_generator_spec.rb index ec25addc93b83..fc34504050c16 100644 --- a/decidim-generators/spec/runtime/full_app_generator_spec.rb +++ b/decidim-generators/spec/runtime/full_app_generator_spec.rb @@ -21,7 +21,7 @@ module Decidim context "when running the db commands consecutively" do let(:command) { "decidim #{test_app} --demo --path #{repo_root}" } - let(:subcommand) { "bundle exec rails db:drop db:create db:migrate db:seed" } + let(:subcommand) { "bundle exec rails db:drop db:create db:migrate assets:precompile db:seed" } let(:subresult) do Bundler.with_original_env { GemManager.new(test_app).capture(subcommand, env: {}) } end diff --git a/decidim-meetings/lib/decidim/meetings/seeds.rb b/decidim-meetings/lib/decidim/meetings/seeds.rb index 29069989b2893..c889655d19e05 100644 --- a/decidim-meetings/lib/decidim/meetings/seeds.rb +++ b/decidim-meetings/lib/decidim/meetings/seeds.rb @@ -160,12 +160,23 @@ def meeting_params(component:, type:, author_type:) def create_meeting!(component:, type: :in_person, author_type: :official) params = meeting_params(component:, type:, author_type:) - Decidim.traceability.create!( + resource = Decidim.traceability.create!( Decidim::Meetings::Meeting, admin_user, params, visibility: "all" ) + + Decidim::EventsManager.publish( + event: "decidim.events.meetings.meeting_created", + event_class: Decidim::Meetings::CreateMeetingEvent, + resource:, + followers: resource.participatory_space.followers + ) + + Decidim::Comments::Seed.comments_for(resource) + + resource end def create_service!(meeting:) diff --git a/decidim-participatory_processes/lib/decidim/participatory_processes/seeds.rb b/decidim-participatory_processes/lib/decidim/participatory_processes/seeds.rb index 645767b10357e..11ae98116a15c 100644 --- a/decidim-participatory_processes/lib/decidim/participatory_processes/seeds.rb +++ b/decidim-participatory_processes/lib/decidim/participatory_processes/seeds.rb @@ -26,6 +26,9 @@ def call 2.times do |_n| process = create_process!(process_group: process_groups.sample, process_type: process_types.sample) + create_follow!(Decidim::User.where(organization:, admin: true).first, process) + create_follow!(Decidim::User.where(organization:, admin: false).first, process) + create_process_step!(process:) create_process_user_roles!(process:) diff --git a/decidim-proposals/lib/decidim/proposals/seeds.rb b/decidim-proposals/lib/decidim/proposals/seeds.rb index 07d06abae6d50..06e23a25d568d 100644 --- a/decidim-proposals/lib/decidim/proposals/seeds.rb +++ b/decidim-proposals/lib/decidim/proposals/seeds.rb @@ -124,6 +124,14 @@ def create_proposal!(component:) end proposal.add_coauthor(coauthor) proposal.save! + + Decidim::EventsManager.publish( + event: "decidim.events.proposals.proposal_published_for_space", + event_class: Decidim::Proposals::PublishProposalEvent, + resource: proposal, + followers: proposal.participatory_space.followers + ) + proposal end end diff --git a/docs/modules/develop/pages/guide_development_app.adoc b/docs/modules/develop/pages/guide_development_app.adoc index 627747655c9f8..c3ed4cfe8892d 100644 --- a/docs/modules/develop/pages/guide_development_app.adoc +++ b/docs/modules/develop/pages/guide_development_app.adoc @@ -49,6 +49,7 @@ On creation, these steps are automatically invoked by the generator: * `bin/rails decidim:upgrade` * `bin/rails db:create` * `bin/rails db:migrate` +* `bin/rails assets:precompile` * `bin/rails db:seed` Mind that if everything went well you should not need to run these commands manually. diff --git a/docs/modules/install/pages/index.adoc b/docs/modules/install/pages/index.adoc index 6d02c8db07b42..4e68512431b1a 100644 --- a/docs/modules/install/pages/index.adoc +++ b/docs/modules/install/pages/index.adoc @@ -52,7 +52,7 @@ You should now setup your database: [source,console] ---- -bin/rails db:create db:migrate db:seed +bin/rails db:create db:migrate assets:precompile db:seed ---- This will also create some example data through the seeds so that you can start testing the application straight away. The following table contains some example user accounts that you can start testing the system with. diff --git a/docs/modules/install/pages/manual.adoc b/docs/modules/install/pages/manual.adoc index bed0a7ab28ac7..000679b2a5b11 100644 --- a/docs/modules/install/pages/manual.adoc +++ b/docs/modules/install/pages/manual.adoc @@ -133,6 +133,7 @@ We should now create your database. For a first local installation, we recommend [source,bash] ---- bin/rails db:create db:migrate +bin/rails assets:precompile bin/rails db:seed ---- @@ -165,5 +166,5 @@ The seed data will not be created in production environments, if you still want [source,bash] ---- -SEED=true rails db:seed +SEED=true rails assets:precompile db:seed ---- From ee7ad7c445c6962f81f7218f9d0c199e25047ee4 Mon Sep 17 00:00:00 2001 From: Alexandru Emil Lupu Date: Mon, 27 May 2024 10:31:23 +0300 Subject: [PATCH 07/15] Hide moderated content from notifications (#12829) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Hide moderated content from notifications * Normalize locales * Apply suggestions from code review Co-authored-by: Andrés Pereira de Lucena --------- Co-authored-by: Andrés Pereira de Lucena --- .../accountability/base_result_event.rb | 4 +++ .../proposal_linked_event_spec.rb | 18 ++++++++++ .../result_progress_updated_event_spec.rb | 18 ++++++++++ .../events/decidim/comments/comment_event.rb | 4 +++ .../lib/decidim/comments/test/factories.rb | 6 ++++ .../test/shared_examples/comment_event.rb | 33 +++++++++++++++++ .../cells/decidim/notification/moderated.erb | 12 +++++++ .../app/cells/decidim/notification_cell.rb | 6 +++- decidim-core/config/locales/en.yml | 1 + decidim-core/lib/decidim/events/base_event.rb | 4 +++ .../cells/decidim/notification_cell_spec.rb | 8 +++++ .../spec/lib/events/simple_event_spec.rb | 36 ++++++++++++++----- decidim-dev/lib/decidim/dev/test/factories.rb | 6 ++++ .../lib/decidim/proposals/test/factories.rb | 6 ++++ 14 files changed, 152 insertions(+), 10 deletions(-) create mode 100644 decidim-core/app/cells/decidim/notification/moderated.erb diff --git a/decidim-accountability/app/events/decidim/accountability/base_result_event.rb b/decidim-accountability/app/events/decidim/accountability/base_result_event.rb index 3f14f856b3e0d..083d3c9f6e039 100644 --- a/decidim-accountability/app/events/decidim/accountability/base_result_event.rb +++ b/decidim-accountability/app/events/decidim/accountability/base_result_event.rb @@ -20,6 +20,10 @@ def proposal_path def proposal @proposal ||= resource.linked_resources(:proposals, "included_proposals").find_by(id: extra[:proposal_id]) end + + def hidden_resource? + super || (proposal.respond_to?(:hidden?) && proposal.hidden?) + end end end end diff --git a/decidim-accountability/spec/events/decidim/accountability/proposal_linked_event_spec.rb b/decidim-accountability/spec/events/decidim/accountability/proposal_linked_event_spec.rb index 85b572c6d0328..5b4d38d115d7f 100644 --- a/decidim-accountability/spec/events/decidim/accountability/proposal_linked_event_spec.rb +++ b/decidim-accountability/spec/events/decidim/accountability/proposal_linked_event_spec.rb @@ -71,4 +71,22 @@ expect(subject.resource_text).to eq translated(resource.description) end end + + describe "hidden_resource?" do + context "when resource is not moderated" do + let(:resource) { create(:proposal) } + + it "returns false" do + expect(subject.hidden_resource?).to be false + end + end + + context "when resource is moderated" do + let(:resource) { create(:proposal, :moderated) } + + it "returns true" do + expect(subject.hidden_resource?).to be true + end + end + end end diff --git a/decidim-accountability/spec/events/decidim/accountability/result_progress_updated_event_spec.rb b/decidim-accountability/spec/events/decidim/accountability/result_progress_updated_event_spec.rb index 5755917678805..176d5be76d99a 100644 --- a/decidim-accountability/spec/events/decidim/accountability/result_progress_updated_event_spec.rb +++ b/decidim-accountability/spec/events/decidim/accountability/result_progress_updated_event_spec.rb @@ -64,4 +64,22 @@ expect(subject.resource_text).to eq translated(resource.description) end end + + describe "hidden_resource?" do + context "when resource is not moderated" do + let(:resource) { create(:proposal) } + + it "returns false" do + expect(subject.hidden_resource?).to be false + end + end + + context "when resource is moderated" do + let(:resource) { create(:proposal, :moderated) } + + it "returns true" do + expect(subject.hidden_resource?).to be true + end + end + end end diff --git a/decidim-comments/app/events/decidim/comments/comment_event.rb b/decidim-comments/app/events/decidim/comments/comment_event.rb index 3d1164774b170..9ed55bca18e43 100644 --- a/decidim-comments/app/events/decidim/comments/comment_event.rb +++ b/decidim-comments/app/events/decidim/comments/comment_event.rb @@ -14,6 +14,10 @@ def resource_text(override_translation = nil) comment.formatted_body(override_translation) end + def hidden_resource? + super || (comment.respond_to?(:hidden?) && comment.hidden?) + end + def author comment.normalized_author end diff --git a/decidim-comments/lib/decidim/comments/test/factories.rb b/decidim-comments/lib/decidim/comments/test/factories.rb index ef0ffed7fbb3e..97bbb97ad4c13 100644 --- a/decidim-comments/lib/decidim/comments/test/factories.rb +++ b/decidim-comments/lib/decidim/comments/test/factories.rb @@ -40,6 +40,12 @@ end root_commentable { build(:dummy_resource, skip_injection:) } end + + trait :moderated do + after(:create) do |comment, evaluator| + create(:moderation, reportable: comment, hidden_at: 2.days.ago, skip_injection: evaluator.skip_injection) + end + end end factory :comment_vote, class: "Decidim::Comments::CommentVote" do diff --git a/decidim-comments/lib/decidim/comments/test/shared_examples/comment_event.rb b/decidim-comments/lib/decidim/comments/test/shared_examples/comment_event.rb index b4f4fb0e474eb..fababc273b5b3 100644 --- a/decidim-comments/lib/decidim/comments/test/shared_examples/comment_event.rb +++ b/decidim-comments/lib/decidim/comments/test/shared_examples/comment_event.rb @@ -42,4 +42,37 @@ expect(subject.resource_text).to eq comment.formatted_body end end + + describe "hidden_resource?" do + context "when comment is not moderated" do + it "returns false" do + expect(subject.hidden_resource?).to be false + end + end + + context "when comment is moderated" do + let(:comment) { create(:comment, :moderated) } + + it "returns true" do + expect(subject.hidden_resource?).to be true + end + end + + context "when resource is not moderated" do + it "returns false" do + expect(subject.hidden_resource?).to be false + end + end + + context "when resource is moderated" do + before do + create(:moderation, reportable: resource, hidden_at: 2.days.ago) + resource.reload + end + + it "returns true" do + expect(subject.hidden_resource?).to be true + end + end + end end diff --git a/decidim-core/app/cells/decidim/notification/moderated.erb b/decidim-core/app/cells/decidim/notification/moderated.erb new file mode 100644 index 0000000000000..f23ef1db58572 --- /dev/null +++ b/decidim-core/app/cells/decidim/notification/moderated.erb @@ -0,0 +1,12 @@ +
    +
    +
    <%= notification.created_at_in_words %>
    +
    + <%= t("decidim.notifications.show.moderated") %> +
    +
    + <%= link_to model, remote: true, method: :delete, class: "notification__button", data: { "notification-read": "" } do %> + <%= t("mark_as_read", scope: "layouts.decidim.notifications_dashboard") %> + <%= icon "check-line", class: "fill-current" %> + <% end %> +
    diff --git a/decidim-core/app/cells/decidim/notification_cell.rb b/decidim-core/app/cells/decidim/notification_cell.rb index 2d365a3fd455c..0a48964d7660c 100644 --- a/decidim-core/app/cells/decidim/notification_cell.rb +++ b/decidim-core/app/cells/decidim/notification_cell.rb @@ -7,7 +7,11 @@ class NotificationCell < Decidim::ViewModel include Decidim::Core::Engine.routes.url_helpers def show - render :show + if notification.event_class_instance.try(:hidden_resource?) + render :moderated + else + render :show + end end def notification_title diff --git a/decidim-core/config/locales/en.yml b/decidim-core/config/locales/en.yml index 7e82e1f8764fd..70375e9d0250d 100644 --- a/decidim-core/config/locales/en.yml +++ b/decidim-core/config/locales/en.yml @@ -1241,6 +1241,7 @@ en: no_notifications: No notifications yet. show: missing_event: Oops, this notification belongs to an item that is no longer available. You can discard it. + moderated: Content moderated notifications_digest_mailer: header: daily: Daily Notification Digest diff --git a/decidim-core/lib/decidim/events/base_event.rb b/decidim-core/lib/decidim/events/base_event.rb index 2d0aab33e3665..6769b3191a6ac 100644 --- a/decidim-core/lib/decidim/events/base_event.rb +++ b/decidim-core/lib/decidim/events/base_event.rb @@ -111,6 +111,10 @@ def resource_title Decidim::ContentProcessor.render_without_format(title, links: false).html_safe end + def hidden_resource? + resource.respond_to?(:hidden?) && resource.hidden? + end + private def component diff --git a/decidim-core/spec/cells/decidim/notification_cell_spec.rb b/decidim-core/spec/cells/decidim/notification_cell_spec.rb index 2286e57e5c5f9..0c18ecfee78b4 100644 --- a/decidim-core/spec/cells/decidim/notification_cell_spec.rb +++ b/decidim-core/spec/cells/decidim/notification_cell_spec.rb @@ -30,4 +30,12 @@ expect(my_cell.notification_title).to include("this notification belongs to an item that is no longer available") end end + + context "when resource is moderated" do + let!(:resource) { create(:dummy_resource, :moderated, component:) } + + it "does not render the resource" do + expect(subject.to_s).to include("Content moderated") + end + end end diff --git a/decidim-core/spec/lib/events/simple_event_spec.rb b/decidim-core/spec/lib/events/simple_event_spec.rb index dc6bd6f9785fe..5f8ec81809e54 100644 --- a/decidim-core/spec/lib/events/simple_event_spec.rb +++ b/decidim-core/spec/lib/events/simple_event_spec.rb @@ -6,16 +6,16 @@ module Decidim describe Events::SimpleEvent do let(:user) { build(:user) } - describe "i18n_options?" do - subject do - described_class.new( - resource:, - event_name: "some.event", - user:, - extra: {} - ) - end + subject do + described_class.new( + resource:, + event_name: "some.event", + user:, + extra: {} + ) + end + describe "i18n_options?" do let(:resource) { create(:dummy_resource, title: { en: "" }) } it "sanitizes the HTML tags from the i18n options" do @@ -23,5 +23,23 @@ module Decidim .to eq "alert('Hey');" end end + + describe "hidden_resource?" do + context "when resource is not moderated" do + let(:resource) { create(:dummy_resource, title: { en: "" }) } + + it "returns false" do + expect(subject.hidden_resource?).to be false + end + end + + context "when resource is moderated" do + let(:resource) { create(:dummy_resource, :moderated, title: { en: "" }) } + + it "returns false" do + expect(subject.hidden_resource?).to be true + end + end + end end end diff --git a/decidim-dev/lib/decidim/dev/test/factories.rb b/decidim-dev/lib/decidim/dev/test/factories.rb index 5f80c928694df..7775b52fab11f 100644 --- a/decidim-dev/lib/decidim/dev/test/factories.rb +++ b/decidim-dev/lib/decidim/dev/test/factories.rb @@ -35,6 +35,12 @@ end end end + + trait :moderated do + after(:create) do |resource, evaluator| + create(:moderation, reportable: resource, hidden_at: 2.days.ago, skip_injection: evaluator.skip_injection) + end + end end factory :nested_dummy_resource, class: "Decidim::Dev::NestedDummyResource" do diff --git a/decidim-proposals/lib/decidim/proposals/test/factories.rb b/decidim-proposals/lib/decidim/proposals/test/factories.rb index 426b0115bd843..3c8a84bd2b97b 100644 --- a/decidim-proposals/lib/decidim/proposals/test/factories.rb +++ b/decidim-proposals/lib/decidim/proposals/test/factories.rb @@ -466,6 +466,12 @@ def generate_state_title(token, skip_injection: false) proposal.attachments << create(:attachment, :with_pdf, attached_to: proposal, skip_injection: evaluator.skip_injection) end end + + trait :moderated do + after(:create) do |proposal, evaluator| + create(:moderation, reportable: proposal, hidden_at: 2.days.ago, skip_injection: evaluator.skip_injection) + end + end end factory :proposal_vote, class: "Decidim::Proposals::ProposalVote" do From 810de07fb229db3d82315eeeaf634a672d212350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Mon, 27 May 2024 20:40:21 +0200 Subject: [PATCH 08/15] Add proposal author when exporting proposals (#12875) --- .../decidim/proposals/proposal_serializer.rb | 51 ++++++++++ .../proposals/proposal_serializer_spec.rb | 96 +++++++++++++++++++ 2 files changed, 147 insertions(+) diff --git a/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb b/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb index c7087075e7637..fa7f40fb0c8a3 100644 --- a/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb +++ b/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb @@ -19,6 +19,9 @@ def initialize(proposal) def serialize { id: proposal.id, + author: { + **author_fields + }, category: { id: proposal.category.try(:id), name: proposal.category.try(:name) || empty_translatable @@ -104,6 +107,54 @@ def convert_to_plain_text(value) convert_to_text(value) end + + def author_fields + is_author_user_group = resource.coauthorships.map(&:decidim_user_group_id).any? + + { + id: resource.authors.map(&:id), + name: resource.authors.map do |author| + author_name(is_author_user_group ? resource.coauthorships.first.user_group : author) + end, + url: resource.authors.map do |author| + author_url(is_author_user_group ? resource.coauthorships.first.user_group : author) + end + } + end + + def author_name(author) + if author.respond_to?(:name) + translated_attribute(author.name) # is a Decidim::User or Decidim::Organization or Decidim::UserGroup + elsif author.respond_to?(:title) + translated_attribute(author.title) # is a Decidim::Meetings::Meeting + end + end + + def author_url(author) + if author.respond_to?(:nickname) + profile_url(author.nickname) # is a Decidim::User or Decidim::UserGroup + elsif author.respond_to?(:title) + meeting_url(author) # is a Decidim::Meetings::Meeting + else + root_url # is a Decidim::Organization + end + end + + def profile_url(nickname) + Decidim::Core::Engine.routes.url_helpers.profile_url(nickname, host:) + end + + def meeting_url(meeting) + Decidim::EngineRouter.main_proxy(meeting.component).meeting_url(id: meeting.id, host:) + end + + def root_url + Decidim::Core::Engine.routes.url_helpers.root_url(host:) + end + + def host + resource.organization.host + end end end end diff --git a/decidim-proposals/spec/services/decidim/proposals/proposal_serializer_spec.rb b/decidim-proposals/spec/services/decidim/proposals/proposal_serializer_spec.rb index 18dc66724e0aa..82d05868b5a24 100644 --- a/decidim-proposals/spec/services/decidim/proposals/proposal_serializer_spec.rb +++ b/decidim-proposals/spec/services/decidim/proposals/proposal_serializer_spec.rb @@ -47,6 +47,86 @@ module Proposals expect(serialized).to include(id: proposal.id) end + describe "author" do + context "when it is an official proposal" do + let!(:proposal) { create(:proposal, :official) } + + before do + component.participatory_space.organization.update!(name: { en: "My organization" }) + proposal.reload + end + + it "serializes the organization name" do + expect(serialized[:author]).to include(name: ["My organization"]) + end + + it "serializes the link to the organization" do + expect(serialized[:author]).to include(url: [root_url]) + end + end + + context "when it is a user" do + let!(:proposal) { create(:proposal, :participant_author) } + + before do + proposal.creator_author.update!(name: "John Doe") + proposal.reload + end + + it "serializes the user name" do + expect(serialized[:author]).to include(name: ["John Doe"]) + end + + it "serializes the link to its profile" do + expect(serialized[:author]).to include(url: [profile_url(proposal.creator_author.nickname)]) + end + end + + context "when it is multiple users" do + let!(:coauthorships) { create_list(:coauthorship, 3, coauthorable: proposal) } + + it "serializes the user names" do + expect(serialized[:author]).to include(name: proposal.authors.map(&:name)) + end + + it "serializes the link to the profiles" do + urls = proposal.authors.map { |author| profile_url(author.nickname) } + expect(serialized[:author]).to include(url: urls) + end + end + + context "when it is a meeting" do + let!(:proposal) { create(:proposal, :official_meeting) } + + it "serializes the title of the meeting" do + title = proposal.authors.map { |author| translated_attribute(author.title) } + expect(serialized[:author]).to include(name: title) + end + + it "serializes the link to the meeting" do + urls = proposal.authors.map { |meeting| meeting_url(meeting) } + expect(serialized[:author]).to include(url: urls) + end + end + + context "when it is a user group" do + let!(:proposal) { create(:proposal, :user_group_author) } + + before do + proposal.coauthorships.first.user_group.update!(name: "ACME", nickname: "acme") + proposal.reload + end + + it "serializes the user name of the user group" do + expect(serialized[:author]).to include(name: ["ACME"]) + end + + it "serializes the link to the profile of the user group" do + expect(serialized[:author]).to include(url: [profile_url("acme")]) + end + end + end + it "serializes the category" do expect(serialized[:category]).to include(id: category.id) expect(serialized[:category]).to include(name: category.name) @@ -235,6 +315,22 @@ module Proposals end end end + + def profile_url(nickname) + Decidim::Core::Engine.routes.url_helpers.profile_url(nickname, host:) + end + + def meeting_url(meeting) + Decidim::EngineRouter.main_proxy(meeting.component).meeting_url(id: meeting.id, host:) + end + + def root_url + Decidim::Core::Engine.routes.url_helpers.root_url(host:) + end + + def host + proposal.organization.host + end end end end From 972ba0f8c79506109b78b4ddf9611e9eebd48120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Mon, 27 May 2024 21:03:05 +0200 Subject: [PATCH 09/15] Fix external URL with a fragment (#12880) * Fix external URL with a fragment * Add page title for external URL warning page --- .../app/controllers/decidim/links_controller.rb | 14 +++++++++++++- decidim-core/app/views/decidim/links/new.html.erb | 2 ++ .../spec/system/external_domain_warning_spec.rb | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/decidim-core/app/controllers/decidim/links_controller.rb b/decidim-core/app/controllers/decidim/links_controller.rb index 90b0331c38d4a..79dac5f528094 100644 --- a/decidim-core/app/controllers/decidim/links_controller.rb +++ b/decidim-core/app/controllers/decidim/links_controller.rb @@ -37,7 +37,19 @@ def parse_url end def external_url - @external_url ||= URI.parse(URI::Parser.new.escape(params[:external_url])) + @external_url ||= URI.parse(escape_url(params[:external_url])) + end + + def escape_url(external_url) + before_fragment, fragment = external_url.split("#", 2) + escaped_before_fragment = URI::Parser.new.escape(before_fragment) + + if fragment + escaped_fragment = URI::Parser.new.escape(fragment) + "#{escaped_before_fragment}##{escaped_fragment}" + else + escaped_before_fragment + end end end end diff --git a/decidim-core/app/views/decidim/links/new.html.erb b/decidim-core/app/views/decidim/links/new.html.erb index def3f57c8f05a..20c8512c3b687 100644 --- a/decidim-core/app/views/decidim/links/new.html.erb +++ b/decidim-core/app/views/decidim/links/new.html.erb @@ -1,3 +1,5 @@ +<% add_decidim_page_title t("decidim.links.warning.title") %> + <%= render layout: "layouts/decidim/shared/layout_center" do %>
    diff --git a/decidim-core/spec/system/external_domain_warning_spec.rb b/decidim-core/spec/system/external_domain_warning_spec.rb index bf1af98d228e1..02dfc33da23eb 100644 --- a/decidim-core/spec/system/external_domain_warning_spec.rb +++ b/decidim-core/spec/system/external_domain_warning_spec.rb @@ -39,6 +39,18 @@ end end + context "when url has a fragment" do + let(:destination) { "https://example.org/test/#/bar/edit/12345" } + # URI need to be escaped, as if not the fragment will be ignored + let(:url) { "http://#{organization.host}/link?external_url=#{URI::Parser.new.escape(destination)}" } + + it "does not show invalid url alert" do + visit url + expect(page).to have_no_content("Invalid URL") + expect(page).to have_content("https://example.org/test/#/bar/edit/12345") + end + end + context "when url is invalid" do let(:invalid_url) { "http://#{organization.host}/link?external_url=foo" } From 4cee13b19b2e4344f939567c2d014849944768cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Mon, 27 May 2024 21:08:56 +0200 Subject: [PATCH 10/15] Remove unecessary accordion in Conferences' program (#12877) --- .../stylesheets/decidim/conferences/_program.scss | 6 +----- .../conference_program/_program_item.html.erb | 12 ++++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/decidim-conferences/app/packs/stylesheets/decidim/conferences/_program.scss b/decidim-conferences/app/packs/stylesheets/decidim/conferences/_program.scss index a8a0a32e4d08b..4ec534831a1a4 100644 --- a/decidim-conferences/app/packs/stylesheets/decidim/conferences/_program.scss +++ b/decidim-conferences/app/packs/stylesheets/decidim/conferences/_program.scss @@ -14,7 +14,7 @@ } &-category { - @apply h-10 w-full bg-background border-b-2 border-gray-3 text-center text-md text-gray-2 font-normal truncate; + @apply h-10 w-full bg-background-4 border-b-2 border-secondary text-center text-secondary font-semibold text-md truncate leading-10; &-container { @apply flex gap-2 [&>*]:grow [&>*]:min-w-0; @@ -23,10 +23,6 @@ &-content { @apply [&>a]:block [&>a]:py-4; } - - &[aria-expanded="true"] { - @apply bg-background-4 border-secondary text-secondary font-semibold; - } } &-attribute { diff --git a/decidim-conferences/app/views/decidim/conferences/conference_program/_program_item.html.erb b/decidim-conferences/app/views/decidim/conferences/conference_program/_program_item.html.erb index c55d665b06d4d..7022ed6c91884 100644 --- a/decidim-conferences/app/views/decidim/conferences/conference_program/_program_item.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/conference_program/_program_item.html.erb @@ -3,23 +3,23 @@
    <%= start_time.to_fs(:time) %> - <%= end_time.to_fs(:time) %>
    -
    +
    <% categories = meetings.map(&:category).uniq %> <% seed = SecureRandom.hex(3).to_s %> <% if categories.present? %>
      - <% categories.each_with_index do |category, i| %> + <% categories.each do |category| %>
    • - +
    <% end %> <% end %> - <% meetings.group_by(&:category).each_with_index do |categories_block, i| %> -
    + <% meetings.group_by(&:category).each do |categories_block| %> +
    <% categories_block.last.each do |meeting| %> <%= render partial: "program_meeting", locals: { meeting: } %> <% end %> From 8b788694cd869ff01d887e220dd403d89f57daad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Mon, 27 May 2024 21:10:58 +0200 Subject: [PATCH 11/15] Fix exception when going to debates new URL directly as non-logged user (#12864) * Fix exception when going to debates new URL directly as non-logged user * Add tests for meetings and proposals when a non-logged in user visits directly --- .../decidim/debates/debates_controller.rb | 1 + .../debates/debates_controller_spec.rb | 39 +++++++++++++++++++ .../meetings/meetings_controller_spec.rb | 10 +++++ .../proposals/proposals_controller_spec.rb | 10 +++++ 4 files changed, 60 insertions(+) create mode 100644 decidim-debates/spec/controllers/decidim/debates/debates_controller_spec.rb diff --git a/decidim-debates/app/controllers/decidim/debates/debates_controller.rb b/decidim-debates/app/controllers/decidim/debates/debates_controller.rb index 0029e1c95eeb0..ba1102effb0ac 100644 --- a/decidim-debates/app/controllers/decidim/debates/debates_controller.rb +++ b/decidim-debates/app/controllers/decidim/debates/debates_controller.rb @@ -13,6 +13,7 @@ class DebatesController < Decidim::Debates::ApplicationController include Decidim::Debates::Orderable helper_method :debates, :debate, :form_presenter, :paginated_debates, :close_debate_form + before_action :authenticate_user!, only: [:new, :create] def new enforce_permission_to :create, :debate diff --git a/decidim-debates/spec/controllers/decidim/debates/debates_controller_spec.rb b/decidim-debates/spec/controllers/decidim/debates/debates_controller_spec.rb new file mode 100644 index 0000000000000..01670bb35ba25 --- /dev/null +++ b/decidim-debates/spec/controllers/decidim/debates/debates_controller_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Debates + describe DebatesController do + routes { Decidim::Debates::Engine.routes } + + let(:user) { create(:user, :confirmed, organization: component.organization) } + + let(:debate_params) do + { + component_id: component.id + } + end + let(:params) { { debate: debate_params } } + + before do + request.env["decidim.current_organization"] = component.organization + request.env["decidim.current_participatory_space"] = component.participatory_space + request.env["decidim.current_component"] = component + stub_const("Decidim::Paginable::OPTIONS", [100]) + end + + describe "GET new" do + let(:component) { create(:debates_component, :with_creation_enabled) } + + context "when user is not logged in" do + it "redirects to the login page" do + get(:new) + expect(response).to have_http_status(:found) + expect(response.body).to have_text("You are being redirected") + end + end + end + end + end +end diff --git a/decidim-meetings/spec/controllers/decidim/meetings/meetings_controller_spec.rb b/decidim-meetings/spec/controllers/decidim/meetings/meetings_controller_spec.rb index 930add9e1cdad..be29839d26e91 100644 --- a/decidim-meetings/spec/controllers/decidim/meetings/meetings_controller_spec.rb +++ b/decidim-meetings/spec/controllers/decidim/meetings/meetings_controller_spec.rb @@ -142,4 +142,14 @@ end end end + + describe "#new" do + context "when user is not logged in" do + it "redirects to the login page" do + get(:new) + expect(response).to have_http_status(:found) + expect(response.body).to have_text("You are being redirected") + end + end + end end diff --git a/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb b/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb index 6d2abaeccb4eb..b6d1f49dc7387 100644 --- a/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb +++ b/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb @@ -105,6 +105,16 @@ module Proposals end end + context "when user is not logged in" do + let(:component) { create(:proposal_component, :with_creation_enabled) } + + it "redirects to the login page" do + get(:new) + expect(response).to have_http_status(:found) + expect(response.body).to have_text("You are being redirected") + end + end + describe "POST create" do before { sign_in user } From e4d529a0089b6961816393b421a49b7f0860d85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Mon, 27 May 2024 21:46:28 +0200 Subject: [PATCH 12/15] Prevent showing the dropdown menu when changing orientation of mobile devices (#12858) * Prevent showing the dropdown menu when changing orientation of mobile devices * Make the dropdown menu to work when changing orientation of mobile devices * Fix string capitalization in 'Filter and Search' * Fix rubocop offense * Fix a11y tests on dropdown menus with children element We need to disable focus in the children element of the hidden menu. If not, we have an AXE error: > aria-hidden-focus: ARIA hidden element must not be focusable or contain focusable elements --- .../accountability/results/_scope_filters.html.erb | 4 ++-- .../layouts/decidim/admin/_sidebar_menu.html.erb | 4 ++-- .../decidim/conferences/conferences/show.html.erb | 4 ++-- decidim-core/app/cells/decidim/nav_links/show.erb | 4 ++-- .../cells/decidim/resource_types_filter/show.erb | 4 ++-- decidim-core/app/packs/src/decidim/a11y.js | 14 ++++++++++++++ .../app/views/decidim/pages/_tabbed.html.erb | 4 ++-- .../app/views/decidim/searches/_filters.html.erb | 4 ++-- .../app/views/decidim/shared/_filters.html.erb | 4 ++-- .../app/views/decidim/shared/_orders.html.erb | 4 ++-- .../decidim/shared/_layout_user_profile.html.erb | 4 ++-- decidim-core/config/locales/en.yml | 2 +- 12 files changed, 35 insertions(+), 21 deletions(-) diff --git a/decidim-accountability/app/views/decidim/accountability/results/_scope_filters.html.erb b/decidim-accountability/app/views/decidim/accountability/results/_scope_filters.html.erb index 829adb5f9e045..56e0745f601be 100644 --- a/decidim-accountability/app/views/decidim/accountability/results/_scope_filters.html.erb +++ b/decidim-accountability/app/views/decidim/accountability/results/_scope_filters.html.erb @@ -4,7 +4,7 @@ <% if current_component.has_subscopes? %>
    - -
    diff --git a/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb b/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb index 2c2a63e0337f2..0ab884729db09 100644 --- a/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb @@ -24,12 +24,12 @@ edit_link( <%= content_for :aside do %>
    - -
    diff --git a/decidim-core/app/cells/decidim/nav_links/show.erb b/decidim-core/app/cells/decidim/nav_links/show.erb index d04dfdcabe000..6517e423268db 100644 --- a/decidim-core/app/cells/decidim/nav_links/show.erb +++ b/decidim-core/app/cells/decidim/nav_links/show.erb @@ -1,10 +1,10 @@
    - -