From c4f383e0bce76b702a815f9a763b57f3cb8f8822 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 5 Dec 2022 15:21:28 +0100
Subject: [PATCH] clean

---
 app/models/communication/website/permalink.rb          |  8 +++++---
 .../communication/website/permalink/administrator.rb   | 10 ----------
 app/models/communication/website/permalink/author.rb   | 10 ----------
 app/models/communication/website/permalink/category.rb |  6 ++++--
 app/models/communication/website/permalink/diploma.rb  | 10 ----------
 .../communication/website/permalink/organization.rb    | 10 ----------
 app/models/communication/website/permalink/page.rb     |  1 +
 app/models/communication/website/permalink/person.rb   | 10 ----------
 .../communication/website/permalink/researcher.rb      | 10 ----------
 app/models/communication/website/permalink/teacher.rb  | 10 ----------
 10 files changed, 10 insertions(+), 75 deletions(-)

diff --git a/app/models/communication/website/permalink.rb b/app/models/communication/website/permalink.rb
index 9cd674123..0ec55be15 100644
--- a/app/models/communication/website/permalink.rb
+++ b/app/models/communication/website/permalink.rb
@@ -91,13 +91,15 @@ class Communication::Website::Permalink < ApplicationRecord
     p
   end
 
+  # Can be overwritten
   def published?
-    # Can be overwritten
-    true
+    about.for_website?(website)
   end
 
   def substitutions
-    raise NotImplementedError
+    {
+      slug: about.slug
+    }
   end
 
   def set_university
diff --git a/app/models/communication/website/permalink/administrator.rb b/app/models/communication/website/permalink/administrator.rb
index cfdbf6990..03cec6366 100644
--- a/app/models/communication/website/permalink/administrator.rb
+++ b/app/models/communication/website/permalink/administrator.rb
@@ -10,14 +10,4 @@ class Communication::Website::Permalink::Administrator < Communication::Website:
   def self.pattern_in_website(website)
     "#{website.special_page(:persons).path_without_language}:slug/roles/"
   end
-
-  protected
-
-  def published?
-    about.for_website?(website)
-  end
-
-  def published_path
-    pattern.gsub(":slug", about.slug)
-  end
 end
diff --git a/app/models/communication/website/permalink/author.rb b/app/models/communication/website/permalink/author.rb
index 848cf48b9..601e992ed 100644
--- a/app/models/communication/website/permalink/author.rb
+++ b/app/models/communication/website/permalink/author.rb
@@ -11,14 +11,4 @@ class Communication::Website::Permalink::Author < Communication::Website::Permal
   def self.pattern_in_website(website)
     "#{website.special_page(:persons).path_without_language}:slug/#{website.special_page(:communication_posts).slug}/"
   end
-
-  protected
-
-  def published?
-    about.for_website?(website)
-  end
-
-  def published_path
-    pattern.gsub(":slug", about.slug)
-  end
 end
diff --git a/app/models/communication/website/permalink/category.rb b/app/models/communication/website/permalink/category.rb
index 89f797a3c..9f98bfb5f 100644
--- a/app/models/communication/website/permalink/category.rb
+++ b/app/models/communication/website/permalink/category.rb
@@ -13,7 +13,9 @@ class Communication::Website::Permalink::Category < Communication::Website::Perm
 
   protected
 
-  def published_path
-    pattern.gsub(":slug", about.path)
+  def substitutions
+    {
+      slug: about.path
+    }
   end
 end
diff --git a/app/models/communication/website/permalink/diploma.rb b/app/models/communication/website/permalink/diploma.rb
index ccf32fbbf..7a94109c5 100644
--- a/app/models/communication/website/permalink/diploma.rb
+++ b/app/models/communication/website/permalink/diploma.rb
@@ -10,14 +10,4 @@ class Communication::Website::Permalink::Diploma < Communication::Website::Perma
   def self.pattern_in_website(website)
     "#{website.special_page(:education_diplomas).path_without_language}:slug/"
   end
-
-  protected
-
-  def published?
-    about.for_website?(website)
-  end
-
-  def published_path
-    pattern.gsub(":slug", about.slug)
-  end
 end
diff --git a/app/models/communication/website/permalink/organization.rb b/app/models/communication/website/permalink/organization.rb
index fdd564a1a..74384a952 100644
--- a/app/models/communication/website/permalink/organization.rb
+++ b/app/models/communication/website/permalink/organization.rb
@@ -10,14 +10,4 @@ class Communication::Website::Permalink::Organization < Communication::Website::
   def self.pattern_in_website(website)
     "#{website.special_page(:organizations).path_without_language}:slug/"
   end
-
-  protected
-
-  def published?
-    about.for_website?(website)
-  end
-
-  def published_path
-    pattern.gsub(":slug", about.slug)
-  end
 end
diff --git a/app/models/communication/website/permalink/page.rb b/app/models/communication/website/permalink/page.rb
index 1afa2991a..ccf7bc38d 100644
--- a/app/models/communication/website/permalink/page.rb
+++ b/app/models/communication/website/permalink/page.rb
@@ -9,6 +9,7 @@ class Communication::Website::Permalink::Page < Communication::Website::Permalin
     website.id == about.communication_website_id && about.published
   end
 
+  # Pages are special, there is no substitution
   def published_path
     about.path
   end
diff --git a/app/models/communication/website/permalink/person.rb b/app/models/communication/website/permalink/person.rb
index 9510fa77b..ba89ef1dc 100644
--- a/app/models/communication/website/permalink/person.rb
+++ b/app/models/communication/website/permalink/person.rb
@@ -10,14 +10,4 @@ class Communication::Website::Permalink::Person < Communication::Website::Permal
   def self.pattern_in_website(website)
     "#{website.special_page(:persons).path_without_language}:slug/"
   end
-
-  protected
-
-  def published?
-    about.for_website?(website)
-  end
-
-  def published_path
-    pattern.gsub(":slug", about.slug)
-  end
 end
diff --git a/app/models/communication/website/permalink/researcher.rb b/app/models/communication/website/permalink/researcher.rb
index f9d52b05e..33bb67890 100644
--- a/app/models/communication/website/permalink/researcher.rb
+++ b/app/models/communication/website/permalink/researcher.rb
@@ -10,14 +10,4 @@ class Communication::Website::Permalink::Researcher < Communication::Website::Pe
   def self.pattern_in_website(website)
     "#{website.special_page(:persons).path_without_language}:slug/papers/"
   end
-
-  protected
-
-  def published?
-    about.for_website?(website)
-  end
-
-  def published_path
-    pattern.gsub(":slug", about.slug)
-  end
 end
diff --git a/app/models/communication/website/permalink/teacher.rb b/app/models/communication/website/permalink/teacher.rb
index de324a201..7e99aaefd 100644
--- a/app/models/communication/website/permalink/teacher.rb
+++ b/app/models/communication/website/permalink/teacher.rb
@@ -10,14 +10,4 @@ class Communication::Website::Permalink::Teacher < Communication::Website::Perma
   def self.pattern_in_website(website)
     "#{website.special_page(:persons).path_without_language}:slug/programs/"
   end
-
-  protected
-
-  def published?
-    about.for_website?(website)
-  end
-
-  def published_path
-    pattern.gsub(":slug", about.slug)
-  end
 end
-- 
GitLab