Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove NotificationSetting#channel and all

Oliver Güntherecfa4a765f3f
diff --git a/app/contracts/notifications/create_contract.rb b/app/contracts/notifications/create_contract.rb
index 61913ddf6d0..154cb51b741 100644
--- a/app/contracts/notifications/create_contract.rb
+++ b/app/contracts/notifications/create_contract.rb
@@ -28,8 +28,6 @@
module Notifications
class CreateContract < ::ModelContract
- CHANNELS = %i[ian mail mail_digest].freeze
-
attribute :recipient
attribute :subject
attribute :reason
@@ -43,34 +41,13 @@ module Notifications
validate :validate_recipient_present
validate :validate_reason_present
- validate :validate_channels
def validate_recipient_present
errors.add(:recipient, :blank) if model.recipient.blank?
end
def validate_reason_present
- CHANNELS.each do |channel|
- errors.add(:"reason_#{channel}", :no_notification_reason) if read_channel_without_reason?(channel)
- end
- end
-
- def validate_channels
- if CHANNELS.map { |channel| read_channel(channel) }.compact.empty?
- errors.add(:base, :at_least_one_channel)
- end
-
- CHANNELS.each do |channel|
- errors.add(:"read_#{channel}", :read_on_creation) if read_channel(channel)
- end
- end
-
- def read_channel_without_reason?(channel)
- read_channel(channel) == false && model.send(:"reason_#{channel}").nil?
- end
-
- def read_channel(channel)
- model.send(:"read_#{channel}")
+ errors.add(:reason, :no_notification_reason) if model.reason.nil?
end
end
end
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb
index 37e36dfe36b..644fb9f174d 100644
--- a/app/models/notification_setting.rb
+++ b/app/models/notification_setting.rb
@@ -15,7 +15,6 @@ class NotificationSetting < ApplicationRecord
WIKI_PAGE_UPDATED = :wiki_page_updated
MEMBERSHIP_ADDED = :membership_added
MEMBERSHIP_UPDATED = :membership_updated
- ALL = :all
def self.all_settings
[
@@ -45,13 +44,9 @@ class NotificationSetting < ApplicationRecord
]
end
- enum channel: { in_app: 0, mail: 1, mail_digest: 2 }
-
belongs_to :project
belongs_to :user
include Scopes::Scoped
scopes :applicable
-
- validates :channel, uniqueness: { scope: %i[project user] }
end
diff --git a/app/models/notification_settings/scopes/applicable.rb b/app/models/notification_settings/scopes/applicable.rb
index 7e34719c709..84adcd306a8 100644
--- a/app/models/notification_settings/scopes/applicable.rb
+++ b/app/models/notification_settings/scopes/applicable.rb
@@ -45,8 +45,7 @@ module NotificationSettings::Scopes
.where(global_notifications[:project_id].eq(nil))
.join(project_notifications, Arel::Nodes::OuterJoin)
.on(project_notifications[:project_id].eq(project.id),
- global_notifications[:user_id].eq(project_notifications[:user_id]),
- global_notifications[:channel].eq(project_notifications[:channel]))
+ global_notifications[:user_id].eq(project_notifications[:user_id]))
.project(global_notifications.coalesce(project_notifications[:id], global_notifications[:id]))
where(global_notifications[:id].in(subselect))
diff --git a/app/seeders/admin_user_seeder.rb b/app/seeders/admin_user_seeder.rb
index add1d9aa577..4c055ed0274 100644
--- a/app/seeders/admin_user_seeder.rb
+++ b/app/seeders/admin_user_seeder.rb
@@ -57,9 +57,7 @@ class AdminUserSeeder < Seeder
user.language = I18n.locale.to_s
user.status = User.statuses[:active]
user.force_password_change = force_password_change?
- user.notification_settings.build(channel: :mail, involved: true, mentioned: true, watched: true)
- user.notification_settings.build(channel: :in_app, involved: true, mentioned: true, watched: true)
- user.notification_settings.build(channel: :mail_digest, involved: true, mentioned: true, watched: true)
+ user.notification_settings.build(involved: true, mentioned: true, watched: true)
end
end
diff --git a/app/services/user_preferences/update_service.rb b/app/services/user_preferences/update_service.rb
index 6f1f8102021..9f4b8d4cce7 100644
--- a/app/services/user_preferences/update_service.rb
+++ b/app/services/user_preferences/update_service.rb
@@ -59,11 +59,11 @@ module UserPreferences
def persist_notifications
global, project = notifications
- .map { |item| item.merge(user_id: model.user_id) }
- .partition { |setting| setting[:project_id].nil? }
+ .map { |item| item.merge(user_id: model.user_id) }
+ .partition { |setting| setting[:project_id].nil? }
- global_ids = upsert_notifications(global, %i[user_id channel], 'project_id IS NULL')
- project_ids = upsert_notifications(project, %i[user_id channel project_id], 'project_id IS NOT NULL')
+ global_ids = upsert_notifications(global, %i[user_id], 'project_id IS NULL')
+ project_ids = upsert_notifications(project, %i[user_id project_id], 'project_id IS NOT NULL')
global_ids + project_ids
end
@@ -106,8 +106,7 @@ module UserPreferences
wiki_page_added
wiki_page_updated
membership_added
- membership_updated
- all]
+ membership_updated]
},
validate: false
).ids
diff --git a/app/services/users/set_attributes_service.rb b/app/services/users/set_attributes_service.rb
index 21e3fca32a7..6636adb2667 100644
--- a/app/services/users/set_attributes_service.rb
+++ b/app/services/users/set_attributes_service.rb
@@ -54,9 +54,7 @@ module Users
end
def initialize_notification_settings
- NotificationSetting.channels.each_key do |channel|
- model.notification_settings.build(channel: channel, involved: true, mentioned: true, watched: true)
- end
+ model.notification_settings.build(involved: true, mentioned: true, watched: true)
end
end
end
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 879149a322c..136adc9b5a5 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -563,7 +563,6 @@ en:
notifications:
title: "Notifications"
- channel: "Channel"
no_unread: "No unread notifications"
reasons:
mentioned: 'mentioned'
diff --git a/db/migrate/20210914065555_cleanup_notifications.rb b/db/migrate/20210914065555_cleanup_notifications.rb
index 114ea6dc68b..7ae9a480cf0 100644
--- a/db/migrate/20210914065555_cleanup_notifications.rb
+++ b/db/migrate/20210914065555_cleanup_notifications.rb
@@ -4,14 +4,71 @@ class CleanupNotifications < ActiveRecord::Migration[6.1]
t.remove :read_mail, :reason_mail, :reason_mail_digest
t.rename :reason_ian, :reason
end
+
+ change_table :notification_settings, bulk: true do |t|
+ t.remove_index name: 'index_notification_settings_unique_project_null'
+ t.remove_index name: 'index_notification_settings_unique_project'
+
+ # Delete all non in-app
+ NotificationSetting.where('channel > 0').delete_all
+
+ t.remove :channel, :all
+
+ t.index %i[user_id],
+ unique: true,
+ where: "project_id IS NULL",
+ name: 'index_notification_settings_unique_project_null'
+
+ t.index %i[user_id project_id],
+ unique: true,
+ where: "project_id IS NOT NULL",
+ name: 'index_notification_settings_unique_project'
+ end
end
def down
change_table :notifications, bulk: true do |t|
- t.boolean :read_email, default: false, index: true
+ t.boolean :read_mail, default: false, index: true
t.integer :reason_mail, limit: 1
t.integer :reason_mail_digest, limit: 1
t.rename :reason, :reason_ian
end
+
+ change_table :notification_settings, bulk: true do |t|
+ t.integer :channel, limit: 1
+ t.boolean :all, default: false
+
+ t.remove_index name: 'index_notification_settings_unique_project_null'
+ t.remove_index name: 'index_notification_settings_unique_project'
+
+ t.index %i[user_id channel],
+ unique: true,
+ where: "project_id IS NULL",
+ name: 'index_notification_settings_unique_project_null'
+
+ t.index %i[user_id project_id channel],
+ unique: true,
+ 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
end
diff --git a/docs/api/apiv3/components/schemas/user_preferences_model.yml b/docs/api/apiv3/components/schemas/user_preferences_model.yml
index 52781433048..38361337526 100644
--- a/docs/api/apiv3/components/schemas/user_preferences_model.yml
+++ b/docs/api/apiv3/components/schemas/user_preferences_model.yml
@@ -17,30 +17,11 @@ example:
timeZone: "Europe/Berlin"
warnOnLeavingUnsaved: true
notifications:
- - channel: "mail"
- watched: false
- involved: true
- mentioned: false
- all: false
- workPackageCommented: false
- _links:
- project:
- href: null
- - channel: "in_app"
- watched: true
- involved: true
- mentioned: true
- all: false
- workPackageCommented: false
- _links:
- project:
- href: null
- - channel: "mail_digest"
- watched: true
- involved: true
- mentioned: true
- all: true,
- workPackageCommented: true
- _links:
- project:
- href: null
+ watched: false
+ involved: true
+ mentioned: false
+ all: false
+ workPackageCommented: false
+ _links:
+ project:
+ href: null
diff --git a/docs/api/apiv3/paths/my_preferences.yml b/docs/api/apiv3/paths/my_preferences.yml
index 98ac0dccd7f..6eb39b23c0c 100644
--- a/docs/api/apiv3/paths/my_preferences.yml
+++ b/docs/api/apiv3/paths/my_preferences.yml
@@ -23,33 +23,14 @@ get:
timeZone: "Europe/Berlin"
warnOnLeavingUnsaved: true
notifications:
- - channel: "mail"
- watched: false
- involved: true
- mentioned: false
- all: false
- workPackageCommented: false
- _links:
- project:
- href: null
- - channel: "in_app"
- watched: true
- involved: true
- mentioned: true
- all: false
- workPackageCommented: false
- _links:
- project:
- href: null
- - channel: "mail_digest"
- watched: true
- involved: true
- mentioned: true
- all: true,
- workPackageCommented: true
- _links:
- project:
- href: null
+ watched: true
+ involved: true
+ mentioned: true
+ all: false
+ workPackageCommented: false
+ _links:
+ project:
+ href: null
schema:
"$ref": "../components/schemas/user_preferences_model.yml"
description: OK
@@ -93,16 +74,6 @@ patch:
timeZone: Europe/Berlin
warnOnLeavingUnsaved: true
notifications:
- - channel: "mail"
- watched: false
- involved: true
- mentioned: false
- all: false
- workPackageCommented: false
- _links:
- project:
- href: null
- - channel: "in_app"
watched: true
involved: true
mentioned: true
@@ -111,15 +82,6 @@ patch:
_links:
project:
href: null
- - channel: "mail_digest"
- watched: true
- involved: true
- mentioned: true
- all: true,
- workPackageCommented: true
- _links:
- project:
- href: null
schema:
"$ref": "../components/schemas/user_preferences_model.yml"
description: OK
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
index 6ce86a8c2c7..d1bbe8c1b2f 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
@@ -159,7 +159,6 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
const globalPrefs:NotificationSetting = {
...globalNotification,
_links: { project: { href: null } },
- channel: 'in_app',
watched: true,
mentioned: true,
involved: notificationSettings.involved,
@@ -168,12 +167,10 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
workPackageScheduled: notificationSettings.workPackageScheduled,
workPackagePrioritized: notificationSettings.workPackagePrioritized,
workPackageCommented: notificationSettings.workPackageCommented,
- all: false,
};
const projectPrefs:NotificationSetting[] = notificationSettings.projectSettings.map((settings) => ({
_links: { project: { href: settings.project.href } },
- channel: 'in_app',
watched: true,
mentioned: true,
involved: settings.involved,
@@ -182,7 +179,6 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
workPackageScheduled: settings.workPackageScheduled,
workPackagePrioritized: settings.workPackagePrioritized,
workPackageCommented: settings.workPackageCommented,
- all: false,
newsAdded: false,
newsCommented: false,
documentAdded: false,
@@ -198,12 +194,7 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
notifications: [
globalPrefs,
...projectPrefs,
- ].reduce((total, next) => [
- ...total,
- next,
- { ...next, channel: 'mail' },
- { ...next, channel: 'mail_digest' },
- ], []),
+ ],
});
}
}
diff --git a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts b/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
index 96020dd6cb2..c00707818bd 100644
--- a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
+++ b/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
@@ -1,10 +1,7 @@
import { HalSourceLink } from 'core-app/features/hal/resources/hal-resource';
-export type NotificationSettingChannel = 'mail'|'mail_digest'|'in_app';
-
export interface NotificationSetting {
_links:{ project:HalSourceLink };
- channel:NotificationSettingChannel;
watched:boolean;
involved:boolean;
mentioned:boolean;
@@ -21,7 +18,6 @@ export interface NotificationSetting {
wikiPageUpdated:boolean;
membershipAdded:boolean;
membershipUpdated:boolean;
- all:boolean;
}
export function buildNotificationSetting(project:null|HalSourceLink, params:Partial<NotificationSetting>):NotificationSetting {
@@ -48,8 +44,6 @@ export function buildNotificationSetting(project:null|HalSourceLink, params:Part
wikiPageUpdated: true,
membershipAdded: true,
membershipUpdated: true,
- all: false,
- channel: 'in_app',
...params,
};
}
diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.query.ts b/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
index 4243ad5c25a..1ece0799d73 100644
--- a/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
+++ b/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
@@ -16,7 +16,7 @@ export class UserPreferencesQuery extends Query<UserPreferencesModel> {
notificationsGroupedByProject$:Observable<{ [key:string]:NotificationSetting[] }> = this
.notificationSettings$
.pipe(
- map((settings) => settings.filter((setting) => setting.channel === 'in_app' && setting._links.project.href)),
+ map((settings) => settings.filter((setting) => setting._links.project.href)),
map((settings) => _.groupBy(settings, (setting) => setting._links.project.title)),
);
@@ -24,13 +24,13 @@ export class UserPreferencesQuery extends Query<UserPreferencesModel> {
notificationsForGlobal$:Observable<NotificationSetting|undefined> = this
.notificationSettings$
.pipe(
- map((notifications) => notifications.find((setting) => setting.channel === 'in_app' && setting._links.project.href === null)),
+ map((notifications) => notifications.find((setting) => setting._links.project.href === null)),
);
projectNotifications$ = this
.notificationSettings$
.pipe(
- map((settings) => settings.filter((setting) => setting.channel === 'in_app' && setting._links.project.href !== null)),
+ map((settings) => settings.filter((setting) => setting._links.project.href !== null)),
);
globalNotification$ = this
diff --git a/spec/contracts/notifications/create_contract_spec.rb b/spec/contracts/notifications/create_contract_spec.rb
index 47490a3af1e..3cb5db3292b 100644
--- a/spec/contracts/notifications/create_contract_spec.rb
+++ b/spec/contracts/notifications/create_contract_spec.rb
@@ -92,13 +92,6 @@ describe Notifications::CreateContract do
it_behaves_like 'contract is valid'
end
- context 'with all channels nil' do
- let(:notification_read_ian) { nil }
- let(:notification_read_mail_digest) { nil }
-
- it_behaves_like 'contract is invalid', base: :at_least_one_channel
- end
-
context 'with read_ian true' do
let(:notification_read_ian) { true }
diff --git a/spec/features/users/notifications/shared_examples.rb b/spec/features/users/notifications/shared_examples.rb
index b9be6349ce4..c1f7d2db3cd 100644
--- a/spec/features/users/notifications/shared_examples.rb
+++ b/spec/features/users/notifications/shared_examples.rb
@@ -38,7 +38,7 @@ shared_examples 'notification settings workflow' do
expect(notification_settings.count).to eq 9
expect(notification_settings.where(project: project).count).to eq 3
- in_app = notification_settings.find_by(project: project, channel: :in_app)
+ in_app = notification_settings.find_by(project: project)
expect(in_app.involved).to be_truthy
expect(in_app.mentioned).to be_truthy
expect(in_app.watched).to be_truthy
@@ -48,26 +48,6 @@ shared_examples 'notification settings workflow' do
expect(in_app.work_package_prioritized).to be_falsey
expect(in_app.work_package_scheduled).to be_falsey
- mail = notification_settings.find_by(project: project, channel: :mail)
- expect(mail.involved).to be_truthy
- expect(mail.mentioned).to be_truthy
- expect(mail.watched).to be_truthy
- expect(mail.work_package_commented).to be_falsey
- expect(mail.work_package_created).to be_falsey
- expect(mail.work_package_processed).to be_falsey
- expect(mail.work_package_prioritized).to be_falsey
- expect(mail.work_package_scheduled).to be_falsey
-
- mail_digest = notification_settings.find_by(project: project, channel: :mail_digest)
- expect(mail_digest.involved).to be_truthy
- expect(mail_digest.mentioned).to be_truthy
- expect(mail_digest.watched).to be_truthy
- expect(mail_digest.work_package_commented).to be_falsey
- expect(mail_digest.work_package_created).to be_falsey
- expect(mail_digest.work_package_processed).to be_falsey
- expect(mail_digest.work_package_prioritized).to be_falsey
- expect(mail_digest.work_package_scheduled).to be_falsey
-
# Trying to add the same project again will not be possible (Regression #38072)
click_button 'Add setting for project'
container = page.find('[data-qa-selector="notification-setting-inline-create"] ng-select')