DEV: Convert review_media_unless_trust_level to group-based setting (#25201)

This commit moves the review_media_unless_trust_level setting
to skip_review_media_groups as part of our move from TL to group
based settings.

c.f. https://meta.discourse.org/t/changes-coming-to-settings-for-giving-access-to-features-from-trust-levels-to-groups/283408
This commit is contained in:
Martin Brennan 2024-01-11 13:43:01 +10:00 committed by GitHub
parent 6ebe61ecec
commit 08d641d932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 9 deletions

View File

@ -14,7 +14,7 @@ class ReviewableScoreSerializer < ApplicationSerializer
invite_only: "invite_only", invite_only: "invite_only",
email_spam: "email_in_spam_header", email_spam: "email_in_spam_header",
suspect_user: "approve_suspect_users", suspect_user: "approve_suspect_users",
contains_media: "review_media_unless_trust_level", contains_media: "skip_media_review_groups",
} }
attributes :id, :score, :agree_stats, :reason, :created_at, :reviewed_at attributes :id, :score, :agree_stats, :reason, :created_at, :reviewed_at

View File

@ -2362,6 +2362,7 @@ en:
returning_user_notice_tl: "Minimum trust level required to see returning user post notices." returning_user_notice_tl: "Minimum trust level required to see returning user post notices."
returning_users_days: "How many days should pass before a user is considered to be returning." returning_users_days: "How many days should pass before a user is considered to be returning."
review_media_unless_trust_level: "Staff will review posts of users with lower trust levels if they contain embedded media." review_media_unless_trust_level: "Staff will review posts of users with lower trust levels if they contain embedded media."
skip_review_media_groups: "Users who are not in any of these groups will have their posts sent to staff for review if the post contains embedded media."
blur_tl0_flagged_posts_media: "Blur flagged posts images to hide potentially NSFW content." blur_tl0_flagged_posts_media: "Blur flagged posts images to hide potentially NSFW content."
enable_page_publishing: "Allow staff members to publish topics to new URLs with their own styling." enable_page_publishing: "Allow staff members to publish topics to new URLs with their own styling."
show_published_pages_login_required: "Anonymous users can see published pages, even when login is required." show_published_pages_login_required: "Anonymous users can see published pages, even when login is required."
@ -2582,6 +2583,7 @@ en:
self_wiki_allowed_groups: "min_trust_to_allow_self_wiki" self_wiki_allowed_groups: "min_trust_to_allow_self_wiki"
create_tag_allowed_groups: "min_trust_to_create_tag" create_tag_allowed_groups: "min_trust_to_create_tag"
send_email_messages_allowed_groups: "min_trust_to_send_email_messages" send_email_messages_allowed_groups: "min_trust_to_send_email_messages"
skip_review_media_groups: "review_media_unless_trust_level"
placeholder: placeholder:
discourse_connect_provider_secrets: discourse_connect_provider_secrets:

View File

@ -1149,6 +1149,13 @@ posting:
review_media_unless_trust_level: review_media_unless_trust_level:
default: 0 default: 0
enum: "TrustLevelSetting" enum: "TrustLevelSetting"
hidden: true
skip_review_media_groups:
default: "10" # TL0 auto group
type: group_list
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
blur_tl0_flagged_posts_media: blur_tl0_flagged_posts_media:
default: true default: true
client: true client: true

View File

@ -0,0 +1,24 @@
# frozen_string_literal: true
class FillSkipReviewMediaGroupsBasedOnDeprecatedSetting < ActiveRecord::Migration[7.0]
def up
old_setting_trust_level =
DB.query_single(
"SELECT value FROM site_settings WHERE name = 'review_media_unless_trust_level' LIMIT 1",
).first
if old_setting_trust_level.present?
allowed_groups = "1#{old_setting_trust_level}"
DB.exec(
"INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('skip_review_media_groups', :setting, '20', NOW(), NOW())",
setting: allowed_groups,
)
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -117,7 +117,7 @@ class NewPostManager
if ( if (
manager.args[:image_sizes].present? && manager.args[:image_sizes].present? &&
user.trust_level < SiteSetting.review_media_unless_trust_level.to_i !user.in_any_groups?(SiteSetting.skip_review_media_groups_map)
) )
return :contains_media return :contains_media
end end

View File

@ -36,6 +36,7 @@ module SiteSettings::DeprecatedSettings
["min_trust_to_allow_self_wiki", "self_wiki_allowed_groups", false, "3.3"], ["min_trust_to_allow_self_wiki", "self_wiki_allowed_groups", false, "3.3"],
["min_trust_to_create_tag", "create_tag_allowed_groups", false, "3.3"], ["min_trust_to_create_tag", "create_tag_allowed_groups", false, "3.3"],
["min_trust_to_send_email_messages", "send_email_messages_allowed_groups", false, "3.3"], ["min_trust_to_send_email_messages", "send_email_messages_allowed_groups", false, "3.3"],
["review_media_unless_trust_level", "skip_review_media_groups", false, "3.3"],
] ]
OVERRIDE_TL_GROUP_SETTINGS = %w[ OVERRIDE_TL_GROUP_SETTINGS = %w[
@ -56,6 +57,7 @@ module SiteSettings::DeprecatedSettings
min_trust_level_to_allow_ignore min_trust_level_to_allow_ignore
min_trust_to_create_tag min_trust_to_create_tag
min_trust_to_send_email_messages min_trust_to_send_email_messages
review_media_unless_trust_level
] ]
def group_to_tl(old_setting, new_setting) def group_to_tl(old_setting, new_setting)

View File

@ -302,10 +302,13 @@ RSpec.describe NewPostManager do
} }
end end
before { user.update!(trust_level: 0) } before do
user.update!(trust_level: 0)
Group.refresh_automatic_groups!
end
it "queues the post for review because if it contains embedded media." do it "queues the post for review because it contains embedded media" do
SiteSetting.review_media_unless_trust_level = 1 SiteSetting.skip_review_media_groups = Group::AUTO_GROUPS[:trust_level_1]
manager = NewPostManager.new(user, manager_opts) manager = NewPostManager.new(user, manager_opts)
result = NewPostManager.default_handler(manager) result = NewPostManager.default_handler(manager)
@ -315,7 +318,7 @@ RSpec.describe NewPostManager do
end end
it "does not enqueue the post if the poster is a trusted user" do it "does not enqueue the post if the poster is a trusted user" do
SiteSetting.review_media_unless_trust_level = 0 SiteSetting.skip_review_media_groups = Group::AUTO_GROUPS[:trust_level_0]
manager = NewPostManager.new(user, manager_opts) manager = NewPostManager.new(user, manager_opts)
result = NewPostManager.default_handler(manager) result = NewPostManager.default_handler(manager)

View File

@ -1,14 +1,14 @@
# frozen_string_literal: true # frozen_string_literal: true
describe "Composer using review_media", type: :system do describe "Composer using review_media", type: :system do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) } fab!(:current_user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:topic) { Fabricate(:topic, category: Category.find(SiteSetting.uncategorized_category_id)) } fab!(:topic) { Fabricate(:topic, category: Category.find(SiteSetting.uncategorized_category_id)) }
fab!(:post) { Fabricate(:post, topic: topic) } fab!(:post) { Fabricate(:post, topic: topic) }
let(:topic_page) { PageObjects::Pages::Topic.new } let(:topic_page) { PageObjects::Pages::Topic.new }
before do before do
SiteSetting.review_media_unless_trust_level = 3 SiteSetting.skip_review_media_groups = Group::AUTO_GROUPS[:trust_level_3]
sign_in user sign_in(current_user)
end end
it "does not flag a post with an emoji" do it "does not flag a post with an emoji" do