Fix language settings for users having selected the kmr language (#26787)

这个提交包含在:
Claire 2023-09-04 17:56:31 +02:00 提交者 GitHub
父节点 ece1ff77d6
当前提交 cddef4c485
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 3 个文件被更改,包括 58 次插入2 次删除

查看文件

@ -0,0 +1,27 @@
# frozen_string_literal: true
class FixKmrLocaleSettings < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
class MigrationUser < ApplicationRecord
self.table_name = :users
end
def up
MigrationUser.reset_column_information
MigrationUser.where.not(settings: [nil, '{}']).find_each do |user|
user_settings = Oj.load(user.settings)
next unless user_settings['default_language'] == 'kmr'
user_settings['default_language'] = 'ku'
user.update!(settings: Oj.dump(user_settings))
end
MigrationUser.where.not(chosen_languages: nil).where('chosen_languages && ?', '{kmr}').find_each do |user|
user.update!(chosen_languages: user.chosen_languages.map { |lang| lang == 'kmr' ? 'ku' : lang }.uniq)
end
end
def down; end
end

查看文件

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_08_22_081029) do ActiveRecord::Schema[7.0].define(version: 2023_09_04_134623) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"

查看文件

@ -68,10 +68,24 @@ namespace :tests do
puts 'Preview cards not deduplicated as expected' puts 'Preview cards not deduplicated as expected'
exit(1) exit(1)
end end
unless Account.find_local('kmruser').user.chosen_languages == %w(en ku ckb)
puts 'Chosen languages not migrated as expected for kmr users'
exit(1)
end
unless Account.find_local('kmruser').user.settings['default_language'] == 'ku'
puts 'Default posting language not migrated as expected for kmr users'
exit(1)
end
end end
desc 'Populate the database with test data for 2.4.3' desc 'Populate the database with test data for 2.4.3'
task populate_v2_4_3: :environment do # rubocop:disable Naming/VariableNumber task populate_v2_4_3: :environment do # rubocop:disable Naming/VariableNumber
user_key = OpenSSL::PKey::RSA.new(2048)
user_private_key = ActiveRecord::Base.connection.quote(user_key.to_pem)
user_public_key = ActiveRecord::Base.connection.quote(user_key.public_key.to_pem)
ActiveRecord::Base.connection.execute(<<~SQL) ActiveRecord::Base.connection.execute(<<~SQL)
INSERT INTO "custom_filters" INSERT INTO "custom_filters"
(id, account_id, phrase, context, whole_word, irreversible, created_at, updated_at) (id, account_id, phrase, context, whole_word, irreversible, created_at, updated_at)
@ -118,6 +132,21 @@ namespace :tests do
(id, thing_type, thing_id, var, value, created_at, updated_at) (id, thing_type, thing_id, var, value, created_at, updated_at)
VALUES VALUES
(3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\ntrending_tag: true\nappeal: true\n', now(), now()); (3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\ntrending_tag: true\nappeal: true\n', now(), now());
INSERT INTO "accounts"
(id, username, domain, private_key, public_key, created_at, updated_at)
VALUES
(10, 'kmruser', NULL, #{user_private_key}, #{user_public_key}, now(), now());
INSERT INTO "users"
(id, account_id, email, created_at, updated_at, admin, locale, chosen_languages)
VALUES
(4, 10, 'kmruser@localhost', now(), now(), false, 'ku', '{en,kmr,ku,ckb}');
INSERT INTO "settings"
(id, thing_type, thing_id, var, value, created_at, updated_at)
VALUES
(4, 'User', 4, 'default_language', E'--- kmr\n', now(), now());
SQL SQL
end end
@ -197,7 +226,7 @@ namespace :tests do
INSERT INTO "users" INSERT INTO "users"
(id, account_id, email, created_at, updated_at, admin, locale) (id, account_id, email, created_at, updated_at, admin, locale)
VALUES VALUES
(3, 7, 'ptuser@localhost', now(), now(), false, 'pt'); (3, 8, 'ptuser@localhost', now(), now(), false, 'pt');
-- conversations -- conversations
INSERT INTO "conversations" (id, created_at, updated_at) VALUES (1, now(), now()); INSERT INTO "conversations" (id, created_at, updated_at) VALUES (1, now(), now());