From 87be6f302cc9ff8295a96ec5f7ba2353bea6f791 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 27 Feb 2019 10:47:58 +0100 Subject: [PATCH] Add default site customization pages From now on these static pages: `/privacy' `/conditions' `/accesibility' `/help/faq' `/welcome' have been moved to the DB and can be modified easily by any administrator in `/admin/site_customization/pages' --- app/assets/javascripts/ckeditor/config.js | 2 +- app/controllers/welcome_controller.rb | 7 ++ app/views/pages/accessibility.html.erb | 114 ------------------ app/views/pages/conditions.html.erb | 17 --- app/views/pages/help/faq/index.html.erb | 21 ---- app/views/pages/privacy.html.erb | 33 ----- app/views/welcome/welcome.html.erb | 50 -------- config/i18n-tasks.yml | 5 +- config/locales/en/general.yml | 5 +- config/locales/en/pages.yml | 18 +-- config/locales/es/general.yml | 5 +- config/locales/es/pages.yml | 25 +--- config/routes.rb | 2 +- db/pages.rb | 7 ++ db/pages/accessibility.rb | 96 +++++++++++++++ db/pages/conditions.rb | 8 ++ db/pages/faq.rb | 6 + db/pages/privacy.rb | 7 ++ db/pages/welcome_level_three_verified.rb | 19 +++ db/pages/welcome_level_two_verified.rb | 25 ++++ db/pages/welcome_not_verified.rb | 25 ++++ db/seeds.rb | 3 + lib/admin_wysiwyg_sanitizer.rb | 4 +- lib/tasks/db.rake | 5 + spec/controllers/pages_controller_spec.rb | 2 +- spec/controllers/welcome_controller_spec.rb | 0 .../admin/site_customization/pages_spec.rb | 31 ++++- .../site_customization/custom_pages_spec.rb | 33 ----- spec/features/welcome_spec.rb | 23 +++- spec/lib/admin_wysiwyg_sanitizer_spec.rb | 21 ++++ spec/lib/tasks/db_spec.rb | 15 +++ 31 files changed, 306 insertions(+), 328 deletions(-) delete mode 100644 app/views/pages/accessibility.html.erb delete mode 100644 app/views/pages/conditions.html.erb delete mode 100644 app/views/pages/help/faq/index.html.erb delete mode 100644 app/views/pages/privacy.html.erb delete mode 100644 app/views/welcome/welcome.html.erb create mode 100644 db/pages.rb create mode 100644 db/pages/accessibility.rb create mode 100644 db/pages/conditions.rb create mode 100644 db/pages/faq.rb create mode 100644 db/pages/privacy.rb create mode 100644 db/pages/welcome_level_three_verified.rb create mode 100644 db/pages/welcome_level_two_verified.rb create mode 100644 db/pages/welcome_not_verified.rb create mode 100644 spec/controllers/welcome_controller_spec.rb create mode 100644 spec/lib/tasks/db_spec.rb diff --git a/app/assets/javascripts/ckeditor/config.js b/app/assets/javascripts/ckeditor/config.js index 1ec099fc0..631cad7d7 100644 --- a/app/assets/javascripts/ckeditor/config.js +++ b/app/assets/javascripts/ckeditor/config.js @@ -98,7 +98,7 @@ CKEDITOR.editorConfig = function( config ) ]; config.toolbar_admin = config.toolbar_mini.concat([ - { name: 'insert', items: [ 'Image' ] } + { name: 'insert', items: [ 'Image', 'Table' ] } ]); config.toolbar = "mini"; diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 8d19394d7..ce17e10bc 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -12,6 +12,13 @@ class WelcomeController < ApplicationController end def welcome + if current_user.level_three_verified? + redirect_to page_path("welcome_level_three_verified") + elsif current_user.level_two_or_three_verified? + redirect_to page_path("welcome_level_two_verified") + else + redirect_to page_path("welcome_not_verified") + end end def verification diff --git a/app/views/pages/accessibility.html.erb b/app/views/pages/accessibility.html.erb deleted file mode 100644 index fe28dbc74..000000000 --- a/app/views/pages/accessibility.html.erb +++ /dev/null @@ -1,114 +0,0 @@ -<% provide :title do %><%= t("pages.titles.accessibility") %><% end %> -<% content_for :canonical do %> - <%= render "shared/canonical", href: page_url("accessibility") %> -<% end %> - -
-
- -

<%= t("pages.accessibility.title") %>

- <%= simple_format(t("pages.accessibility.description")) %> - -
    - <% t("pages.accessibility.examples").each do |example| %> -
  • <%= example %>
  • - <% end %> -
- -

<%= t("pages.accessibility.keyboard_shortcuts.title") %>

- -

<%= t("pages.accessibility.keyboard_shortcuts.navigation_table.description") %>

- -
- - - - - - - - - - <% t("pages.accessibility.keyboard_shortcuts.navigation_table.rows").each do |row| %> - - - - - <% end %> - -
- <%= t("pages.accessibility.keyboard_shortcuts.navigation_table.caption") %> -
- <%= t("pages.accessibility.keyboard_shortcuts.navigation_table.key_header") %> - - <%= t("pages.accessibility.keyboard_shortcuts.navigation_table.page_header") %> -
<%= row[:key_column] %><%= row[:page_column] %>
-
- -

<%= t("pages.accessibility.keyboard_shortcuts.browser_table.description") %>

- -
- - - - - - - - - - <% t("pages.accessibility.keyboard_shortcuts.browser_table.rows").each do |row| %> - - - - - <% end %> - -
- <%= t("pages.accessibility.keyboard_shortcuts.browser_table.caption") %> -
- <%= t("pages.accessibility.keyboard_shortcuts.browser_table.browser_header") %> - - <%= t("pages.accessibility.keyboard_shortcuts.browser_table.key_header") %> -
<%= row[:browser_column] %><%= row[:key_column] %>
-
- -

<%= t("pages.accessibility.textsize.title") %>

-

<%= t("pages.accessibility.textsize.browser_settings_table.description") %>

- -
- - - - - - - - - <% t("pages.accessibility.textsize.browser_settings_table.rows").each do |row| %> - - - - - <% end %> - -
- <%= t("pages.accessibility.textsize.browser_settings_table.browser_header") %> - - <%= t("pages.accessibility.textsize.browser_settings_table.action_header") %> -
<%= row[:browser_column] %><%= row[:action_column] %>
-
- -

<%= t("pages.accessibility.textsize.browser_shortcuts_table.description") %>

- -
    - <% t("pages.accessibility.textsize.browser_shortcuts_table.rows").each do |row| %> -
  • <%= row[:shortcut_column] %> <%= row[:description_column] %>
  • - <% end %> -
- -

<%= t("pages.accessibility.compatibility.title") %>

- -

<%= t("pages.accessibility.compatibility.description_html") %>

-
-
diff --git a/app/views/pages/conditions.html.erb b/app/views/pages/conditions.html.erb deleted file mode 100644 index 340513d1e..000000000 --- a/app/views/pages/conditions.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<% provide :title do %><%= t("pages.titles.conditions") %><% end %> -<% content_for :canonical do %> - <%= render "shared/canonical", href: page_url("conditions") %> -<% end %> - -
- -
-

<%= t("pages.conditions.title") %>

-

<%= t("pages.conditions.subtitle") %>

-

<%= t("pages.conditions.description") %>

-
- -
- <%= render '/shared/print' %> -
-
diff --git a/app/views/pages/help/faq/index.html.erb b/app/views/pages/help/faq/index.html.erb deleted file mode 100644 index 36c7d98b8..000000000 --- a/app/views/pages/help/faq/index.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<% content_for :canonical do %> - <%= render "shared/canonical", href: faq_url %> -<% end %> - -
- - -
-

<%= t("pages.help.faq.page.title") %>

-

<%= t("pages.help.faq.page.description") %>

- -

<%= t("pages.help.faq.page.faq_1_title") %>

-

<%= t("pages.help.faq.page.faq_1_description") %>

-
-
diff --git a/app/views/pages/privacy.html.erb b/app/views/pages/privacy.html.erb deleted file mode 100644 index 3c76d3c18..000000000 --- a/app/views/pages/privacy.html.erb +++ /dev/null @@ -1,33 +0,0 @@ -<% provide :title do %><%= t("pages.titles.privacy") %><% end %> -<% content_for :canonical do %> - <%= render "shared/canonical", href: page_url("privacy") %> -<% end %> - -
- -
-

<%= t("pages.privacy.title") %>

-

<%= t("pages.privacy.subtitle") %>

- -
    - <% t("pages.privacy.info_items").each do |item| %> - <% if item.key? :text %> -
  1. <%= item[:text] %>
  2. - <% else %> -
      - <% item[:subitems].each do |subitem| %> -
    • - <%= subitem[:field] %> - <%= subitem[:description] %> -
    • - <% end %> -
    - <% end %> - <% end %> -
-
- -
- <%= render '/shared/print' %> -
-
diff --git a/app/views/welcome/welcome.html.erb b/app/views/welcome/welcome.html.erb deleted file mode 100644 index c8a3641a4..000000000 --- a/app/views/welcome/welcome.html.erb +++ /dev/null @@ -1,50 +0,0 @@ -

<%= t("welcome.welcome.title") %>

- -
-

<%= t("welcome.welcome.user_permission_info") %>

- - -

- <%= t("welcome.welcome.user_permission_verify_info") %> -

- -

- <%= t("welcome.welcome.user_permission_verify") %> -

- - <% if current_user.level_three_verified? %> -

- - <%= t("account.show.verified_account") %> -

- <% else %> - <%= link_to(t("welcome.welcome.user_permission_verify_my_account"), verification_path, class: "button success radius expand") %> - <% end %> - -

- <% if feature?(:help_page) %> - <%= link_to t("welcome.welcome.go_to_index"), help_path %> - <% else %> - <%= link_to t("welcome.welcome.go_to_index"), root_path %> - <% end %> -

-
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index b7b6ca9d2..8377deb4f 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -73,8 +73,9 @@ data: # Find translate calls search: ## Paths or `File.find` patterns to search in: - # paths: - # - app/ + paths: + - app/ + - db/pages/ ## Root directories for relative keys resolution. # relative_roots: diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index c8ce0d561..d9c1d7949 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -799,13 +799,14 @@ en: question: Do you already have an account in %{org_name}? title: Account verification welcome: - go_to_index: See proposals and debates + go_to_index: Not now, go to index page + start_using_consul: Go to index page title: Participate user_permission_debates: Participate on debates user_permission_info: With your account you can... user_permission_proposal: Create new proposals user_permission_support_proposal: Support proposals* - user_permission_verify: To perform all the actions verify your account. + user_permission_verify: "To perform the following actions verify your account." user_permission_verify_info: "* Only for users on Census." user_permission_verify_my_account: Verify my account user_permission_votes: Participate on final voting diff --git a/config/locales/en/pages.yml b/config/locales/en/pages.yml index 48ed93fed..af20e3ffd 100644 --- a/config/locales/en/pages.yml +++ b/config/locales/en/pages.yml @@ -51,8 +51,6 @@ en: page: title: "Frequently Asked Questions" description: "Use this page to resolve the common FAQs to the users of site." - faq_1_title: "Question 1" - faq_1_description: "This is an example for the description of question one." other: title: "Other information of interest" how_to_use: "Use %{org_name} in your city" @@ -67,18 +65,7 @@ en: how_to_use: Use it in your local government privacy: title: Privacy Policy - subtitle: INFORMATION REGARDING DATA PRIVACY - info_items: - - text: The navigation through the information available in the Open Government Portal is anonymous. - - text: To use the services contained in the Open Government Portal, the user must register and previously provide personal data according to the specific information included in each type of registration. - - text: 'The data provided will be incorporated and processed by the City Council in accordance with the description of the following file:' - - subitems: - - field: 'File name:' - description: NAME OF THE FILE - - field: 'Purpose of the file:' - description: Managing participatory processes to control the qualification of the people participating in them and merely numerical and statistical recount of the results derived from citizen participation processes. - - field: 'Institution in charge of the file:' - description: INSTITUTION IN CHARGE OF THE FILE + subtitle: "Information page on privacy" accessibility: title: Accessibility description: |- @@ -154,10 +141,7 @@ en: title: Compatibility with standards and visual design description_html: 'All pages of this website comply with the Accessibility Guidelines or General Principles of Accessible Design established by the Working Group WAI belonging to W3C.' titles: - accessibility: Accessibility - conditions: Terms of use help: "What is %{org}? - Citizen participation" - privacy: Privacy Policy verify: code: Code you received in letter email: Email diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 5b4e4d99f..8c0aad6f9 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -798,13 +798,14 @@ es: question: '¿Tienes ya una cuenta en %{org_name}?' title: Verificación de cuenta welcome: - go_to_index: Ahora no, ver propuestas + go_to_index: Ahora no, ir a la página de inicio + start_using_consul: Ir a la página de inicio title: Empieza a participar user_permission_debates: Participar en debates user_permission_info: Con tu cuenta ya puedes... user_permission_proposal: Crear nuevas propuestas user_permission_support_proposal: Apoyar propuestas* - user_permission_verify: Para poder realizar todas las acciones, verifica tu cuenta. + user_permission_verify: "Para poder realizar las siguientes acciones, verifica tu cuenta." user_permission_verify_info: "* Sólo usuarios empadronados." user_permission_verify_my_account: Verificar mi cuenta user_permission_votes: Participar en las votaciones finales* diff --git a/config/locales/es/pages.yml b/config/locales/es/pages.yml index e5e6a82db..e625c1058 100644 --- a/config/locales/es/pages.yml +++ b/config/locales/es/pages.yml @@ -51,8 +51,6 @@ es: page: title: "Preguntas Frecuentes" description: "Utiliza esta página para resolver las Preguntas frecuentes a los usuarios del sitio." - faq_1_title: "Pregunta 1" - faq_1_description: "Este es un ejemplo para la descripción de la pregunta uno." other: title: "Otra información de interés" how_to_use: "Utiliza %{org_name} en tu municipio" @@ -67,25 +65,7 @@ es: how_to_use: Utilízalo en tu municipio privacy: title: Política de privacidad - subtitle: AVISO DE PROTECCIÓN DE DATOS - info_items: - - - text: La navegación por la informacion disponible en el Portal de Gobierno Abierto es anónima. - - - text: Para utilizar los servicios contenidos en el Portal de Gobierno Abierto el usuario deberá darse de alta y proporcionar previamente los datos de carácter personal segun la informacion especifica que consta en cada tipo de alta. - - - text: 'Los datos aportados serán incorporados y tratados por el Ayuntamiento de acuerdo con la descripción del fichero siguiente:' - - - subitems: - - - field: 'Nombre del fichero/tratamiento:' - description: NOMBRE DEL FICHERO - - - field: 'Finalidad del fichero/tratamiento:' - description: Gestionar los procesos participativos para el control de la habilitación de las personas que participan en los mismos y recuento meramente numérico y estadístico de los resultados derivados de los procesos de participación ciudadana. - - - field: 'Órgano responsable:' - description: ÓRGANO RESPONSABLE + subtitle: Página de información de protección de datos accessibility: title: Accesibilidad description: |- @@ -179,10 +159,7 @@ es: title: Compatibilidad con estándares y diseño visual description_html: 'Todas las páginas de este sitio web cumplen con las Pautas de Accesibilidad o Principios Generales de Diseño Accesible establecidas por el Grupo de Trabajo WAI perteneciente al W3C.' titles: - accessibility: Accesibilidad - conditions: Condiciones de uso help: "¿Qué es %{org}? - Participación ciudadana" - privacy: Política de privacidad verify: code: Código que has recibido en tu carta email: Email diff --git a/config/routes.rb b/config/routes.rb index 9d9a345dc..386f6044e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,7 +45,7 @@ Rails.application.routes.draw do # More info pages get 'help', to: 'pages#show', id: 'help/index', as: 'help' get 'help/how-to-use', to: 'pages#show', id: 'help/how_to_use/index', as: 'how_to_use' - get 'help/faq', to: 'pages#show', id: 'help/faq/index', as: 'faq' + get "help/faq", to: "pages#show", id: "faq", as: "faq" # Static pages resources :pages, path: '/', only: [:show] diff --git a/db/pages.rb b/db/pages.rb new file mode 100644 index 000000000..2fa21000f --- /dev/null +++ b/db/pages.rb @@ -0,0 +1,7 @@ +load Rails.root.join("db", "pages", "welcome_level_three_verified.rb") +load Rails.root.join("db", "pages", "welcome_level_two_verified.rb") +load Rails.root.join("db", "pages", "welcome_not_verified.rb") +load Rails.root.join("db", "pages", "accessibility.rb") +load Rails.root.join("db", "pages", "conditions.rb") +load Rails.root.join("db", "pages", "privacy.rb") +load Rails.root.join("db", "pages", "faq.rb") diff --git a/db/pages/accessibility.rb b/db/pages/accessibility.rb new file mode 100644 index 000000000..853ec75d7 --- /dev/null +++ b/db/pages/accessibility.rb @@ -0,0 +1,96 @@ +if SiteCustomization::Page.find_by_slug("accessibility").nil? + page = SiteCustomization::Page.new(slug: "accessibility", status: "published") + page.title = I18n.t("pages.accessibility.title") + + content = "" + I18n.t("pages.accessibility.description").each_line do |line| + content << "

#{line}

" + end + content << " +

#{I18n.t("pages.accessibility.keyboard_shortcuts.title")}

+

#{I18n.t("pages.accessibility.keyboard_shortcuts.navigation_table.description")}

+ + + + + + + + + " + I18n.t("pages.accessibility.keyboard_shortcuts.navigation_table.rows").each do |row| + content << " + + + " + end + content << " +
+ #{I18n.t("pages.accessibility.keyboard_shortcuts.navigation_table.caption")} +
+ #{I18n.t("pages.accessibility.keyboard_shortcuts.navigation_table.key_header")} + + #{I18n.t("pages.accessibility.keyboard_shortcuts.navigation_table.page_header")} +
#{row[:key_column]}#{row[:page_column]}
+

#{I18n.t("pages.accessibility.keyboard_shortcuts.browser_table.description")}

+ + + + + + + + + " + I18n.t("pages.accessibility.keyboard_shortcuts.browser_table.rows").each do |row| + content << " + + + " + end + content << " +
+ #{I18n.t("pages.accessibility.keyboard_shortcuts.browser_table.caption")} +
+ #{I18n.t("pages.accessibility.keyboard_shortcuts.browser_table.browser_header")} + + #{I18n.t("pages.accessibility.keyboard_shortcuts.browser_table.key_header")} +
#{row[:browser_column]}#{row[:key_column]}
+

#{I18n.t("pages.accessibility.textsize.title")}

+

#{I18n.t("pages.accessibility.textsize.browser_settings_table.description")}

+ + + + + + + + " + I18n.t("pages.accessibility.textsize.browser_settings_table.rows").each do |row| + content << " + + + " + end + content << " +
+ #{I18n.t("pages.accessibility.textsize.browser_settings_table.browser_header")} + + #{I18n.t("pages.accessibility.textsize.browser_settings_table.action_header")} +
#{row[:browser_column]}#{row[:action_column]}
" + content << "

#{I18n.t("pages.accessibility.textsize.browser_shortcuts_table.description")}

+ +

#{I18n.t("pages.accessibility.compatibility.title")}

+

#{I18n.t("pages.accessibility.compatibility.description_html")}

" + + page.content = content + page.save! +end diff --git a/db/pages/conditions.rb b/db/pages/conditions.rb new file mode 100644 index 000000000..8a57b63cc --- /dev/null +++ b/db/pages/conditions.rb @@ -0,0 +1,8 @@ +if SiteCustomization::Page.find_by_slug("conditions").nil? + page = SiteCustomization::Page.new(slug: "conditions", status: "published") + page.print_content_flag = true + page.title = I18n.t("pages.conditions.title") + page.subtitle = I18n.t("pages.conditions.subtitle") + page.content = "

#{I18n.t("pages.conditions.description")}

" + page.save! +end diff --git a/db/pages/faq.rb b/db/pages/faq.rb new file mode 100644 index 000000000..6479e1b57 --- /dev/null +++ b/db/pages/faq.rb @@ -0,0 +1,6 @@ +if SiteCustomization::Page.find_by_slug("faq").nil? + page = SiteCustomization::Page.new(slug: "faq", status: "published") + page.title = I18n.t("pages.help.faq.page.title") + page.content = "

#{I18n.t("pages.help.faq.page.description")}

" + page.save! +end diff --git a/db/pages/privacy.rb b/db/pages/privacy.rb new file mode 100644 index 000000000..f06b1687c --- /dev/null +++ b/db/pages/privacy.rb @@ -0,0 +1,7 @@ +if SiteCustomization::Page.find_by_slug("privacy").nil? + page = SiteCustomization::Page.new(slug: "privacy", status: "published") + page.print_content_flag = true + page.title = I18n.t("pages.privacy.title") + page.content = I18n.t("pages.privacy.subtitle") + page.save! +end diff --git a/db/pages/welcome_level_three_verified.rb b/db/pages/welcome_level_three_verified.rb new file mode 100644 index 000000000..2c00e4fb0 --- /dev/null +++ b/db/pages/welcome_level_three_verified.rb @@ -0,0 +1,19 @@ +if SiteCustomization::Page.find_by_slug("welcome_level_three_verified").nil? + page = SiteCustomization::Page.new(slug: "welcome_level_three_verified", status: "published") + page.title = I18n.t("welcome.welcome.title") + + page.content = "

#{I18n.t("welcome.welcome.user_permission_info")}

+ + +

#{I18n.t("welcome.welcome.user_permission_verify_info")}

+ +

#{I18n.t("account.show.verified_account")}

+ +

#{I18n.t("welcome.welcome.start_using_consul")}

" + page.save! +end diff --git a/db/pages/welcome_level_two_verified.rb b/db/pages/welcome_level_two_verified.rb new file mode 100644 index 000000000..911a0c850 --- /dev/null +++ b/db/pages/welcome_level_two_verified.rb @@ -0,0 +1,25 @@ +if SiteCustomization::Page.find_by_slug("welcome_level_two_verified").nil? + page = SiteCustomization::Page.new(slug: "welcome_level_two_verified", status: "published") + page.title = I18n.t("welcome.welcome.title") + + page.content = "

#{I18n.t("welcome.welcome.user_permission_info")}

+ + +

#{I18n.t("welcome.welcome.user_permission_verify")}

+ + +

#{I18n.t("welcome.welcome.user_permission_verify_info")}

+ + + #{I18n.t("welcome.welcome.user_permission_verify_my_account")} + + +

#{I18n.t("welcome.welcome.go_to_index")}

" + page.save! +end diff --git a/db/pages/welcome_not_verified.rb b/db/pages/welcome_not_verified.rb new file mode 100644 index 000000000..51df2ac39 --- /dev/null +++ b/db/pages/welcome_not_verified.rb @@ -0,0 +1,25 @@ +if SiteCustomization::Page.find_by_slug("welcome_not_verified").nil? + page = SiteCustomization::Page.new(slug: "welcome_not_verified", status: "published") + page.title = I18n.t("welcome.welcome.title") + + page.content = "

#{I18n.t("welcome.welcome.user_permission_info")}

+ + +

#{I18n.t("welcome.welcome.user_permission_verify")}

+ + +

#{I18n.t("welcome.welcome.user_permission_verify_info")}

+ + + #{I18n.t("welcome.welcome.user_permission_verify_my_account")} + + +

#{I18n.t("welcome.welcome.go_to_index")}

" + page.save! +end diff --git a/db/seeds.rb b/db/seeds.rb index f59291f64..6a9957c1c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -126,3 +126,6 @@ WebSection.create(name: "debates") WebSection.create(name: "proposals") WebSection.create(name: "budgets") WebSection.create(name: "help_page") + +# Default custom pages +load Rails.root.join("db", "pages.rb") diff --git a/lib/admin_wysiwyg_sanitizer.rb b/lib/admin_wysiwyg_sanitizer.rb index 6e219f1e8..48c9a49a1 100644 --- a/lib/admin_wysiwyg_sanitizer.rb +++ b/lib/admin_wysiwyg_sanitizer.rb @@ -1,9 +1,9 @@ class AdminWYSIWYGSanitizer < WYSIWYGSanitizer def allowed_tags - super + %w[img] + super + %w[img table caption thead tbody tr th td] end def allowed_attributes - super + %w[alt src style] + super + %w[alt src align border cellpadding cellspacing dir style class summary scope id] end end diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 0c036c609..1d350a4bd 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -4,4 +4,9 @@ namespace :db do @avoid_log = args[:print_log] == "avoid_log" load(Rails.root.join("db", "dev_seeds.rb")) end + + desc "populate the default pages manually" + task pages: :environment do + load(Rails.root.join("db", "pages.rb")) + end end diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index 1069652ff..a4b05f768 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -32,7 +32,7 @@ describe PagesController do end it "includes a faq page" do - get :show, id: "help/faq/index" + get :show, id: :faq expect(response).to be_ok end end diff --git a/spec/controllers/welcome_controller_spec.rb b/spec/controllers/welcome_controller_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/features/admin/site_customization/pages_spec.rb b/spec/features/admin/site_customization/pages_spec.rb index 65502a470..07a162d97 100644 --- a/spec/features/admin/site_customization/pages_spec.rb +++ b/spec/features/admin/site_customization/pages_spec.rb @@ -13,12 +13,33 @@ feature "Admin custom pages" do %w[title subtitle], { "content" => :ckeditor } - scenario "Index" do - custom_page = create(:site_customization_page) - visit admin_site_customization_pages_path + context "Index" do + + scenario "lists all created custom pages" do + custom_page = create(:site_customization_page) + visit admin_site_customization_pages_path + + expect(page).to have_content(custom_page.title) + expect(page).to have_content(custom_page.slug) + end + + scenario "should contain all default custom pages published populated by db:seeds" do + slugs = %w[accessibility conditions faq privacy welcome_not_verified + welcome_level_two_verified welcome_level_three_verified] + + visit admin_site_customization_pages_path + + expect(SiteCustomization::Page.count).to be 7 + slugs.each do |slug| + expect(SiteCustomization::Page.find_by_slug(slug).status).to eq "published" + end + + expect(all("[id^='site_customization_page_']").count).to be 7 + slugs.each do |slug| + expect(page).to have_content slug + end + end - expect(page).to have_content(custom_page.title) - expect(page).to have_content(custom_page.slug) end context "Create" do diff --git a/spec/features/site_customization/custom_pages_spec.rb b/spec/features/site_customization/custom_pages_spec.rb index 0c659ab2b..6a797fa5a 100644 --- a/spec/features/site_customization/custom_pages_spec.rb +++ b/spec/features/site_customization/custom_pages_spec.rb @@ -1,39 +1,6 @@ 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_en: "Custom conditions", - content_en: "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("Information page on the conditions of use, privacy and protection of personal data.") - 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_en: "Custom conditions", - content_en: "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 diff --git a/spec/features/welcome_spec.rb b/spec/features/welcome_spec.rb index 53232f678..23b88849f 100644 --- a/spec/features/welcome_spec.rb +++ b/spec/features/welcome_spec.rb @@ -2,12 +2,29 @@ require "rails_helper" feature "Welcome screen" do - scenario "a regular users sees it the first time he logs in" do - user = create(:user) + let(:budget) { create(:budget) } + scenario "for a not verified user" do + user = create(:user) login_through_form_as(user) - expect(page).to have_current_path(welcome_path) + expect(page).to have_current_path(page_path("welcome_not_verified")) + end + + scenario "for a level two verified user" do + user = create(:user, :level_two) + login_as(user) + + visit welcome_path + expect(page).to have_current_path(page_path("welcome_level_two_verified")) + end + + scenario "for a level three verified user" do + user = create(:user, :level_three) + login_as(user) + + visit welcome_path + expect(page).to have_current_path(page_path("welcome_level_three_verified")) end scenario "a regular user does not see it when coing to /email" do diff --git a/spec/lib/admin_wysiwyg_sanitizer_spec.rb b/spec/lib/admin_wysiwyg_sanitizer_spec.rb index 2ff151414..ecfee0073 100644 --- a/spec/lib/admin_wysiwyg_sanitizer_spec.rb +++ b/spec/lib/admin_wysiwyg_sanitizer_spec.rb @@ -4,9 +4,30 @@ describe AdminWYSIWYGSanitizer do let(:sanitizer) { AdminWYSIWYGSanitizer.new } describe "#sanitize" do + it "allows images" do html = 'DangerousSmile image' expect(sanitizer.sanitize(html)).to eq(html) end + + it "allows tables" do + html = ' + + + + + + + + + + + +
caption
header 1cell 1
header 2cell 2
' + expect(sanitizer.sanitize(html)).to eq(html) + end + end end diff --git a/spec/lib/tasks/db_spec.rb b/spec/lib/tasks/db_spec.rb new file mode 100644 index 000000000..6c7b1d960 --- /dev/null +++ b/spec/lib/tasks/db_spec.rb @@ -0,0 +1,15 @@ +require "rails_helper" + +describe "rake db:pages" do + let :run_rake_task do + Rake.application.invoke_task("db:pages") + end + + it "seeds the database with the default custom pages" do + SiteCustomization::Page.destroy_all + expect(SiteCustomization::Page.count).to be 0 + + run_rake_task + expect(SiteCustomization::Page.count).to be 7 + end +end