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

limiting users eligible for date alerts

ulfertsfb78d2861a97
diff --git a/app/workers/notifications/schedule_date_alerts_notifications_job/service.rb b/app/workers/notifications/schedule_date_alerts_notifications_job/service.rb
index f39c0bbb60d..384c424a4ef 100644
--- a/app/workers/notifications/schedule_date_alerts_notifications_job/service.rb
+++ b/app/workers/notifications/schedule_date_alerts_notifications_job/service.rb
@@ -40,7 +40,7 @@ class Notifications::ScheduleDateAlertsNotificationsJob::Service
def call
return unless EnterpriseToken.allows_to?(:date_alerts)
- User.with_time_zone(time_zones_covering_1am_local_time).find_each do |user|
+ users_at_1am_with_notification_settings.find_each do |user|
Notifications::CreateDateAlertsNotificationsJob.perform_later(user)
end
end
@@ -62,4 +62,13 @@ class Notifications::ScheduleDateAlertsNotificationsJob::Service
local_time = time.in_time_zone(time_zone)
local_time.strftime('%H:%M') == '01:00'
end
+
+ def users_at_1am_with_notification_settings
+ User
+ .with_time_zone(time_zones_covering_1am_local_time)
+ .not_locked
+ .where("EXISTS (SELECT 1 FROM notification_settings " \
+ "WHERE user_id = users.id AND " \
+ "(overdue IS NOT NULL OR start_date IS NOT NULL OR due_date IS NOT NULL))")
+ end
end
diff --git a/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb b/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb
index 6de7d0de824..b256b040fb0 100644
--- a/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb
+++ b/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb
@@ -194,5 +194,108 @@ describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, with_ee:
let(:user) { user_paris }
end
end
+
+ context 'with a user having only due_date active in notification settings' do
+ before do
+ NotificationSetting
+ .where(user: user_paris)
+ .update_all(due_date: 1,
+ start_date: nil,
+ overdue: nil)
+ end
+
+ it_behaves_like 'job execution creates date alerts creation job' do
+ let(:timezone) { timezone_paris }
+ let(:scheduled_at) { '1:00' }
+ let(:local_time) { '1:00' }
+ let(:user) { user_paris }
+ end
+ end
+
+ context 'with a user having only start_date active in notification settings' do
+ before do
+ NotificationSetting
+ .where(user: user_paris)
+ .update_all(due_date: nil,
+ start_date: 1,
+ overdue: nil)
+ end
+
+ it_behaves_like 'job execution creates date alerts creation job' do
+ let(:timezone) { timezone_paris }
+ let(:scheduled_at) { '1:00' }
+ let(:local_time) { '1:00' }
+ let(:user) { user_paris }
+ end
+ end
+
+ context 'with a user having only overdue active in notification settings' do
+ before do
+ NotificationSetting
+ .where(user: user_paris)
+ .update_all(due_date: nil,
+ start_date: nil,
+ overdue: 1)
+ end
+
+ it_behaves_like 'job execution creates date alerts creation job' do
+ let(:timezone) { timezone_paris }
+ let(:scheduled_at) { '1:00' }
+ let(:local_time) { '1:00' }
+ let(:user) { user_paris }
+ end
+ end
+
+ context 'without a user having notification settings' do
+ before do
+ NotificationSetting
+ .where(user: user_paris)
+ .update_all(due_date: nil,
+ start_date: nil,
+ overdue: nil)
+ end
+
+ it_behaves_like 'job execution creates no date alerts creation job' do
+ let(:timezone) { timezone_paris }
+ let(:scheduled_at) { '1:00' }
+ let(:local_time) { '1:00' }
+ end
+ end
+
+ context 'with a user having only a project active notification settings' do
+ before do
+ NotificationSetting
+ .where(user: user_paris)
+ .update_all(due_date: nil,
+ start_date: nil,
+ overdue: nil)
+
+ NotificationSetting
+ .create(user: user_paris,
+ project: create(:project),
+ due_date: 1,
+ start_date: nil,
+ overdue: nil)
+ end
+
+ it_behaves_like 'job execution creates date alerts creation job' do
+ let(:timezone) { timezone_paris }
+ let(:scheduled_at) { '1:00' }
+ let(:local_time) { '1:00' }
+ let(:user) { user_paris }
+ end
+ end
+
+ context 'with a locked user' do
+ before do
+ user_paris.locked!
+ end
+
+ it_behaves_like 'job execution creates no date alerts creation job' do
+ let(:timezone) { timezone_paris }
+ let(:scheduled_at) { '1:00' }
+ let(:local_time) { '1:00' }
+ end
+ end
end
end