DEV: Convert tl4_delete_posts_and_topics to groups (#24866)

We're changing the implementation of trust levels to use groups. Part of this is to have site settings that reference trust levels use groups instead. It converts the tl4_delete_posts_and_topics  site setting to delete_all_posts_and_topics_allowed_groups.

This one is a bit different from previous ones, as it's a boolean flag, and the default should be no group. Pay special attention to the migration during review.
This commit is contained in:
Ted Johansson
2023-12-14 09:56:42 +08:00
committed by GitHub
parent 2a1952d9ba
commit 48116186af
9 changed files with 56 additions and 16 deletions

View File

@@ -0,0 +1,28 @@
# frozen_string_literal: true
class FillDeleteAllPostsAndTopicsAllowedGroupsBasedOnDeprecatedSettings < ActiveRecord::Migration[
7.0
]
def up
currently_enabled =
DB.query_single(
"SELECT value FROM site_settings WHERE name = 'tl4_delete_posts_and_topics' AND value = 't' LIMIT 1",
).first
if currently_enabled == "t"
# Matches Group::AUTO_GROUPS to the trust levels.
tl4 = "14"
# Data_type 20 is group_list.
DB.exec(
"INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('delete_all_posts_and_topics_allowed_groups', :setting, '20', NOW(), NOW())",
setting: tl4,
)
end
end
def down
raise ActiveRecord::IrreversibleMigrationError
end
end