mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
At the moment there is no way in the UI to convert a category to nested replies. This introduces a backfill button and UI to show admin the current state (using category custom field). Screenshots pretty much tell the story: <img width="1483" height="1187" alt="Screenshot 2026-07-02 at 10 08 23 AM" src="https://github.com/user-attachments/assets/532bd7d2-8aae-455a-9744-aee0f3ac5b82" /> <img width="1498" height="1247" alt="Screenshot 2026-07-02 at 10 08 38 AM" src="https://github.com/user-attachments/assets/a1382732-8b72-4526-a770-72b6452b56bb" /> <img width="1460" height="1220" alt="Screenshot 2026-07-02 at 10 08 58 AM" src="https://github.com/user-attachments/assets/b4113347-c760-4f66-b947-988c270750a6" />
74 lines
2.5 KiB
Ruby
Vendored
74 lines
2.5 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class CategorySetting < ActiveRecord::Base
|
|
# TODO: drop columns require_topic_approval, require_reply_approval in a future migration
|
|
self.ignored_columns += %i[require_topic_approval require_reply_approval]
|
|
|
|
belongs_to :category
|
|
|
|
enum :topic_posting_review_mode,
|
|
{ no_one: 0, everyone: 1, everyone_except: 2, no_one_except: 3 },
|
|
prefix: true
|
|
enum :reply_posting_review_mode,
|
|
{ no_one: 0, everyone: 1, everyone_except: 2, no_one_except: 3 },
|
|
prefix: true
|
|
|
|
after_save :clear_nested_replies_conversion_completed,
|
|
if: :saved_change_to_nested_replies_default?
|
|
|
|
def require_topic_approval=(value)
|
|
self.topic_posting_review_mode =
|
|
ActiveModel::Type::Boolean.new.cast(value) ? :everyone : :no_one
|
|
end
|
|
|
|
def require_reply_approval=(value)
|
|
self.reply_posting_review_mode =
|
|
ActiveModel::Type::Boolean.new.cast(value) ? :everyone : :no_one
|
|
end
|
|
|
|
alias_method :require_topic_approval, :topic_posting_review_mode_everyone?
|
|
alias_method :require_topic_approval?, :topic_posting_review_mode_everyone?
|
|
alias_method :require_reply_approval, :reply_posting_review_mode_everyone?
|
|
alias_method :require_reply_approval?, :reply_posting_review_mode_everyone?
|
|
|
|
GROUP_BASED_MODES = %w[everyone_except no_one_except].freeze
|
|
|
|
validates :num_auto_bump_daily,
|
|
numericality: {
|
|
only_integer: true,
|
|
greater_than_or_equal_to: 0,
|
|
allow_nil: true,
|
|
}
|
|
|
|
validates :auto_bump_cooldown_days,
|
|
numericality: {
|
|
only_integer: true,
|
|
greater_than_or_equal_to: 0,
|
|
allow_nil: true,
|
|
}
|
|
|
|
private
|
|
|
|
def clear_nested_replies_conversion_completed
|
|
category.clear_nested_replies_conversion_completed! unless nested_replies_default?
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: category_settings
|
|
#
|
|
# id :bigint not null, primary key
|
|
# auto_bump_cooldown_days :integer default(1)
|
|
# nested_replies_default :boolean default(FALSE), not null
|
|
# num_auto_bump_daily :integer default(0)
|
|
# reply_posting_review_mode :integer default("no_one"), not null
|
|
# topic_posting_review_mode :integer default("no_one"), not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# category_id :bigint not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_category_settings_on_category_id (category_id) UNIQUE
|
|
#
|