mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 11:58:27 +00:00
Currently when a category is deleted, if it has an associated chat channel, the latter won’t be deleted automatically. The fix is quite simple as we were simply missing a `dependent: :destroy` option on the existing relation.
20 lines
435 B
Ruby
20 lines
435 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Chat::CategoryExtension
|
|
extend ActiveSupport::Concern
|
|
|
|
include Chatable
|
|
|
|
prepended { has_one :category_channel, as: :chatable, dependent: :destroy }
|
|
|
|
def cannot_delete_reason
|
|
return I18n.t("category.cannot_delete.has_chat_channels") if category_channel
|
|
super
|
|
end
|
|
|
|
def deletable_for_chat?
|
|
return true if !category_channel
|
|
category_channel.chat_messages_empty?
|
|
end
|
|
end
|