mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add skin migrations for glitch-soc
This commit is contained in:
@@ -54,7 +54,7 @@ module ThemeHelper
|
|||||||
|
|
||||||
def current_skin
|
def current_skin
|
||||||
skins = Themes.instance.skins_for(current_flavour)
|
skins = Themes.instance.skins_for(current_flavour)
|
||||||
[current_user&.setting_skin, Setting.skin, 'system', 'default'].find { |skin| skins.include?(skin) }
|
[current_user&.setting_skin, Setting.skin, 'default'].find { |skin| skins.include?(skin) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_theme
|
def current_theme
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class GlitchMigrateDefaultSkinSetting < ActiveRecord::Migration[8.0]
|
||||||
|
class Setting < ApplicationRecord; end
|
||||||
|
|
||||||
|
def up
|
||||||
|
Setting.reset_column_information
|
||||||
|
|
||||||
|
return unless %w(glitch vanilla).include?(flavour)
|
||||||
|
|
||||||
|
setting = Setting.find_by(var: 'skin')
|
||||||
|
return unless setting.present? && setting.attributes['value'].present?
|
||||||
|
|
||||||
|
theme = YAML.safe_load(setting.attributes['value'], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol])
|
||||||
|
return unless %w(mastodon-light contrast system).include?(theme)
|
||||||
|
|
||||||
|
setting.update_column('value', "--- default\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
def down; end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def flavour
|
||||||
|
setting = Setting.find_by(var: 'flavour')
|
||||||
|
return 'glitch' unless setting.present? && setting.attributes['value'].present?
|
||||||
|
|
||||||
|
YAML.safe_load(setting.attributes['value'], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol])
|
||||||
|
end
|
||||||
|
end
|
||||||
31
db/migrate/20260209143307_glitch_migrate_user_skin.rb
Normal file
31
db/migrate/20260209143307_glitch_migrate_user_skin.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class GlitchMigrateUserSkin < ActiveRecord::Migration[8.0]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
# Dummy classes, to make migration possible across version changes
|
||||||
|
class User < ApplicationRecord; end
|
||||||
|
|
||||||
|
def up
|
||||||
|
User.where.not(settings: nil).find_each do |user|
|
||||||
|
settings = Oj.load(user.attributes_before_type_cast['settings'])
|
||||||
|
next if settings.nil? || settings['skin'].blank? || %w(system default mastodon-light contrast).exclude?(settings['skin'])
|
||||||
|
|
||||||
|
case settings['skin']
|
||||||
|
when 'default'
|
||||||
|
settings['web.color_scheme'] = 'dark'
|
||||||
|
settings['web.contrast'] = 'auto'
|
||||||
|
when 'contrast'
|
||||||
|
settings['web.color_scheme'] = 'dark'
|
||||||
|
settings['web.contrast'] = 'high'
|
||||||
|
when 'mastodon-light'
|
||||||
|
settings['web.color_scheme'] = 'light'
|
||||||
|
settings['web.contrast'] = 'auto'
|
||||||
|
end
|
||||||
|
|
||||||
|
settings['skin'] = 'default'
|
||||||
|
|
||||||
|
user.update_column('settings', Oj.dump(settings))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -154,7 +154,7 @@ namespace :tests do
|
|||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless Setting.theme == 'default'
|
unless Setting.skin == 'default'
|
||||||
puts 'Default theme setting not migrated as expected'
|
puts 'Default theme setting not migrated as expected'
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
@@ -183,7 +183,8 @@ namespace :tests do
|
|||||||
VALUES
|
VALUES
|
||||||
(7, NULL, NULL, 'timeline_preview', E'--- false\n', now(), now()),
|
(7, NULL, NULL, 'timeline_preview', E'--- false\n', now(), now()),
|
||||||
(8, NULL, NULL, 'trends_as_landing_page', E'--- false\n', now(), now()),
|
(8, NULL, NULL, 'trends_as_landing_page', E'--- false\n', now(), now()),
|
||||||
(9, NULL, NULL, 'theme', E'--- system', now(), now());
|
(9, NULL, NULL, 'theme', E'--- system', now(), now()),
|
||||||
|
(1000, NULL, NULL, 'skin', E'--- system', now(), now());
|
||||||
|
|
||||||
/* Doorkeeper records
|
/* Doorkeeper records
|
||||||
While the `read:me` scope was technically not valid in 3.3.0,
|
While the `read:me` scope was technically not valid in 3.3.0,
|
||||||
|
|||||||
Reference in New Issue
Block a user