DEV: Convert approve_new_topics_unless_trust_level to groups (#24504)

* DEV: Convert approve_new_topics_unless_trust_level to groups

This change converts the `approve_new_topics_unless_trust_level` site
setting to `approve_new_topics_unless_allowed_groups`.

See: https://meta.discourse.org/t/283408

- Hides the old setting
- Adds the new site setting
- Add a deprecation warning
- Updates to use the new setting
- Adds a migration to fill in the new setting if the old setting was
  changed
- Adds an entry to the site_setting.keywords section
- Updates tests to account for the new change

After a couple of months we will remove the
`approve_new_topics_unless_trust_level` setting entirely.

Internal ref: /t/115696

* add missing translation

* Add keyword entry

* Add migration
This commit is contained in:
Blake Erickson 2023-11-22 10:44:59 -07:00 committed by GitHub
parent c766125fe8
commit 8a45f84277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 9 deletions

View File

@ -6,6 +6,7 @@ class ReviewableScoreSerializer < ApplicationSerializer
trust_level: "approve_unless_trust_level",
group: "approve_unless_allowed_groups",
new_topics_unless_trust_level: "approve_new_topics_unless_trust_level",
new_topics_unless_allowed_groups: "approve_new_topics_unless_allowed_groups",
fast_typer: "min_first_post_typing_time",
auto_silence_regex: "auto_silence_first_post_regex",
staged: "approve_unless_staged",

View File

@ -2321,6 +2321,7 @@ en:
approve_unless_trust_level: "Posts for users below this trust level must be approved"
approve_unless_allowed_groups: "Posts for users not in these groups must be approved"
approve_new_topics_unless_trust_level: "New topics for users below this trust level must be approved"
approve_new_topics_unless_allowed_groups: "New topics for users not in these groups must be approved"
approve_unless_staged: "New topics and posts for staged users must be approved"
notify_about_queued_posts_after: "If there are posts that have been waiting to be reviewed for more than this many hours, send a notification to all moderators. Set to 0 to disable these notifications."
reviewable_revision_reasons: "List of reasons that can be selected when rejecting a reviewable queued post with a revision. Other is always available as well, which allows for a custom reason to be entered."
@ -2545,6 +2546,7 @@ en:
here_mention_allowed_groups: "min_trust_level_for_here_mention"
shared_drafts_allowed_groups: "shared_drafts_min_trust_level"
approve_unless_allowed_groups: "approve_unless_trust_level"
approve_new_topics_unless_allowed_groups: "approve_new_topics_unless_trust_level"
placeholder:
discourse_connect_provider_secrets:

View File

@ -1075,6 +1075,13 @@ posting:
approve_new_topics_unless_trust_level:
default: 0
enum: "TrustLevelSetting"
hidden: true
approve_new_topics_unless_allowed_groups:
default: 10
type: group_list
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
approve_suspect_users:
default: true
approve_unless_staged:

View File

@ -0,0 +1,27 @@
# frozen_string_literal: true
class FillNewTopicsUnlessAllowedGroupsBasedOnDeprecatedSettings < ActiveRecord::Migration[7.0]
def up
approve_new_topics_unless_trust_level_raw =
DB.query_single(
"SELECT value FROM site_settings WHERE name = 'approve_new_topics_unless_trust_level' LIMIT 1",
).first
# Default for old setting is TL0, we only need to do anything if it's been changed in the DB.
if approve_new_topics_unless_trust_level_raw.present?
# Matches Group::AUTO_GROUPS to the trust levels.
approve_new_topics_unless_allowed_groups = "1#{approve_new_topics_unless_trust_level_raw}"
# Data_type 20 is group_list
DB.exec(
"INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('approve_new_topics_unless_allowed_groups', :setting, '20', NOW(), NOW())",
setting: approve_new_topics_unless_allowed_groups,
)
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -97,10 +97,10 @@ class NewPostManager
end
if (
manager.args[:title].present? &&
user.trust_level < SiteSetting.approve_new_topics_unless_trust_level.to_i
manager.args[:title].present? && user.groups.any? &&
!user.in_any_groups?(SiteSetting.approve_new_topics_unless_allowed_groups_map)
)
return :new_topics_unless_trust_level
return :new_topics_unless_allowed_groups
end
if WordWatcher.new("#{manager.args[:title]} #{manager.args[:raw]}").requires_approval?
@ -205,9 +205,13 @@ class NewPostManager
SiteSetting.approve_post_count > 0 ||
!(
SiteSetting.approve_unless_allowed_groups_map.include?(Group::AUTO_GROUPS[:trust_level_0])
) || SiteSetting.approve_new_topics_unless_trust_level.to_i > 0 ||
SiteSetting.approve_unless_staged || WordWatcher.words_for_action_exist?(:require_approval) ||
handlers.size > 1
) ||
!(
SiteSetting.approve_new_topics_unless_allowed_groups_map.include?(
Group::AUTO_GROUPS[:trust_level_0],
)
) || SiteSetting.approve_unless_staged ||
WordWatcher.words_for_action_exist?(:require_approval) || handlers.size > 1
end
def initialize(user, args)

View File

@ -12,6 +12,12 @@ module SiteSettings::DeprecatedSettings
["shared_drafts_min_trust_level", "shared_drafts_allowed_groups", false, "3.3"],
["min_trust_level_for_here_mention", "here_mention_allowed_groups", false, "3.3"],
["approve_unless_trust_level", "approve_unless_allowed_groups", false, "3.3"],
[
"approve_new_topics_unless_trust_level",
"approve_new_topics_unless_allowed_groups",
false,
"3.3",
],
]
def setup_deprecated_methods

View File

@ -249,7 +249,9 @@ RSpec.describe NewPostManager do
end
context "with a high trust level setting for new topics but post responds to existing topic" do
before { SiteSetting.approve_new_topics_unless_trust_level = 4 }
before do
SiteSetting.approve_new_topics_unless_allowed_groups = Group::AUTO_GROUPS[:trust_level_4]
end
it "doesn't return a result action" do
result = NewPostManager.default_handler(manager)
expect(result).to eq(nil)
@ -329,14 +331,14 @@ RSpec.describe NewPostManager do
end
context "with a high trust level setting for new topics" do
before do
SiteSetting.approve_new_topics_unless_trust_level = 4
SiteSetting.approve_new_topics_unless_allowed_groups = Group::AUTO_GROUPS[:trust_level_4]
Group.refresh_automatic_groups!
end
it "will return an enqueue result" do
result = NewPostManager.default_handler(manager)
expect(NewPostManager.queue_enabled?).to eq(true)
expect(result.action).to eq(:enqueued)
expect(result.reason).to eq(:new_topics_unless_trust_level)
expect(result.reason).to eq(:new_topics_unless_allowed_groups)
end
end
end