diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 03f62925a..81d6e8dbd 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -2,7 +2,11 @@ class PagesController < ApplicationController skip_authorization_check def show - render action: params[:id] + if @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id]) + render action: :custom_page + else + render action: params[:id] + end rescue ActionView::MissingTemplate head 404 end diff --git a/app/models/site_customization/page.rb b/app/models/site_customization/page.rb index 565e6352a..ea3003465 100644 --- a/app/models/site_customization/page.rb +++ b/app/models/site_customization/page.rb @@ -7,6 +7,7 @@ class SiteCustomization::Page < ActiveRecord::Base validates :status, presence: true, inclusion: { in: VALID_STATUSES } scope :published, -> { where(status: 'published').order('id DESC') } + scope :with_more_info_flag, -> { where(status: 'published', more_info_flag: true).order('id ASC') } def url "/#{slug}" diff --git a/app/views/admin/site_customization/pages/index.html.erb b/app/views/admin/site_customization/pages/index.html.erb index 356a1813b..eef3370e6 100644 --- a/app/views/admin/site_customization/pages/index.html.erb +++ b/app/views/admin/site_customization/pages/index.html.erb @@ -2,19 +2,12 @@ Admin - <%= t("admin.menu.site_customization.pages") %> <% end %> -
-
-
-

<%= t("admin.site_customization.pages.index.title") %>

-
-
- <%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button" %> -
-
+<%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button float-right margin-right" %> +

<%= t("admin.site_customization.pages.index.title") %>

<%= page_entries_info @pages %>

- +
@@ -33,7 +26,7 @@ - +
<%= t("admin.site_customization.pages.page.title") %> <%= I18n.l page.created_at, format: :short %> <%= I18n.l page.created_at, format: :short %><%= t("admin.legislation.processes.process.status_#{page.status}") %><%= t("admin.site_customization.pages.page.status_#{page.status}") %> <%= link_to t("admin.site_customization.pages.index.see_page"), page.url %> @@ -48,5 +41,3 @@
<%= paginate @pages %> - -
diff --git a/app/views/pages/custom_page.html.erb b/app/views/pages/custom_page.html.erb new file mode 100644 index 000000000..f14eba7d9 --- /dev/null +++ b/app/views/pages/custom_page.html.erb @@ -0,0 +1,15 @@ +<% provide :title do %><%= @custom_page.title %><% end %> + +
+ +
+

<%= @custom_page.title %>

+

<%= @custom_page.subtitle %>

+ + <%= raw @custom_page.content %> +
+ +
+ <%= render '/shared/print' if @custom_page.print_content_flag %> +
+
diff --git a/app/views/pages/more_info/_other.html.erb b/app/views/pages/more_info/_other.html.erb index d0718294c..5501c9e31 100644 --- a/app/views/pages/more_info/_other.html.erb +++ b/app/views/pages/more_info/_other.html.erb @@ -4,4 +4,8 @@
  • <%= link_to t("pages.more_info.other.how_to_use", org_name: setting['org_name']), faq_path %>
  • <%= link_to t("pages.more_info.other.facts"), participation_facts_path %>
  • <%= link_to t("pages.more_info.other.world"), participation_world_path %>
  • + + <% SiteCustomization::Page.with_more_info_flag.each do |custom_page| %> +
  • <%= link_to custom_page.title, page_path(custom_page.slug) %>
  • + <% end %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index f95f0a550..85844f948 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -152,6 +152,7 @@ ignore_unused: - 'views.pagination.*' # kaminari - 'shared.suggest.*' - 'invisible_captcha.*' + - 'admin.site_customization.pages.page.status_*' # - '{devise,kaminari,will_paginate}.*' # - 'simple_form.{yes,no}' # - 'simple_form.{placeholders,hints,labels}.*' diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index d44179ce8..be2f9280e 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -508,3 +508,5 @@ en: status: Status title: Title updated_at: Updated at + status_draft: Draft + status_published: Published diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index f93433546..7b14bf90a 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -508,3 +508,5 @@ es: status: Estado title: Título updated_at: Última actualización + status_draft: Borrador + status_published: Publicada diff --git a/config/routes.rb b/config/routes.rb index e31bd86a0..af9ac8a08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -224,7 +224,7 @@ Rails.application.routes.draw do resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy] namespace :site_customization do - resources :pages + resources :pages, except: [:show] end end diff --git a/spec/features/admin/site_customization/pages_spec.rb b/spec/features/admin/site_customization/pages_spec.rb index b9ebeb273..20b817f50 100644 --- a/spec/features/admin/site_customization/pages_spec.rb +++ b/spec/features/admin/site_customization/pages_spec.rb @@ -1,50 +1,48 @@ require 'rails_helper' -feature 'Admin custom pages' do +feature "Admin custom pages" do background do admin = create(:administrator) login_as(admin.user) end - context "Index" do - scenario 'Displaying custom pages' do - custom_page = create(:site_customization_page) - visit admin_site_customization_pages_path + scenario "Index" do + custom_page = create(:site_customization_page) + visit admin_site_customization_pages_path - expect(page).to have_content(custom_page.title) - end + expect(page).to have_content(custom_page.title) end - context 'Create' do - scenario 'Valid custom page' do + context "Create" do + scenario "Valid custom page" do visit admin_root_path - within('#side_menu') do + within("#side_menu") do click_link "Custom Pages" end - expect(page).to_not have_content 'An example custom page' + expect(page).to_not have_content "An example custom page" click_link "Create new page" - fill_in 'site_customization_page_title', with: 'An example custom page' - fill_in 'site_customization_page_subtitle', with: 'Page subtitle' - fill_in 'site_customization_page_slug', with: 'example-page' - fill_in 'site_customization_page_content', with: 'This page is about...' + fill_in "site_customization_page_title", with: "An example custom page" + fill_in "site_customization_page_subtitle", with: "Page subtitle" + fill_in "site_customization_page_slug", with: "example-page" + fill_in "site_customization_page_content", with: "This page is about..." - click_button 'Create Custom page' + click_button "Create Custom page" - expect(page).to have_content 'An example custom page' + expect(page).to have_content "An example custom page" end end - context 'Update' do - scenario 'Valid custom page' do - custom_page = create(:site_customization_page, title: 'An example custom page') + context "Update" do + scenario "Valid custom page" do + custom_page = create(:site_customization_page, title: "An example custom page") visit admin_root_path - within('#side_menu') do + within("#side_menu") do click_link "Custom Pages" end @@ -52,11 +50,20 @@ feature 'Admin custom pages' do expect(page).to have_selector("h2", text: "An example custom page") - fill_in 'site_customization_page_title', with: 'Another example custom page' + fill_in "site_customization_page_title", with: "Another example custom page" click_button "Update Custom page" expect(page).to have_content "Page updated successfully" - expect(page).to have_content 'Another example custom page' + expect(page).to have_content "Another example custom page" end end + + scenario "Index" do + custom_page = create(:site_customization_page, title: "An example custom page") + visit edit_admin_site_customization_page_path(custom_page) + + click_button "Delete" + + expect(page).to_not have_content("An example custom page") + end end diff --git a/spec/features/site_customization/custom_pages_spec.rb b/spec/features/site_customization/custom_pages_spec.rb new file mode 100644 index 000000000..2e2fac84a --- /dev/null +++ b/spec/features/site_customization/custom_pages_spec.rb @@ -0,0 +1,102 @@ +require 'rails_helper' + +feature "Custom Pages" do + context "Override existing page" do + scenario "See default content when custom page is not published" do + custom_page = create(:site_customization_page, + slug: "conditions", + title: "Custom conditions", + content: "New text for conditions page", + print_content_flag: true + ) + + visit custom_page.url + + expect(page).to have_title("Terms of use") + expect(page).to have_selector("h1", text: "Terms and conditions of use") + expect(page).to have_content("Página de información sobre las condiciones de uso, privacidad y protección de datos personales.") + expect(page).to have_content("Print this info") + end + + scenario "See custom content when custom page is published" do + custom_page = create(:site_customization_page, :published, + slug: "conditions", + title: "Custom conditions", + content: "New text for conditions page", + print_content_flag: true + ) + + visit custom_page.url + + expect(page).to have_title("Custom conditions") + expect(page).to have_selector("h1", text: "Custom conditions") + expect(page).to have_content("New text for conditions page") + expect(page).to have_content("Print this info") + end + end + + context "New custom page" do + context "Draft" do + scenario "See page" do + custom_page = create(:site_customization_page, + slug: "other-slug", + title: "Custom page", + content: "Text for new custom page", + print_content_flag: false + ) + + visit custom_page.url + + expect(page.status_code).to eq(404) + end + end + + context "Published" do + scenario "See page" do + custom_page = create(:site_customization_page, :published, + slug: "other-slug", + title: "Custom page", + content: "Text for new custom page", + print_content_flag: false + ) + + visit custom_page.url + + expect(page).to have_title("Custom page") + expect(page).to have_selector("h1", text: "Custom page") + expect(page).to have_content("Text for new custom page") + expect(page).to_not have_content("Print this info") + end + + scenario "Listed in more information page" do + custom_page = create(:site_customization_page, :published, + slug: "another-slug", title: "Another custom page", + subtitle: "Subtitle for custom page", + more_info_flag: true + ) + + visit more_info_path + + expect(page).to have_content("Another custom page") + end + + scenario "Not listed in more information page" do + custom_page = create(:site_customization_page, :published, + slug: "another-slug", title: "Another custom page", + subtitle: "Subtitle for custom page", + more_info_flag: false + ) + + visit more_info_path + + expect(page).to_not have_content("Another custom page") + + visit custom_page.url + + expect(page).to have_title("Another custom page") + expect(page).to have_selector("h1", text: "Another custom page") + expect(page).to have_content("Subtitle for custom page") + end + end + end +end