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