Implement notification settings migration [SCI-9790]

This commit is contained in:
Martin Artnik 2023-11-28 13:52:04 +01:00
parent f3ee9a854f
commit f5299ea6e9
2 changed files with 26 additions and 9 deletions

View file

@ -607,8 +607,6 @@ class User < ApplicationRecord
if Rails.application.config.x.disable_local_passwords
throw(:warden, message: I18n.t('devise.failure.auth_method_disabled'))
end
update_notification_settings
end
def my_module_visible_table_columns
@ -659,11 +657,4 @@ class User < ApplicationRecord
def clear_view_cache
Rails.cache.delete_matched(%r{^views\/users\/#{id}-})
end
def update_notification_settings
if settings.dig(:notifications_settings, :my_module_designation, :in_app)
settings[:notifications_settings][:project_experiment_access][:in_app] = true
settings[:notifications_settings][:other_team_invitation][:in_app] = true
end
end
end

View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
class MigrateDefaultNotificationSettings < ActiveRecord::Migration[7.0]
def up
User.find_each do |user|
my_module_designation = user.settings.dig(:notifications_settings, :my_module_designation)
next unless my_module_designation
user.settings[:notifications_settings][:project_experiment_access] =
{
in_app: my_module_designation[:in_app],
email: my_module_designation[:email]
}
user.settings[:notifications_settings][:other_team_invitation] =
{
in_app: my_module_designation[:in_app],
email: my_module_designation[:email]
}
user.save!
end
end
def down; end
end