]> git.openstreetmap.org Git - rails.git/blob - app/models/user_mute.rb
Update secondary nav active item highlight from js router
[rails.git] / app / models / user_mute.rb
1 # == Schema Information
2 #
3 # Table name: user_mutes
4 #
5 #  id         :bigint(8)        not null, primary key
6 #  owner_id   :bigint(8)        not null
7 #  subject_id :bigint(8)        not null
8 #  created_at :datetime         not null
9 #  updated_at :datetime         not null
10 #
11 # Indexes
12 #
13 #  index_user_mutes_on_owner_id_and_subject_id  (owner_id,subject_id) UNIQUE
14 #
15 # Foreign Keys
16 #
17 #  fk_rails_...  (owner_id => users.id)
18 #  fk_rails_...  (subject_id => users.id)
19 #
20 class UserMute < ApplicationRecord
21   belongs_to :owner, :class_name => "User"
22   belongs_to :subject, :class_name => "User"
23
24   validates :subject, :uniqueness => { :scope => :owner_id, :message => :is_already_muted }
25
26   def self.active?(owner:, subject:)
27     !subject.administrator? &&
28       !subject.moderator? &&
29       exists?(
30         :owner => owner,
31         :subject => subject
32       )
33   end
34 end