From 5c2985e86c11501e45fa0714026344dd782fe310 Mon Sep 17 00:00:00 2001 From: Harrison Hassig Date: Tue, 5 Nov 2024 18:39:36 +0100 Subject: [PATCH 1/2] Override of pages_controller for accessibility redirect --- Gemfile.lock | 2 +- app/controllers/decidim/pages_controller.rb | 57 +++++++++++++++++++++ config/routes.rb | 2 + spec/lib/overrides_spec.rb | 3 +- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 app/controllers/decidim/pages_controller.rb diff --git a/Gemfile.lock b/Gemfile.lock index bbccfad20..6ebd3b570 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/AjuntamentdeBarcelona/decidim - revision: 739d2cc1c0faa65a7e8d0788944165debd416bd1 + revision: 4bfc73be0724b60918f93867ae0a03d662aea1fd branch: release/0.28-stable-bcn specs: decidim (0.28.4) diff --git a/app/controllers/decidim/pages_controller.rb b/app/controllers/decidim/pages_controller.rb new file mode 100644 index 000000000..58a025425 --- /dev/null +++ b/app/controllers/decidim/pages_controller.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Decidim + # This controller serves static pages using HighVoltage. + class PagesController < Decidim::ApplicationController + layout "layouts/decidim/application" + + helper_method :page, :pages, :page_content_blocks + helper CtaButtonHelper + helper Decidim::SanitizeHelper + + before_action :legacy_redirect, :set_default_request_format, :accessibility_redirect + + def index + enforce_permission_to :read, :public_page + @topics = StaticPageTopic.where(organization: current_organization) + @orphan_pages = StaticPage.where(topic: nil, organization: current_organization) + end + + def show + @page = current_organization.static_pages.find_by!(slug: params[:id]) + enforce_permission_to :read, :public_page, page: @page + @topic = @page.topic + @pages = @topic&.pages + raise + end + + private + + def legacy_redirect + redirect_to decidim.page_path("terms-of-service") if params[:id] == "terms-and-conditions" + end + + def accessibility_redirect + if params[:id] == "accessibilitat" + if params[:locale] == "es" + redirect_to "https://ajuntament.barcelona.cat/declaracio-accessibilitat/es/decidim-barcelona" + else + redirect_to "https://ajuntament.barcelona.cat/declaracio-accessibilitat/ca/decidim-barcelona" + end + end + end + + def set_default_request_format + request.format = :html + end + + def page_content_blocks + return [] unless Decidim.page_blocks.include?(@page.slug) + + @page_content_blocks ||= Decidim::ContentBlock.published + .for_scope(:static_page, organization: current_organization) + .where(scoped_resource_id: @page.id) + .reject { |content_block| content_block.manifest.nil? } + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 7427c3e8c..46ad77feb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,6 +43,8 @@ get "/pages/faq", to: redirect("/pages/decidim") + # get "/pages/accessibilitat", to: redirect("https://ajuntament.barcelona.cat/declaracio-accessibilitat/es/decidim-barcelona") + scope "/processes/:participatory_process_slug/f/:component_id" do get :export_results, to: "export_results#csv" diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index 26b3da048..a3752cf0b 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -28,7 +28,8 @@ "/app/cells/decidim/activities_cell.rb" => "dd17416a8d1efe7f26b1e759613e4db4", "/app/cells/decidim/user_profile_cell.rb" => "71216a17c7eea8dd8ebc1ea3907efaef", "/lib/decidim/search_resource_fields_mapper.rb" => "ff2cc476eb72c2942cf2e69ae21b84fa", - "/app/views/layouts/decidim/header/_main.html.erb" => "a6496ec11e073062743a927ee3c8bd3c" + "/app/views/layouts/decidim/header/_main.html.erb" => "a6496ec11e073062743a927ee3c8bd3c", + "/app/controllers/decidim/pages_controller.rb" => "f91d3b04c66db579dfaa7f230d28a381" } }, { From 4db3989231b585a703cadf60627f3702a0db9540 Mon Sep 17 00:00:00 2001 From: Harrison Hassig Date: Tue, 5 Nov 2024 18:52:11 +0100 Subject: [PATCH 2/2] Remove comment from routes.rb --- config/routes.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 46ad77feb..7427c3e8c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,8 +43,6 @@ get "/pages/faq", to: redirect("/pages/decidim") - # get "/pages/accessibilitat", to: redirect("https://ajuntament.barcelona.cat/declaracio-accessibilitat/es/decidim-barcelona") - scope "/processes/:participatory_process_slug/f/:component_id" do get :export_results, to: "export_results#csv"