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

[#43673] Include date alert into NotificationSetting Representer & Database

Dmitriid386ad04105f
diff --git a/app/models/notification.rb b/app/models/notification.rb
index c228a953403..4feda5a0d3b 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -9,7 +9,8 @@ class Notification < ApplicationRecord
processed: 6,
prioritized: 7,
scheduled: 8,
- responsible: 9
+ responsible: 9,
+ date_alert: 10
}.freeze
enum reason: REASONS,
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb
index c22de824486..f2943cf7c62 100644
--- a/app/models/notification_setting.rb
+++ b/app/models/notification_setting.rb
@@ -3,6 +3,9 @@ class NotificationSetting < ApplicationRecord
ASSIGNEE = :assignee
RESPONSIBLE = :responsible
MENTIONED = :mentioned
+ START_DATE = :start_date
+ DUE_DATE = :due_date
+ OVERDUE = :overdue
WORK_PACKAGE_CREATED = :work_package_created
WORK_PACKAGE_COMMENTED = :work_package_commented
WORK_PACKAGE_PROCESSED = :work_package_processed
@@ -23,6 +26,9 @@ class NotificationSetting < ApplicationRecord
ASSIGNEE,
RESPONSIBLE,
MENTIONED,
+ START_DATE,
+ DUE_DATE,
+ OVERDUE,
WORK_PACKAGE_CREATED,
WORK_PACKAGE_COMMENTED,
WORK_PACKAGE_PROCESSED,
@@ -50,4 +56,9 @@ class NotificationSetting < ApplicationRecord
include Scopes::Scoped
scopes :applicable
+
+ validates :start_date, :due_date, :overdue, numericality: { only_integer: true,
+ allow_nil: true,
+ greater_than_or_equal_to: 0,
+ less_than_or_equal_to: 168 }
end
diff --git a/app/services/user_preferences/update_service.rb b/app/services/user_preferences/update_service.rb
index 65f4e3040c6..2402b263a0c 100644
--- a/app/services/user_preferences/update_service.rb
+++ b/app/services/user_preferences/update_service.rb
@@ -50,7 +50,10 @@ module UserPreferences
return service_call if notifications.nil?
inserted = persist_notifications
- remove_other_notifications(inserted)
+
+ if inserted.present?
+ remove_other_notifications(inserted)
+ end
service_call
end
@@ -93,6 +96,9 @@ module UserPreferences
assignee
responsible
mentioned
+ start_date
+ due_date
+ overdue
work_package_commented
work_package_created
work_package_processed
@@ -107,7 +113,7 @@ module UserPreferences
membership_added
membership_updated]
},
- validate: false
+ validate: true
).ids
end
end
diff --git a/db/migrate/20220918165443_add_start_date_due_date_and_overdue_to_notification_settings.rb b/db/migrate/20220918165443_add_start_date_due_date_and_overdue_to_notification_settings.rb
new file mode 100644
index 00000000000..ddaa4cc94ca
--- /dev/null
+++ b/db/migrate/20220918165443_add_start_date_due_date_and_overdue_to_notification_settings.rb
@@ -0,0 +1,9 @@
+class AddStartDateDueDateAndOverdueToNotificationSettings < ActiveRecord::Migration[7.0]
+ def change
+ change_table :notification_settings, bulk: true do |t|
+ t.column :start_date, :integer, default: 24
+ t.column :due_date, :integer, default: 24
+ t.column :overdue, :integer, default: nil
+ end
+ end
+end