require "contacts/publisher"

class ContactGroup < ActiveRecord::Base
  extend ActiveHash::Associations::ActiveRecordExtensions
  include Versioning
  include FriendlyId

  belongs_to :organisation

  after_save :publish_finder

  friendly_id :title, use: :history

  has_many :contacts, through: :contact_memberships
  has_many :contact_memberships, dependent: :destroy

  belongs_to_active_hash :contact_group_type

  validates :title, presence: true
  validates :description, presence: true

  scope :most_popular, -> {
    where(contact_group_type_id: ContactGroupType.most_popular.id)
  }
  scope :except_most_popular, -> {
    where("contact_group_type_id != ?", ContactGroupType.most_popular.id)
  }
  scope :with_contacts, -> { includes(:contacts) }
  scope :by_title, -> { order("contact_groups.title ASC") }

  def to_s
    title
  end

private

  def publish_finder
    presenter = ContactsFinderPresenter.new(self.organisation)
    Contacts::Publisher.publish(presenter)
  end
end

require "contacts/publisher"

class ContactGroup < ActiveRecord::Base
  extend ActiveHash::Associations::ActiveRecordExtensions
  include Versioning
  include FriendlyId

  belongs_to :organisation

  # The line below is commented out in order to disable publishing of
  # Finders until we have Contacts within the Elastic Search index.
  #
  # after_save :publish_finder

  friendly_id :title, use: :history

  has_many :contacts, through: :contact_memberships
  has_many :contact_memberships, dependent: :destroy

  belongs_to_active_hash :contact_group_type

  validates :title, presence: true
  validates :description, presence: true

  scope :most_popular, -> {
    where(contact_group_type_id: ContactGroupType.most_popular.id)
  }
  scope :except_most_popular, -> {
    where("contact_group_type_id != ?", ContactGroupType.most_popular.id)
  }
  scope :with_contacts, -> { includes(:contacts) }
  scope :by_title, -> { order("contact_groups.title ASC") }

  def to_s
    title
  end

private

  def publish_finder
    presenter = ContactsFinderPresenter.new(self.organisation)
    Contacts::Publisher.publish(presenter)
  end
end

Disable Finder publishing for now
Disable Finder publishing for now

Publishing the Finder will take over the Index page for Contacts and
as they don't yet exist in the search index there's then no way to
browse them.

This commit disables the Finder publishing temporarily by commenting
it out and explaining why it is commented.
