From d82bb0f41b3b3b0fb08ffb8450f52d73872d0ba7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 16 Dec 2022 11:51:58 +0100
Subject: [PATCH] fix permalinks config which had lang iso code

---
 app/models/communication/website/permalink.rb               | 5 ++++-
 app/models/communication/website/permalink/administrator.rb | 2 +-
 app/models/communication/website/permalink/author.rb        | 2 +-
 app/models/communication/website/permalink/category.rb      | 2 +-
 app/models/communication/website/permalink/diploma.rb       | 2 +-
 app/models/communication/website/permalink/organization.rb  | 2 +-
 app/models/communication/website/permalink/person.rb        | 2 +-
 app/models/communication/website/permalink/post.rb          | 2 +-
 app/models/communication/website/permalink/program.rb       | 2 +-
 app/models/communication/website/permalink/researcher.rb    | 2 +-
 app/models/communication/website/permalink/teacher.rb       | 2 +-
 11 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/app/models/communication/website/permalink.rb b/app/models/communication/website/permalink.rb
index 8c44020ac..d3bcc73b5 100644
--- a/app/models/communication/website/permalink.rb
+++ b/app/models/communication/website/permalink.rb
@@ -105,7 +105,10 @@ class Communication::Website::Permalink < ApplicationRecord
 
   # Can be overwritten (Page for example)
   def published_path
-    p = pattern
+    # TODO I18n doit prendre la langue du about
+    p = ""
+    p += "/#{website.languages.first.iso_code}" if website.languages.any?
+    p += pattern
     substitutions.each do |key, value|
       p.gsub! ":#{key}", "#{value}"
     end
diff --git a/app/models/communication/website/permalink/administrator.rb b/app/models/communication/website/permalink/administrator.rb
index a852b130b..3ae3a90cf 100644
--- a/app/models/communication/website/permalink/administrator.rb
+++ b/app/models/communication/website/permalink/administrator.rb
@@ -33,6 +33,6 @@ class Communication::Website::Permalink::Administrator < Communication::Website:
 
   # /equipe/:slug/roles/
   def self.pattern_in_website(website)
-    "#{website.special_page(:persons).path}:slug/roles/"
+    "/#{website.special_page(:persons).slug_with_ancestors}/:slug/roles/"
   end
 end
diff --git a/app/models/communication/website/permalink/author.rb b/app/models/communication/website/permalink/author.rb
index d5e2aa061..6f94a1153 100644
--- a/app/models/communication/website/permalink/author.rb
+++ b/app/models/communication/website/permalink/author.rb
@@ -34,6 +34,6 @@ class Communication::Website::Permalink::Author < Communication::Website::Permal
 
   # /equipe/:slug/actualites/
   def self.pattern_in_website(website)
-    "#{website.special_page(:persons).path}:slug/#{website.special_page(:communication_posts).slug}/"
+    "/#{website.special_page(:persons).slug_with_ancestors}/:slug/#{website.special_page(:communication_posts).slug}/"
   end
 end
diff --git a/app/models/communication/website/permalink/category.rb b/app/models/communication/website/permalink/category.rb
index baf5ebd30..933dcd3a9 100644
--- a/app/models/communication/website/permalink/category.rb
+++ b/app/models/communication/website/permalink/category.rb
@@ -33,7 +33,7 @@ class Communication::Website::Permalink::Category < Communication::Website::Perm
 
   # /actualites/:slug/
   def self.pattern_in_website(website)
-    "#{website.special_page(:communication_posts).path}:slug/"
+    "/#{website.special_page(:communication_posts).slug_with_ancestors}/:slug/"
   end
 
   protected
diff --git a/app/models/communication/website/permalink/diploma.rb b/app/models/communication/website/permalink/diploma.rb
index 0446d7323..9df94320c 100644
--- a/app/models/communication/website/permalink/diploma.rb
+++ b/app/models/communication/website/permalink/diploma.rb
@@ -33,6 +33,6 @@ class Communication::Website::Permalink::Diploma < Communication::Website::Perma
 
   # /diplomes/:slug/
   def self.pattern_in_website(website)
-    "#{website.special_page(:education_diplomas).path}:slug/"
+    "/#{website.special_page(:education_diplomas).slug_with_ancestors}/:slug/"
   end
 end
diff --git a/app/models/communication/website/permalink/organization.rb b/app/models/communication/website/permalink/organization.rb
index 00220b12d..b1b20dc23 100644
--- a/app/models/communication/website/permalink/organization.rb
+++ b/app/models/communication/website/permalink/organization.rb
@@ -33,6 +33,6 @@ class Communication::Website::Permalink::Organization < Communication::Website::
 
   # /organisations/:slug/
   def self.pattern_in_website(website)
-    "#{website.special_page(:organizations).path}:slug/"
+    "/#{website.special_page(:organizations).slug_with_ancestors}/:slug/"
   end
 end
diff --git a/app/models/communication/website/permalink/person.rb b/app/models/communication/website/permalink/person.rb
index dbe8b043a..95ea4ba45 100644
--- a/app/models/communication/website/permalink/person.rb
+++ b/app/models/communication/website/permalink/person.rb
@@ -33,6 +33,6 @@ class Communication::Website::Permalink::Person < Communication::Website::Permal
 
   # /equipe/:slug/
   def self.pattern_in_website(website)
-    "#{website.special_page(:persons).path}:slug/"
+    "/#{website.special_page(:persons).slug_with_ancestors}/:slug/"
   end
 end
diff --git a/app/models/communication/website/permalink/post.rb b/app/models/communication/website/permalink/post.rb
index fdb8fcdf7..43e79fa4f 100644
--- a/app/models/communication/website/permalink/post.rb
+++ b/app/models/communication/website/permalink/post.rb
@@ -33,7 +33,7 @@ class Communication::Website::Permalink::Post < Communication::Website::Permalin
 
   # /actualites/2022-10-21-un-article/
   def self.pattern_in_website(website)
-    "#{website.special_page(:communication_posts).path}:year-:month-:day-:slug/"
+    "/#{website.special_page(:communication_posts).slug_with_ancestors}/:year-:month-:day-:slug/"
   end
 
   protected
diff --git a/app/models/communication/website/permalink/program.rb b/app/models/communication/website/permalink/program.rb
index 506696d7e..7e4f7fd28 100644
--- a/app/models/communication/website/permalink/program.rb
+++ b/app/models/communication/website/permalink/program.rb
@@ -33,6 +33,6 @@ class Communication::Website::Permalink::Program < Communication::Website::Perma
 
   # /formations/:slug/
   def self.pattern_in_website(website)
-    "#{website.special_page(:education_programs).path}:slug/"
+    "/#{website.special_page(:education_programs).slug_with_ancestors}/:slug/"
   end
 end
diff --git a/app/models/communication/website/permalink/researcher.rb b/app/models/communication/website/permalink/researcher.rb
index e0cbf3c44..a770f8e2a 100644
--- a/app/models/communication/website/permalink/researcher.rb
+++ b/app/models/communication/website/permalink/researcher.rb
@@ -34,6 +34,6 @@ class Communication::Website::Permalink::Researcher < Communication::Website::Pe
   # /equipe/:slug/papers/
   # FIXME
   def self.pattern_in_website(website)
-    "#{website.special_page(:persons).path}:slug/papers/"
+    "/#{website.special_page(:persons).slug_with_ancestors}/:slug/papers/"
   end
 end
diff --git a/app/models/communication/website/permalink/teacher.rb b/app/models/communication/website/permalink/teacher.rb
index ebd6ed95d..37783685b 100644
--- a/app/models/communication/website/permalink/teacher.rb
+++ b/app/models/communication/website/permalink/teacher.rb
@@ -34,6 +34,6 @@ class Communication::Website::Permalink::Teacher < Communication::Website::Perma
   # /equipe/:slug/programs/
   # FIXME
   def self.pattern_in_website(website)
-    "#{website.special_page(:persons).path}:slug/programs/"
+    "/#{website.special_page(:persons).slug_with_ancestors}/:slug/programs/"
   end
 end
-- 
GitLab