summaryrefslogtreecommitdiffstats
path: root/app/models/custom_filter_status.rb
blob: 58b61cd79d40215cd9645522b4144f841b6c6d5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

# == Schema Information
#
# Table name: custom_filter_statuses
#
#  id               :bigint(8)        not null, primary key
#  custom_filter_id :bigint(8)        not null
#  status_id        :bigint(8)        not null
#  created_at       :datetime         not null
#  updated_at       :datetime         not null
#

class CustomFilterStatus < ApplicationRecord
  include CustomFilterCache

  belongs_to :custom_filter
  belongs_to :status

  validates :status, uniqueness: { scope: :custom_filter }
  validate :validate_status_access

  private

  def validate_status_access
    errors.add(:status_id, :invalid) unless StatusPolicy.new(custom_filter.account, status).show?
  end
end