From f5299ea6e96c4a4ad06a516452dd392d785a6948 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Tue, 28 Nov 2023 13:52:04 +0100 Subject: [PATCH] Implement notification settings migration [SCI-9790] --- app/models/user.rb | 9 ------- ...5_migrate_default_notification_settings.rb | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20231128123835_migrate_default_notification_settings.rb diff --git a/app/models/user.rb b/app/models/user.rb index 3c0deeffd..54c454875 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/db/migrate/20231128123835_migrate_default_notification_settings.rb b/db/migrate/20231128123835_migrate_default_notification_settings.rb new file mode 100644 index 000000000..9b0d4dbb5 --- /dev/null +++ b/db/migrate/20231128123835_migrate_default_notification_settings.rb @@ -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