From 042c7c0043ed1ca7f241f2a94b435e7f3fad658d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 6 Jan 2023 16:51:59 +0100
Subject: [PATCH] clean kinds

---
 app/models/communication/website/menu/item.rb | 25 +------------------
 .../communication/website/with_menus.rb       |  2 --
 ...106130950_set_about_from_menu_item_kind.rb | 22 ++++++++--------
 3 files changed, 12 insertions(+), 37 deletions(-)

diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb
index 6383eb0ab..f66fa1e69 100644
--- a/app/models/communication/website/menu/item.rb
+++ b/app/models/communication/website/menu/item.rb
@@ -57,19 +57,7 @@ class Communication::Website::Menu::Item < ApplicationRecord
     category: 41,
     post: 42,
     volume: 61,
-    paper: 63,
-    # Legacy (remove when no menu items remain with these kinds)
-    programs: 30,
-    diplomas: 32,
-    posts: 40,
-    organizations: 45,
-    persons: 50,
-    administrators: 51,
-    authors: 52,
-    researchers: 53,
-    teachers: 54,
-    volumes: 60,
-    papers: 62
+    paper: 63
   }, _prefix: :kind
 
   validates :title, presence: true
@@ -79,25 +67,14 @@ class Communication::Website::Menu::Item < ApplicationRecord
 
   def self.icon_for(kind)
     icons = {
-      'administrators' => Icon::UNIVERSITY_PERSON_ADMINISTRATORS,
-      'authors' => Icon::UNIVERSITY_PERSON,
       'blank' => 'font',
       'diploma' => Icon::EDUCATION_DIPLOMA,
-      'diplomas' => Icon::EDUCATION_DIPLOMA,
-      'posts' => Icon::COMMUNICATION_WEBSITE_POST,
       'post' => Icon::COMMUNICATION_WEBSITE_POST,
       'category' => Icon::COMMUNICATION_WEBSITE_POST,
       'page' => Icon::COMMUNICATION_WEBSITE_PAGE,
       'program' => Icon::EDUCATION_PROGRAM,
-      'programs' => Icon::EDUCATION_PROGRAM,
       'paper' => Icon::RESEARCH_LABORATORY,
-      'papers' => Icon::RESEARCH_LABORATORY,
-      'volumes' => Icon::RESEARCH_LABORATORY,
       'volume' => Icon::RESEARCH_LABORATORY,
-      'researchers' => Icon::RESEARCH_RESEARCHER,
-      'organizations' => Icon::UNIVERSITY_ORGANIZATION,
-      'persons' => Icon::UNIVERSITY_PERSON,
-      'teachers' => Icon::EDUCATION_TEACHER,
       'url' => 'globe',
     }
     "fas fa-#{icons[kind]}" if icons.has_key? kind
diff --git a/app/models/communication/website/with_menus.rb b/app/models/communication/website/with_menus.rb
index 509e15915..d25cf0404 100644
--- a/app/models/communication/website/with_menus.rb
+++ b/app/models/communication/website/with_menus.rb
@@ -12,8 +12,6 @@ module Communication::Website::WithMenus
 
   def menu_item_kinds
     Communication::Website::Menu::Item.kinds.reject do |key, value|
-      # TODO: Supprimer quand les pages spéciales seront en kind=page
-      next true if ["programs", "diplomas", "posts", "organizations", "persons", "administrators", "authors", "researchers", "teachers", "volumes", "papers"].include?(key)
       method_name = "menu_item_kind_#{key}?"
       respond_to?(method_name) && !public_send(method_name)
     end
diff --git a/db/migrate/20230106130950_set_about_from_menu_item_kind.rb b/db/migrate/20230106130950_set_about_from_menu_item_kind.rb
index 62de9c2b6..e1bd0840f 100644
--- a/db/migrate/20230106130950_set_about_from_menu_item_kind.rb
+++ b/db/migrate/20230106130950_set_about_from_menu_item_kind.rb
@@ -1,17 +1,17 @@
 class SetAboutFromMenuItemKind < ActiveRecord::Migration[7.0]
   def change
     mapping = {
-      programs: Communication::Website::Page::EducationProgram,
-      diplomas: Communication::Website::Page::EducationDiploma,
-      posts: Communication::Website::Page::CommunicationPost,
-      organizations: Communication::Website::Page::Organization,
-      persons: Communication::Website::Page::Person,
-      administrators: Communication::Website::Page::Administrator,
-      authors: Communication::Website::Page::Author,
-      researchers: Communication::Website::Page::Researcher,
-      teachers: Communication::Website::Page::Teacher,
-      volumes: Communication::Website::Page::ResearchVolume,
-      papers: Communication::Website::Page::ResearchPaper
+      30: Communication::Website::Page::EducationProgram,
+      32: Communication::Website::Page::EducationDiploma,
+      40: Communication::Website::Page::CommunicationPost,
+      45: Communication::Website::Page::Organization,
+      50: Communication::Website::Page::Person,
+      51: Communication::Website::Page::Administrator,
+      52: Communication::Website::Page::Author,
+      53: Communication::Website::Page::Researcher,
+      54: Communication::Website::Page::Teacher,
+      60: Communication::Website::Page::ResearchVolume,
+      62: Communication::Website::Page::ResearchPaper
     }
 
     websites = Communication::Website.where(id: Communication::Website::Menu::Item.where(kind: mapping.keys).distinct.pluck(:website_id))
-- 
GitLab