2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
# requires scope "neighbors_of" to find translations in same scope
|
|
|
|
class KnowledgeBase
|
|
|
|
module HasUniqueTitle
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
validate :validate_title_uniqueness
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_title_uniqueness
|
|
|
|
return if self
|
|
|
|
.class
|
|
|
|
.where(kb_locale_id: kb_locale_id, title: title)
|
|
|
|
.where.not(id: id)
|
|
|
|
.neighbours_of(self)
|
|
|
|
.none?
|
|
|
|
|
|
|
|
errors.add(:title, 'is already used')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|