From: Anton Khorev Date: Thu, 13 Mar 2025 15:49:27 +0000 (+0300) Subject: Create changeset subscription model X-Git-Tag: live~8^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/9d2342a41ab1eb6a6c2bba747bd29ff58f246258?hp=--cc Create changeset subscription model --- 9d2342a41ab1eb6a6c2bba747bd29ff58f246258 diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index bd3ea28bb..36f3b89dc 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -32,7 +32,7 @@ class Ability can :read, [:deletion, :account_terms, :account_pd_declaration, :account_home] if Settings.status != "database_offline" - can [:read, :create, :destroy], :changeset_subscription + can [:read, :create, :destroy], ChangesetSubscription can [:read, :create, :update, :destroy], :oauth2_application can [:read, :destroy], :oauth2_authorized_application can [:read, :create, :destroy], :oauth2_authorization diff --git a/app/controllers/changeset_subscriptions_controller.rb b/app/controllers/changeset_subscriptions_controller.rb index 6e0ad5257..27872a5e8 100644 --- a/app/controllers/changeset_subscriptions_controller.rb +++ b/app/controllers/changeset_subscriptions_controller.rb @@ -5,7 +5,7 @@ class ChangesetSubscriptionsController < ApplicationController before_action :set_locale before_action :check_database_writable - authorize_resource :class => :changeset_subscription + authorize_resource around_action :web_timeout diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 50b30c1a4..ccc67027a 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -41,7 +41,8 @@ class Changeset < ApplicationRecord has_many :old_relations has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "ChangesetComment" - has_and_belongs_to_many :subscribers, :class_name => "User", :join_table => "changesets_subscribers", :association_foreign_key => "subscriber_id" + has_many :subscriptions, :class_name => "ChangesetSubscription" + has_many :subscribers, :through => :subscriptions validates :id, :uniqueness => true, :presence => { :on => :update }, :numericality => { :on => :update, :only_integer => true } diff --git a/app/models/changeset_subscription.rb b/app/models/changeset_subscription.rb new file mode 100644 index 000000000..5a686f04f --- /dev/null +++ b/app/models/changeset_subscription.rb @@ -0,0 +1,23 @@ +# == Schema Information +# +# Table name: changesets_subscribers +# +# subscriber_id :bigint not null +# changeset_id :bigint not null +# +# Indexes +# +# index_changesets_subscribers_on_changeset_id (changeset_id) +# index_changesets_subscribers_on_subscriber_id_and_changeset_id (subscriber_id,changeset_id) UNIQUE +# +# Foreign Keys +# +# changesets_subscribers_changeset_id_fkey (changeset_id => changesets.id) +# changesets_subscribers_subscriber_id_fkey (subscriber_id => users.id) +# +class ChangesetSubscription < ApplicationRecord + self.table_name = "changesets_subscribers" + + belongs_to :subscriber, :class_name => "User" + belongs_to :changeset +end diff --git a/app/models/user.rb b/app/models/user.rb index a63846e42..695f29ed8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -63,7 +63,7 @@ class User < ApplicationRecord has_many :preferences, :class_name => "UserPreference" has_many :changesets, -> { order(:created_at => :desc) }, :inverse_of => :user has_many :changeset_comments, :foreign_key => :author_id, :inverse_of => :author - has_and_belongs_to_many :changeset_subscriptions, :class_name => "Changeset", :join_table => "changesets_subscribers", :foreign_key => "subscriber_id" + has_many :changeset_subscriptions, :foreign_key => :subscriber_id has_many :note_comments, :foreign_key => :author_id, :inverse_of => :author has_many :notes, :through => :note_comments has_many :note_subscriptions, :class_name => "NoteSubscription"