Merge pull request #9800 from opf/feature/38671/reset-all-notifications

[38595] Reset all notification settings, remove previous migration attempts
pull/9812/head
ulferts 3 years ago committed by GitHub
commit 98cc7d9f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 95
      db/migrate/20210618132206_add_notification_settings.rb
  2. 24
      db/migrate/20210701073944_add_digest_setting.rb
  3. 19
      db/migrate/20210914065555_cleanup_notifications.rb
  4. 20
      db/migrate/20211104151329_default_notification_setting.rb
  5. 5
      spec_legacy/fixtures/users.yml

@ -22,106 +22,17 @@ class AddNotificationSettings < ActiveRecord::Migration[6.1]
name: 'index_notification_settings_unique_project'
end
insert_project_specific_channel
insert_default_mail_channel
insert_default_in_app_channel
remove_column :members, :mail_notification
remove_column :users, :mail_notification
end
def down
add_column :members, :mail_notification, :boolean, default: false, null: false
add_column :users, :mail_notification, :string, default: '', null: false
update_mail_notifications
drop_table :notification_settings
end
def insert_default_mail_channel
execute <<~SQL
INSERT INTO
notification_settings
(user_id,
channel,
watched,
involved,
mentioned,
"all")
SELECT
id,
1,
mail_notification = 'only_my_events',
mail_notification = 'only_my_events' OR mail_notification = 'only_assigned',
NOT mail_notification = 'all' AND NOT mail_notification = 'NONE',
mail_notification = 'all'
FROM
users
WHERE
mail_notification IS NOT NULL
SQL
end
def insert_project_specific_channel
execute <<~SQL
INSERT INTO
notification_settings
(project_id,
user_id,
channel,
"all")
SELECT
project_id,
user_id,
1,
true
FROM
members
WHERE
mail_notification
SQL
end
def insert_default_in_app_channel
execute <<~SQL
INSERT INTO
notification_settings
(user_id,
channel,
involved,
mentioned,
watched)
SELECT
id,
0,
true,
true,
true
FROM
users
WHERE
type = 'User'
SQL
end
def update_mail_notifications
# We cannot reconstruct the settings completely
execute <<~SQL
UPDATE
users
SET
mail_notification = CASE
WHEN notification_settings.all
THEN 'all'
WHEN notification_settings.watched
THEN 'only_my_events'
WHEN notification_settings.involved
THEN 'only_assigned'
ELSE 'none'
FROM
notification_settings
WHERE
notification_settings.user_id = users.id
SQL
User.reset_column_information
User.update_all(mail_notification: 'only_assigned')
end
end

@ -1,34 +1,12 @@
class AddDigestSetting < ActiveRecord::Migration[6.1]
def up
insert_default_digest_channel
# No-op
end
def down
remove_digest_channels
end
def insert_default_digest_channel
execute <<~SQL
INSERT INTO
notification_settings
(user_id,
channel,
involved,
mentioned,
watched)
SELECT
id,
2,
true,
true,
true
FROM
users
WHERE
type = 'User'
SQL
end
# Removes all digest channels. Includes non default channels as those might
# also have been added not by the migration but in the cause of the functionality
# the migration was added for.

@ -55,25 +55,6 @@ class CleanupNotifications < ActiveRecord::Migration[6.1]
where: "project_id IS NOT NULL",
name: 'index_notification_settings_unique_project'
end
# Set all channels to ian
execute <<~SQL.squish
UPDATE notification_settings SET channel = 0;
SQL
# Restore notification settings
execute <<~SQL.squish
INSERT INTO notification_settings
(project_id, user_id, channel, watched, involved, mentioned,
work_package_commented, work_package_created, work_package_processed, work_package_prioritized, work_package_scheduled)
SELECT project_id, user_id, channel + 1, watched, involved, mentioned,
work_package_commented, work_package_created, work_package_processed, work_package_prioritized, work_package_scheduled
FROM notification_settings
UNION
SELECT project_id, user_id, channel + 2, watched, involved, mentioned,
work_package_commented, work_package_created, work_package_processed, work_package_prioritized, work_package_scheduled
FROM notification_settings;
SQL
end
# rubocop:enable Metrics/AbcSize
end

@ -0,0 +1,20 @@
class DefaultNotificationSetting < ActiveRecord::Migration[6.1]
def up
NotificationSetting.delete_all
execute <<~SQL.squish
INSERT INTO
notification_settings
(user_id, watched, involved, mentioned)
SELECT
id, true, true, true
FROM
users
WHERE type = 'User'
SQL
end
def down
# No data to revert
end
end

@ -84,7 +84,6 @@ users_003:
firstname: Dave
id: 3
auth_source_id:
mail_notification: all
login: dlopper
type: User
first_login: false
@ -101,7 +100,6 @@ users_005:
lastname: Lopper2
firstname: Dave2
auth_source_id:
mail_notification: all
login: dlopper2
type: User
first_login: false
@ -132,7 +130,6 @@ users_007:
lastname: One
firstname: Some
auth_source_id:
mail_notification: only_my_events
login: someone
type: User
first_login: false
@ -148,7 +145,6 @@ users_008:
lastname: Misc
firstname: User
auth_source_id:
mail_notification: only_my_events
login: miscuser8
type: User
first_login: false
@ -164,7 +160,6 @@ users_009:
lastname: Misc
firstname: User
auth_source_id:
mail_notification: only_my_events
login: miscuser9
type: User
first_login: false

Loading…
Cancel
Save