]> git.openstreetmap.org Git - rails.git/blob - app/models/moderation_zone.rb
Merge remote-tracking branch 'upstream/pull/7060'
[rails.git] / app / models / moderation_zone.rb
1 # frozen_string_literal: true
2
3 # == Schema Information
4 #
5 # Table name: moderation_zones
6 #
7 #  id            :bigint           not null, primary key
8 #  name          :string           not null
9 #  reason        :string           not null
10 #  reason_format :enum             default("markdown")
11 #  zone          :st_polygon       not null, polygon, 4326
12 #  ends_at       :datetime
13 #  creator_id    :bigint           not null
14 #  revoker_id    :bigint
15 #  created_at    :datetime         not null
16 #  updated_at    :datetime         not null
17 #
18 # Indexes
19 #
20 #  index_moderation_zones_on_creator_id  (creator_id)
21 #  index_moderation_zones_on_revoker_id  (revoker_id)
22 #
23 # Foreign Keys
24 #
25 #  fk_rails_...  (creator_id => users.id)
26 #  fk_rails_...  (revoker_id => users.id)
27 #
28 class ModerationZone < ApplicationRecord
29   belongs_to :creator, :class_name => "User"
30   belongs_to :revoker, :class_name => "User", :optional => true
31
32   validates :name, :presence => true
33   validates :reason, :presence => true
34   validates :zone, :presence => true
35
36   def self.falls_within_any?(lon:, lat:)
37     factory = RGeo::Cartesian.simple_factory(:srid => 4326)
38     point = factory.point(lon, lat)
39
40     where(
41       arel_table[:zone].st_contains(point)
42     ).exists?
43   end
44 end