app/models/spotlight/exhibit.rb in blacklight-spotlight-3.0.0.rc2 vs app/models/spotlight/exhibit.rb in blacklight-spotlight-3.0.0.rc3
- old
+ new
@@ -2,10 +2,11 @@
require 'mail'
module Spotlight
##
# Spotlight exhibit
+ # rubocop:disable Metrics/ClassLength
class Exhibit < ActiveRecord::Base
class_attribute :themes_selector
include Spotlight::ExhibitAnalytics
include Spotlight::ExhibitDefaults
include Spotlight::ExhibitDocuments
@@ -20,15 +21,20 @@
scope :ordered_by_weight, -> { order('weight ASC') }
paginates_per 48
extend FriendlyId
- friendly_id :title, use: %i[slugged finders]
+ friendly_id :title, use: %i[slugged finders] do |config|
+ config.reserved_words&.concat(%w[site])
+ end
+
validates :title, presence: true, if: -> { I18n.locale == I18n.default_locale }
validates :slug, uniqueness: true
validates :theme, inclusion: { in: Spotlight::Engine.config.exhibit_themes }, allow_blank: true
+ after_validation :move_friendly_id_error_to_slug
+
acts_as_tagger
acts_as_taggable
delegate :blacklight_config, to: :blacklight_configuration
serialize :facets, Array
@@ -48,10 +54,11 @@
end
end
has_many :custom_search_fields, dependent: :delete_all
has_many :feature_pages, -> { for_default_locale }, extend: FriendlyId::FinderMethods
+ has_many :groups, dependent: :delete_all
has_many :main_navigations, dependent: :delete_all
has_many :reindexing_log_entries, dependent: :destroy
has_many :resources
has_many :roles, as: :resource, dependent: :delete_all
has_many :searches, dependent: :destroy, extend: FriendlyId::FinderMethods
@@ -68,11 +75,11 @@
belongs_to :site, optional: true
belongs_to :masthead, dependent: :destroy, optional: true
belongs_to :thumbnail, class_name: 'Spotlight::ExhibitThumbnail', dependent: :destroy, optional: true
- accepts_nested_attributes_for :about_pages, :attachments, :contacts, :custom_fields, :feature_pages, :languages,
+ accepts_nested_attributes_for :about_pages, :attachments, :contacts, :custom_fields, :feature_pages, :groups, :languages,
:main_navigations, :owned_taggings, :pages, :resources, :searches, :solr_document_sidecars, :translations
accepts_nested_attributes_for :blacklight_configuration, :home_page, :filters, update_only: true
accepts_nested_attributes_for :masthead, :thumbnail, update_only: true, reject_if: proc { |attr| attr['iiif_tilesource'].blank? }
accepts_nested_attributes_for :contact_emails, reject_if: proc { |attr| attr['email'].blank? }
accepts_nested_attributes_for :roles, allow_destroy: true, reject_if: proc { |attr| attr['user_key'].blank? && attr['id'].blank? }
@@ -149,7 +156,12 @@
private
def current_reindexing_log_entry
reindexing_log_entries.started_or_completed.first || reindexing_log_entries.build
end
+
+ def move_friendly_id_error_to_slug
+ errors.add :slug, *errors.delete(:friendly_id) if errors[:friendly_id].present?
+ end
end
+ # rubocop:enable Metrics/ClassLength
end