From 6a5a9647629edb06365fd9bd506c2340b4a39fa5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 22 Nov 2021 14:31:18 +0100
Subject: [PATCH] Revert "slug validator"

This reverts commit c1672fb38779e8a02e3805b6443c64d403522d39.
---
 app/models/communication/website/author.rb   | 2 --
 app/models/communication/website/category.rb | 1 -
 app/models/communication/website/page.rb     | 1 -
 app/models/communication/website/post.rb     | 5 ++---
 app/models/concerns/with_slug.rb             | 2 ++
 app/models/education/teacher.rb              | 2 --
 6 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/app/models/communication/website/author.rb b/app/models/communication/website/author.rb
index e316d74bf..a81414d3d 100644
--- a/app/models/communication/website/author.rb
+++ b/app/models/communication/website/author.rb
@@ -39,8 +39,6 @@ class Communication::Website::Author < ApplicationRecord
            class_name: 'Communication::Website::Post',
            dependent: :nullify
 
-  validates :slug, uniqueness: { scope: :website_id }
-
   scope :ordered, -> { order(:last_name, :first_name) }
 
   def to_s
diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb
index 811c1d7e6..5d662a5c3 100644
--- a/app/models/communication/website/category.rb
+++ b/app/models/communication/website/category.rb
@@ -59,7 +59,6 @@ class Communication::Website::Category < ApplicationRecord
 
 
   validates :name, presence: true
-  validates :slug, uniqueness: { scope: :website_id }
 
   scope :ordered, -> { order(:position) }
 
diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb
index 042b5bcf0..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
-  validates :path, uniqueness: { scope: :website_id }
 
   before_validation :make_path
   after_save :update_children_paths if :saved_change_to_path?
diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb
index 5896b97cd..51bbcec9b 100644
--- a/app/models/communication/website/post.rb
+++ b/app/models/communication/website/post.rb
@@ -49,12 +49,11 @@ class Communication::Website::Post < ApplicationRecord
                           foreign_key: 'communication_website_post_id',
                           association_foreign_key: 'communication_website_category_id'
 
-  validates :title, presence: true
-  validates :slug, uniqueness: { scope: :website_id }
-
   scope :ordered, -> { order(published_at: :desc, created_at: :desc) }
   scope :recent, -> { order(published_at: :desc).limit(5) }
 
+  validates :title, presence: true
+
   def github_path_generated
     "_posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html"
   end
diff --git a/app/models/concerns/with_slug.rb b/app/models/concerns/with_slug.rb
index 793e8f090..c13d07f01 100644
--- a/app/models/concerns/with_slug.rb
+++ b/app/models/concerns/with_slug.rb
@@ -2,6 +2,8 @@ module WithSlug
   extend ActiveSupport::Concern
 
   included do
+    validates :slug,
+              uniqueness: { scope: :university_id }
     validates :slug,
               format: { with: /\A[a-z0-9\-]+\z/, message: I18n.t('slug_error') }
   end
diff --git a/app/models/education/teacher.rb b/app/models/education/teacher.rb
index 33e0abb22..970d4a478 100644
--- a/app/models/education/teacher.rb
+++ b/app/models/education/teacher.rb
@@ -36,8 +36,6 @@ class Education::Teacher < ApplicationRecord
                           association_foreign_key: 'education_program_id'
   has_many :websites, -> { distinct }, through: :programs
 
-  validates :slug, uniqueness: { scope: :university_id }
-
   scope :ordered, -> { order(:last_name, :first_name) }
 
   def to_s
-- 
GitLab