]> git.openstreetmap.org Git - rails.git/commitdiff
Create changeset subscription model
authorAnton Khorev <tony29@yandex.ru>
Thu, 13 Mar 2025 15:49:27 +0000 (18:49 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 13 Mar 2025 17:09:01 +0000 (20:09 +0300)
app/abilities/ability.rb
app/controllers/changeset_subscriptions_controller.rb
app/models/changeset.rb
app/models/changeset_subscription.rb [new file with mode: 0644]
app/models/user.rb

index bd3ea28bb1e18f151ef593b1c854a4771021f9f0..36f3b89dc355a6ce64203aa366c9daf7fca5b79c 100644 (file)
@@ -32,7 +32,7 @@ class Ability
       can :read, [:deletion, :account_terms, :account_pd_declaration, :account_home]
 
       if Settings.status != "database_offline"
       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
         can [:read, :create, :update, :destroy], :oauth2_application
         can [:read, :destroy], :oauth2_authorized_application
         can [:read, :create, :destroy], :oauth2_authorization
index 6e0ad5257e8ce90de8d8547a8a5eb27888e297b4..27872a5e8fe1607d143dcad604e99e6cd108d229 100644 (file)
@@ -5,7 +5,7 @@ class ChangesetSubscriptionsController < ApplicationController
   before_action :set_locale
   before_action :check_database_writable
 
   before_action :set_locale
   before_action :check_database_writable
 
-  authorize_resource :class => :changeset_subscription
+  authorize_resource
 
   around_action :web_timeout
 
 
   around_action :web_timeout
 
index 50b30c1a4c6c409fd890f343f5f62503095a0cdd..ccc67027ab2961bf8b77da2e864431954c4b0c94 100644 (file)
@@ -41,7 +41,8 @@ class Changeset < ApplicationRecord
   has_many :old_relations
 
   has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "ChangesetComment"
   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 }
 
   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 (file)
index 0000000..5a686f0
--- /dev/null
@@ -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
index a63846e421f917044560852bb3c07ded3ed00649..695f29ed8d3f2713b5e89ee632f31bc478e81228 100644 (file)
@@ -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_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"
   has_many :note_comments, :foreign_key => :author_id, :inverse_of => :author
   has_many :notes, :through => :note_comments
   has_many :note_subscriptions, :class_name => "NoteSubscription"