mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 16:12:51 +08:00
FIX: deleted misconfigured embeddable hosts (#19833)
When EmbeddableHost is configured for a specific category and that category is deleted, then EmbeddableHost should be deleted as well. In addition, migration was added to fix existing data.
This commit is contained in:
parent
de1922e656
commit
023accf6a8
|
@ -130,6 +130,7 @@ class Category < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :category_required_tag_groups, -> { order(order: :asc) }, dependent: :destroy
|
has_many :category_required_tag_groups, -> { order(order: :asc) }, dependent: :destroy
|
||||||
has_many :sidebar_section_links, as: :linkable, dependent: :delete_all
|
has_many :sidebar_section_links, as: :linkable, dependent: :delete_all
|
||||||
|
has_many :embeddable_hosts, dependent: :destroy
|
||||||
|
|
||||||
belongs_to :reviewable_by_group, class_name: "Group"
|
belongs_to :reviewable_by_group, class_name: "Group"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class DeleteMisconfiguredEmbeddableHosts < ActiveRecord::Migration[7.0]
|
||||||
|
def up
|
||||||
|
execute(<<~SQL)
|
||||||
|
DELETE FROM embeddable_hosts eh1
|
||||||
|
WHERE eh1.id IN (
|
||||||
|
SELECT eh2.id FROM embeddable_hosts eh2
|
||||||
|
LEFT JOIN categories ON categories.id = eh2.category_id
|
||||||
|
WHERE eh2.category_id IS NOT NULL
|
||||||
|
AND categories.id IS NULL
|
||||||
|
)
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
end
|
|
@ -577,6 +577,12 @@ RSpec.describe Category do
|
||||||
expect(SiteSetting.shared_drafts_category).to be_blank
|
expect(SiteSetting.shared_drafts_category).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "deletes related embeddable host" do
|
||||||
|
embeddable_host = Fabricate(:embeddable_host, category: @category)
|
||||||
|
@category.destroy!
|
||||||
|
expect { embeddable_host.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
|
end
|
||||||
|
|
||||||
it "triggers a extensibility event" do
|
it "triggers a extensibility event" do
|
||||||
event = DiscourseEvent.track(:category_destroyed) { @category.destroy }
|
event = DiscourseEvent.track(:category_destroyed) { @category.destroy }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user