From 8e461d462b312e9b16c088496d43c417f97193e3 Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Fri, 19 Nov 2021 15:00:28 +0100
Subject: [PATCH] cleanup pages

---
 .../admin/communication/website/pages_controller.rb   |  1 -
 app/models/communication/website/page.rb              | 11 +----------
 app/models/concerns/with_slug.rb                      |  3 +--
 .../admin/communication/website/pages/jekyll.html.erb |  3 ---
 config/locales/communication/en.yml                   | 10 ----------
 config/locales/communication/fr.yml                   | 10 ----------
 config/locales/en.yml                                 |  1 +
 config/locales/fr.yml                                 |  1 +
 8 files changed, 4 insertions(+), 36 deletions(-)

diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb
index f599f794c..94d6260a8 100644
--- a/app/controllers/admin/communication/website/pages_controller.rb
+++ b/app/controllers/admin/communication/website/pages_controller.rb
@@ -55,7 +55,6 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web
   end
 
   def update
-    byebug
     if @page.update(page_params)
       redirect_to admin_communication_website_page_path(@page), notice: t('admin.successfully_updated_html', model: @page.to_s)
     else
diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb
index 9c60d9ceb..5e7b1f45b 100644
--- a/app/models/communication/website/page.rb
+++ b/app/models/communication/website/page.rb
@@ -63,7 +63,6 @@ class Communication::Website::Page < ApplicationRecord
              dependent: :nullify
 
   validates :title, presence: true
-  validate :homepage_is_published?
 
   before_validation :make_path
   after_save :update_children_paths if :saved_change_to_path?
@@ -91,10 +90,6 @@ class Communication::Website::Page < ApplicationRecord
     "#{ title }"
   end
 
-  def is_homepage?
-    path == '/'
-  end
-
   protected
 
   def make_path
@@ -105,9 +100,5 @@ class Communication::Website::Page < ApplicationRecord
     children.each(&:save)
   end
 
-  def homepage_is_published?
-     if is_homepage? and !published
-        errors.add(:published, :home_not_published)
-     end
-  end
+
 end
diff --git a/app/models/concerns/with_slug.rb b/app/models/concerns/with_slug.rb
index 81ec3bc25..c13d07f01 100644
--- a/app/models/concerns/with_slug.rb
+++ b/app/models/concerns/with_slug.rb
@@ -5,7 +5,6 @@ module WithSlug
     validates :slug,
               uniqueness: { scope: :university_id }
     validates :slug,
-              format: { with: /\A[a-z0-9\-]+\z/, message: "ne peut contenir que des lettres minuscules, des chiffres et des traits d'union." },
-              allow_blank: true
+              format: { with: /\A[a-z0-9\-]+\z/, message: I18n.t('slug_error') }
   end
 end
diff --git a/app/views/admin/communication/website/pages/jekyll.html.erb b/app/views/admin/communication/website/pages/jekyll.html.erb
index c7f5d008d..c99b7a260 100644
--- a/app/views/admin/communication/website/pages/jekyll.html.erb
+++ b/app/views/admin/communication/website/pages/jekyll.html.erb
@@ -1,7 +1,4 @@
 ---
-<% if @page.is_homepage? %>
-layout: home
-<% end %>
 title: "<%= @page.title %>"
 permalink: "<%= @page.path %>"
 identifier: "<%= @page.id %>"
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index 23975e9a2..cd85630bb 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -113,19 +113,9 @@ en:
         text: Text
         title: Title
         website: Website
-    errors:
-      models:
-        communication/website/page:
-          attributes:
-            published:
-              home_not_published: must be checked. Homepage has to be published.
   enums:
     communication/website/menu/item:
       kind:
         blank: Title
         page: Page
         url: URL
-  simple_form:
-    hints:
-      communication_website_page:
-        slug: Leave empty for home page
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 9efca97a4..7116b0d67 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -113,19 +113,9 @@ fr:
         text: Texte
         title: Titre
         website: Site Web
-    errors:
-      models:
-        communication/website/page:
-          attributes:
-            published:
-              home_not_published: doit être coché. La page d'accueil doit être publiée.
   enums:
     communication/website/menu/item:
       kind:
         blank: Titre intermédiaire
         page: Page
         url: URL
-  simple_form:
-    hints:
-      communication_website_page:
-        slug: Laisser vide pour la page d'accueil du site
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 683b157c9..5401d17f0 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -119,6 +119,7 @@ en:
   simple_form_password_with_hints:
       test_chars: "%{min_length} characters min."
   show: Show
+  slug_error: can only contain downcase letters, numbers, and dashes.
   terms_of_service: Terms of service
   terms_of_service_url: https://osuny.org/conditions-d-utilisation
   time:
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index b36549ec4..9ed3416ca 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -119,6 +119,7 @@ fr:
   simple_form_password_with_hints:
       test_chars: "%{min_length} caractères min."
   show: Voir
+  slug_error: ne peut contenir que des lettres minuscules, des chiffres et des traits d'union.
   terms_of_service: Conditions d'utilisation
   terms_of_service_url: https://osuny.org/conditions-d-utilisation
   time:
-- 
GitLab