From 07e09fa21987c7e4692d9259d3370fbfc77389fa Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Tue, 13 Jan 2026 14:48:34 +0000 Subject: [PATCH] Add table+model to store geoblock zones --- app/models/moderation_zone.rb | 35 ++++++++ .../20260113144310_create_moderation_zones.rb | 18 ++++ db/structure.sql | 83 +++++++++++++++++++ test/models/moderation_zone_test.rb | 6 ++ 4 files changed, 142 insertions(+) create mode 100644 app/models/moderation_zone.rb create mode 100644 db/migrate/20260113144310_create_moderation_zones.rb create mode 100644 test/models/moderation_zone_test.rb diff --git a/app/models/moderation_zone.rb b/app/models/moderation_zone.rb new file mode 100644 index 000000000..2a26771db --- /dev/null +++ b/app/models/moderation_zone.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: moderation_zones +# +# id :bigint not null, primary key +# name :string not null +# reason :string not null +# reason_format :enum default("markdown") +# zone :st_polygon not null, polygon, 4326 +# ends_at :datetime +# creator_id :bigint not null +# revoker_id :bigint +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_moderation_zones_on_creator_id (creator_id) +# index_moderation_zones_on_revoker_id (revoker_id) +# +# Foreign Keys +# +# fk_rails_... (creator_id => users.id) +# fk_rails_... (revoker_id => users.id) +# +class ModerationZone < ApplicationRecord + belongs_to :creator, :class_name => "User" + belongs_to :revoker, :class_name => "User", :optional => true + + validates :name, :presence => true + validates :reason, :presence => true + validates :zone, :presence => true +end diff --git a/db/migrate/20260113144310_create_moderation_zones.rb b/db/migrate/20260113144310_create_moderation_zones.rb new file mode 100644 index 000000000..bb9af1b2e --- /dev/null +++ b/db/migrate/20260113144310_create_moderation_zones.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateModerationZones < ActiveRecord::Migration[8.1] + def change + create_table :moderation_zones do |t| + t.string :name, :null => false + t.string :reason, :null => false + t.column :reason_format, :format_enum, :default => "markdown" + t.st_polygon :zone, :srid => 4326, :null => false + t.datetime :ends_at + + t.references :creator, :null => false, :foreign_key => { :to_table => :users } + t.references :revoker, :foreign_key => { :to_table => :users } + + t.timestamps + end + end +end diff --git a/db/structure.sql b/db/structure.sql index ba27a3a9f..ed663bdae 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1017,6 +1017,43 @@ CREATE SEQUENCE public.messages_id_seq ALTER SEQUENCE public.messages_id_seq OWNED BY public.messages.id; +-- +-- Name: moderation_zones; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.moderation_zones ( + id bigint NOT NULL, + name character varying NOT NULL, + reason character varying NOT NULL, + reason_format public.format_enum DEFAULT 'markdown'::public.format_enum, + zone public.geometry(Polygon,4326) NOT NULL, + ends_at timestamp(6) without time zone, + creator_id bigint NOT NULL, + revoker_id bigint, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: moderation_zones_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.moderation_zones_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: moderation_zones_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.moderation_zones_id_seq OWNED BY public.moderation_zones.id; + + -- -- Name: node_tags; Type: TABLE; Schema: public; Owner: - -- @@ -1866,6 +1903,13 @@ ALTER TABLE ONLY public.issues ALTER COLUMN id SET DEFAULT nextval('public.issue ALTER TABLE ONLY public.messages ALTER COLUMN id SET DEFAULT nextval('public.messages_id_seq'::regclass); +-- +-- Name: moderation_zones id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.moderation_zones ALTER COLUMN id SET DEFAULT nextval('public.moderation_zones_id_seq'::regclass); + + -- -- Name: note_comments id; Type: DEFAULT; Schema: public; Owner: - -- @@ -2194,6 +2238,14 @@ ALTER TABLE ONLY public.messages ADD CONSTRAINT messages_pkey PRIMARY KEY (id); +-- +-- Name: moderation_zones moderation_zones_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.moderation_zones + ADD CONSTRAINT moderation_zones_pkey PRIMARY KEY (id); + + -- -- Name: node_tags node_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2739,6 +2791,20 @@ CREATE INDEX index_issues_on_status ON public.issues USING btree (status); CREATE INDEX index_issues_on_updated_by ON public.issues USING btree (updated_by); +-- +-- Name: index_moderation_zones_on_creator_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_moderation_zones_on_creator_id ON public.moderation_zones USING btree (creator_id); + + +-- +-- Name: index_moderation_zones_on_revoker_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_moderation_zones_on_revoker_id ON public.moderation_zones USING btree (revoker_id); + + -- -- Name: index_note_comments_on_author_id_and_created_at; Type: INDEX; Schema: public; Owner: - -- @@ -3296,6 +3362,14 @@ ALTER TABLE ONLY public.social_links ADD CONSTRAINT fk_rails_6034fd4f62 FOREIGN KEY (user_id) REFERENCES public.users(id); +-- +-- Name: moderation_zones fk_rails_6a0b70e3da; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.moderation_zones + ADD CONSTRAINT fk_rails_6a0b70e3da FOREIGN KEY (creator_id) REFERENCES public.users(id); + + -- -- Name: oauth_access_tokens fk_rails_732cb83ab7; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -3368,6 +3442,14 @@ ALTER TABLE ONLY public.oauth_access_tokens ADD CONSTRAINT fk_rails_ee63f25419 FOREIGN KEY (resource_owner_id) REFERENCES public.users(id) NOT VALID; +-- +-- Name: moderation_zones fk_rails_f2132b7340; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.moderation_zones + ADD CONSTRAINT fk_rails_f2132b7340 FOREIGN KEY (revoker_id) REFERENCES public.users(id); + + -- -- Name: friends friends_friend_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -3701,6 +3783,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('21'), ('20260223105922'), ('20260218183352'), +('20260113144310'), ('20260113142804'), ('20251218105716'), ('20251121134648'), diff --git a/test/models/moderation_zone_test.rb b/test/models/moderation_zone_test.rb new file mode 100644 index 000000000..e927b8aea --- /dev/null +++ b/test/models/moderation_zone_test.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +require "test_helper" + +class ModerationZoneTest < ActiveSupport::TestCase +end -- 2.39.5