DEV: Switch over category settings to new table - Part 3 (#20657)

In #20135 we prevented invalid inputs from being accepted in category setting form fields on the front-end. We didn't do anything on the back-end at that time, because we were still discussing which path we wanted to take. Eventually we decided we want to move this to a new CategorySetting model.

This PR moves the require_topic_approval and require_reply_approval from custom fields to the new CategorySetting model.

This PR is nearly identical to #20580, which migrated num_auto_bump_daily, but since these are slightly more sensitive, they are moved after the previous one is verified.
This commit is contained in:
Ted Johansson
2023-09-12 09:51:49 +08:00
committed by GitHub
parent 07c29f3066
commit f08c6d2756
13 changed files with 178 additions and 51 deletions

View File

@ -60,7 +60,7 @@ RSpec.describe NewPostManager do
tag3 = Fabricate(:tag)
tag_group = Fabricate(:tag_group, tags: [tag2])
category = Fabricate(:category, tags: [tag1], tag_groups: [tag_group])
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
category.require_topic_approval = true
category.save!
manager =
@ -498,7 +498,7 @@ RSpec.describe NewPostManager do
context "when new topics require approval" do
before do
SiteSetting.tagging_enabled = true
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
category.require_topic_approval = true
category.save
end
@ -625,7 +625,7 @@ RSpec.describe NewPostManager do
let!(:topic) { Fabricate(:topic, category: category) }
before do
category.custom_fields[Category::REQUIRE_REPLY_APPROVAL] = true
category.require_reply_approval = true
category.save
end

View File

@ -83,7 +83,7 @@ RSpec.describe PostRevisor do
it "does not revise category when the destination category requires topic approval" do
new_category = Fabricate(:category)
new_category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
new_category.require_topic_approval = true
new_category.save!
post = create_post
@ -92,7 +92,7 @@ RSpec.describe PostRevisor do
post.revise(post.user, category_id: new_category.id)
expect(post.reload.topic.category_id).to eq(old_category_id)
new_category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = false
new_category.require_topic_approval = false
new_category.save!
post.revise(post.user, category_id: new_category.id)

View File

@ -1004,9 +1004,14 @@ RSpec.describe TopicView do
describe "#reviewable_counts" do
it "exclude posts queued because the category needs approval" do
category = Fabricate.build(:category, user: admin)
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
category.save!
category =
Fabricate.create(
:category,
user: admin,
category_setting_attributes: {
require_topic_approval: true,
},
)
manager =
NewPostManager.new(
user,
@ -1081,13 +1086,16 @@ RSpec.describe TopicView do
let(:queue_enabled) { false }
context "when category is moderated" do
before { category.custom_fields[Category::REQUIRE_REPLY_APPROVAL] = true }
before do
category.require_reply_approval = true
category.save!
end
it { expect(topic_view.queued_posts_enabled?).to be(true) }
end
context "when category is not moderated" do
it { expect(topic_view.queued_posts_enabled?).to be(nil) }
it { expect(topic_view.queued_posts_enabled?).to be(false) }
end
end
end