From 514299842ef81cd5da053b36c0b7dc972e11f131 Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Thu, 10 Feb 2022 11:15:37 +0100
Subject: [PATCH] Cleanup Home title + Add Home description + Remove all 'force
 publish' buttons

---
 .../admin/communication/website/categories_controller.rb | 7 +------
 .../admin/communication/website/home_controller.rb       | 2 +-
 .../admin/communication/website/pages_controller.rb      | 5 -----
 .../admin/communication/website/posts_controller.rb      | 5 -----
 .../admin/communication/websites_controller.rb           | 5 -----
 app/models/communication/website/home.rb                 | 2 +-
 app/models/communication/website/structure.rb            | 2 +-
 .../admin/communication/website/categories/show.html.erb | 7 -------
 .../admin/communication/website/homes/edit.html.erb      | 2 +-
 .../admin/communication/website/homes/static.html.erb    | 4 ++--
 .../admin/communication/website/pages/show.html.erb      | 8 --------
 .../admin/communication/website/posts/show.html.erb      | 7 -------
 app/views/admin/communication/websites/show.html.erb     | 7 -------
 config/locales/communication/en.yml                      | 7 +++----
 config/locales/communication/fr.yml                      | 7 +++----
 config/routes/admin/communication.rb                     | 9 +--------
 ...0095616_add_description_and_remove_title_from_home.rb | 6 ++++++
 db/schema.rb                                             | 4 ++--
 18 files changed, 22 insertions(+), 74 deletions(-)
 create mode 100644 db/migrate/20220210095616_add_description_and_remove_title_from_home.rb

diff --git a/app/controllers/admin/communication/website/categories_controller.rb b/app/controllers/admin/communication/website/categories_controller.rb
index d328417e9..1c609c597 100644
--- a/app/controllers/admin/communication/website/categories_controller.rb
+++ b/app/controllers/admin/communication/website/categories_controller.rb
@@ -33,12 +33,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication
     @posts = @category.posts.ordered.page(params[:page])
     breadcrumb
   end
-
-  def publish
-    @category.sync_with_git
-    redirect_to admin_communication_website_category_path(@category), notice: t('admin.will_be_published_html', model: @category.to_s)
-  end
-
+  
   def new
     @category.website = @website
     breadcrumb
diff --git a/app/controllers/admin/communication/website/home_controller.rb b/app/controllers/admin/communication/website/home_controller.rb
index 323e9ba3c..195cf52cb 100644
--- a/app/controllers/admin/communication/website/home_controller.rb
+++ b/app/controllers/admin/communication/website/home_controller.rb
@@ -30,7 +30,7 @@ class Admin::Communication::Website::HomeController < Admin::Communication::Webs
   def home_params
     params.require(:communication_website_home)
           .permit(
-            :title, :text, :featured_image, :featured_image_delete,
+            :description, :text, :featured_image, :featured_image_delete,
             :featured_image_infos, :featured_image_alt
           )
   end
diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb
index eae14a1cc..6588b3a8d 100644
--- a/app/controllers/admin/communication/website/pages_controller.rb
+++ b/app/controllers/admin/communication/website/pages_controller.rb
@@ -31,11 +31,6 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web
     breadcrumb
   end
 
-  def publish
-    @page.sync_with_git
-    redirect_to admin_communication_website_page_path(@page), notice: t('admin.will_be_published_html', model: @page.to_s)
-  end
-
   def new
     @page.website = @website
     breadcrumb
diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb
index d337f5968..7574a6220 100644
--- a/app/controllers/admin/communication/website/posts_controller.rb
+++ b/app/controllers/admin/communication/website/posts_controller.rb
@@ -10,11 +10,6 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web
     breadcrumb
   end
 
-  def publish
-    @post.sync_with_git
-    redirect_to admin_communication_website_post_path(@post), notice: t('admin.will_be_published_html', model: @post.to_s)
-  end
-
   def new
     @post.website = @website
     breadcrumb
diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb
index 5c7c8e6aa..7080de940 100644
--- a/app/controllers/admin/communication/websites_controller.rb
+++ b/app/controllers/admin/communication/websites_controller.rb
@@ -33,11 +33,6 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati
     add_breadcrumb Communication::Website::Imported::Website.model_name.human
   end
 
-  def publish
-    @website.sync_with_git
-    redirect_to admin_communication_website_path(@website), notice: t('admin.will_be_published_html', model: @website.to_s)
-  end
-
   def edit
     breadcrumb
     add_breadcrumb t('edit')
diff --git a/app/models/communication/website/home.rb b/app/models/communication/website/home.rb
index 6d0989f06..ab747c846 100644
--- a/app/models/communication/website/home.rb
+++ b/app/models/communication/website/home.rb
@@ -3,9 +3,9 @@
 # Table name: communication_website_homes
 #
 #  id                       :uuid             not null, primary key
+#  description              :text
 #  featured_image_alt       :string
 #  github_path              :text
-#  title                    :string           default("Home")
 #  created_at               :datetime         not null
 #  updated_at               :datetime         not null
 #  communication_website_id :uuid             not null
diff --git a/app/models/communication/website/structure.rb b/app/models/communication/website/structure.rb
index 41e414f97..0cb7d3efc 100644
--- a/app/models/communication/website/structure.rb
+++ b/app/models/communication/website/structure.rb
@@ -74,8 +74,8 @@ class Communication::Website::Structure < ApplicationRecord
 
   def git_dependencies(website)
     dependencies = []
-    dependencies << Communication::Website::Structure::Administrators.find(id)
     dependencies << Communication::Website::Structure::Persons.find(id)
+    dependencies << Communication::Website::Structure::Administrators.find(id)
     dependencies << Communication::Website::Structure::Authors.find(id) if website.authors.any?
     dependencies << Communication::Website::Structure::CommunicationPosts.find(id) if website.posts.published.any?
 
diff --git a/app/views/admin/communication/website/categories/show.html.erb b/app/views/admin/communication/website/categories/show.html.erb
index 04e252e98..1d529ac45 100644
--- a/app/views/admin/communication/website/categories/show.html.erb
+++ b/app/views/admin/communication/website/categories/show.html.erb
@@ -60,13 +60,6 @@
   <% end %>
 <% end %>
 
-<% content_for :action_bar_left do %>
-  <%= link_to t('communication.website.force_publication'),
-              publish_admin_communication_website_category_path(@category),
-              method: :post,
-              class: button_classes %>
-<% end %>
-
 <% content_for :action_bar_right do %>
   <%= edit_link @category %>
 <% end %>
diff --git a/app/views/admin/communication/website/homes/edit.html.erb b/app/views/admin/communication/website/homes/edit.html.erb
index e341c33b2..ca117a77c 100644
--- a/app/views/admin/communication/website/homes/edit.html.erb
+++ b/app/views/admin/communication/website/homes/edit.html.erb
@@ -9,7 +9,7 @@
             <h5 class="card-title mb-0"><%= t('content') %></h5>
           </div>
           <div class="card-body">
-            <%= f.input :title %>
+            <%= f.input :description %>
             <%= f.input :text, as: :rich_text_area %>
           </div>
         </div>
diff --git a/app/views/admin/communication/website/homes/static.html.erb b/app/views/admin/communication/website/homes/static.html.erb
index f4868873d..94f6b2024 100644
--- a/app/views/admin/communication/website/homes/static.html.erb
+++ b/app/views/admin/communication/website/homes/static.html.erb
@@ -1,12 +1,12 @@
 ---
 title: >
   <%= @home.website.name %>
-breadcrumb_title: "<%= @home.title %>"
+breadcrumb_title: "<%= @website.structure.home_title %>"
 <% if @home.featured_image.attached? %>
 image: "<%= @home.featured_image.blob.id %>"
 image_alt: "<%= @home.featured_image_alt %>"
 <% end %>
 description: >
-  <%= strip_tags prepare_html_for_static(@home.text, @home.university) %>
+  <%= @home.description %>
 ---
 <%= prepare_html_for_static @home.text, @home.university %>
diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb
index b42d6c952..898684ec0 100644
--- a/app/views/admin/communication/website/pages/show.html.erb
+++ b/app/views/admin/communication/website/pages/show.html.erb
@@ -77,14 +77,6 @@
   </div>
 <% end %>
 
-<% content_for :action_bar_left do %>
-  <%= destroy_link @page %>
-  <%= link_to t('communication.website.force_publication'),
-              publish_admin_communication_website_page_path(@page),
-              method: :post,
-              class: button_classes %>
-<% end %>
-
 <% content_for :action_bar_right do %>
   <%= edit_link @page %>
 <% end %>
diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb
index f8d9c7788..9ffac8da6 100644
--- a/app/views/admin/communication/website/posts/show.html.erb
+++ b/app/views/admin/communication/website/posts/show.html.erb
@@ -60,13 +60,6 @@
   </div>
 <% end %>
 
-<% content_for :action_bar_left do %>
-  <%= link_to t('communication.website.force_publication'),
-              publish_admin_communication_website_post_path(@post),
-              method: :post,
-              class: button_classes %>
-<% end %>
-
 <% content_for :action_bar_right do %>
   <%= edit_link @post %>
 <% end %>
diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb
index 6748a6d07..dd872787e 100644
--- a/app/views/admin/communication/websites/show.html.erb
+++ b/app/views/admin/communication/websites/show.html.erb
@@ -26,13 +26,6 @@
   </div>
 <% end %>
 
-<% content_for :action_bar_left do %>
-  <%= link_to t('communication.website.force_publication'),
-              publish_admin_communication_website_path(@website),
-              method: :post,
-              class: button_classes %>
-<% end %>
-
 <% content_for :action_bar_right do %>
   <% if can? :read, Communication::Website::Imported::Website %>
     <% if @website.imported? %>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index dff6d1ca8..afa0575fb 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -50,8 +50,8 @@ en:
         parent: Parent category
         slug: Slug
       communication/website/home:
+        description: Description (SEO)
         text: Text
-        title: Title
         featured_image: Featured image
         featured_image_alt: Alt text
       communication/website/imported/category:
@@ -130,7 +130,6 @@ en:
     manage_authors: Manage authors
     number_of_posts: Nunber of posts
     website:
-      force_publication: 'Force publication'
       git: Git
       imported:
         from: Imported from
@@ -173,5 +172,5 @@ en:
               url: URL
   simple_form:
     hints:
-      communication_website_home:
-        title: Will be used in the breadcrumbs
+      communication_website_structure:
+        home_title: Will be used in the breadcrumbs
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 99849e41c..c59adc6e0 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -50,8 +50,8 @@ fr:
         parent: Catégorie parente
         slug: Slug
       communication/website/home:
+        description: Description (SEO)
         text: Texte
-        title: Titre
         featured_image: Image à la une
         featured_image_alt: Texte alternatif
       communication/website/imported/category:
@@ -130,7 +130,6 @@ fr:
     manage_authors: Gérer les auteur·rice·s
     number_of_posts: Nombre d'actualités
     website:
-      force_publication: 'Forcer la publication'
       git: Git
       imported:
         from: Importé depuis
@@ -173,5 +172,5 @@ fr:
               url: URL
   simple_form:
     hints:
-      communication_website_home:
-        title: Sera utilisé notamment dans le fil d'Ariane
+      communication_website_structure:
+        home_title: Sera utilisé notamment dans le fil d'Ariane
diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb
index 1bb626b6e..705d9fb28 100644
--- a/config/routes/admin/communication.rb
+++ b/config/routes/admin/communication.rb
@@ -5,7 +5,6 @@ namespace :communication do
     member do
       get :import
       post :import
-      post :publish
     end
     resources :pages, controller: 'website/pages' do
       collection do
@@ -13,7 +12,6 @@ namespace :communication do
       end
       member do
         get :children
-        post :publish
       end
     end
     resources :categories, controller: 'website/categories' do
@@ -22,15 +20,10 @@ namespace :communication do
       end
       member do
         get :children
-        post :publish
       end
     end
     resources :authors, controller: 'website/authors', only: [:index, :show]
-    resources :posts, controller: 'website/posts' do
-      member do
-        post :publish
-      end
-    end
+    resources :posts, controller: 'website/posts'
     resources :curations, path: 'posts/curations', as: :post_curations, controller: 'website/posts/curations', only: [:new, :create]
     resources :menus, controller: 'website/menus' do
       resources :items, controller: 'website/menu/items', except: :index do
diff --git a/db/migrate/20220210095616_add_description_and_remove_title_from_home.rb b/db/migrate/20220210095616_add_description_and_remove_title_from_home.rb
new file mode 100644
index 000000000..028e52fc4
--- /dev/null
+++ b/db/migrate/20220210095616_add_description_and_remove_title_from_home.rb
@@ -0,0 +1,6 @@
+class AddDescriptionAndRemoveTitleFromHome < ActiveRecord::Migration[6.1]
+  def change
+    add_column :communication_website_homes, :description, :text
+    remove_column :communication_website_homes, :title
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 3491f21e8..533b70088 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2022_02_07_152152) do
+ActiveRecord::Schema.define(version: 2022_02_10_095616) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -125,7 +125,7 @@ ActiveRecord::Schema.define(version: 2022_02_07_152152) do
     t.datetime "updated_at", precision: 6, null: false
     t.text "github_path"
     t.string "featured_image_alt"
-    t.string "title", default: "Home"
+    t.text "description"
     t.index ["communication_website_id"], name: "idx_comm_website_homes_on_communication_website_id"
     t.index ["university_id"], name: "index_communication_website_homes_on_university_id"
   end
-- 
GitLab