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

Keep track of reminder notifications

Kabiru Mwenja09622465b98b
diff --git a/app/models/reminder.rb b/app/models/reminder.rb
index 5e894f91152..b2fca7cc9ae 100644
--- a/app/models/reminder.rb
+++ b/app/models/reminder.rb
@@ -30,6 +30,8 @@ class Reminder < ApplicationRecord
belongs_to :remindable, polymorphic: true
belongs_to :creator, class_name: "User"
+ has_many :reminder_notifications, dependent: :destroy
+
def scheduled?
job_id.present?
end
diff --git a/app/models/reminder_notification.rb b/app/models/reminder_notification.rb
new file mode 100644
index 00000000000..cbdd70905a9
--- /dev/null
+++ b/app/models/reminder_notification.rb
@@ -0,0 +1,4 @@
+class ReminderNotification < ApplicationRecord
+ belongs_to :reminder
+ belongs_to :notification
+end
diff --git a/app/workers/reminders/schedule_reminder_job.rb b/app/workers/reminders/schedule_reminder_job.rb
index 195b185bfad..e87d47ffb9b 100644
--- a/app/workers/reminders/schedule_reminder_job.rb
+++ b/app/workers/reminders/schedule_reminder_job.rb
@@ -38,6 +38,7 @@ module Reminders
return if reminder.scheduled?
create_notification_from_reminder(reminder)
+ .on_success { |service_result| ReminderNotification.create!(reminder:, notification: service_result.result) }
end
private
diff --git a/db/migrate/20241121113638_create_reminder_notifications.rb b/db/migrate/20241121113638_create_reminder_notifications.rb
new file mode 100644
index 00000000000..576e07c8f1e
--- /dev/null
+++ b/db/migrate/20241121113638_create_reminder_notifications.rb
@@ -0,0 +1,10 @@
+class CreateReminderNotifications < ActiveRecord::Migration[7.1]
+ def change
+ create_table :reminder_notifications do |t|
+ t.references :reminder, foreign_key: true
+ t.references :notification, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/spec/models/reminder_notification_spec.rb b/spec/models/reminder_notification_spec.rb
new file mode 100644
index 00000000000..95c8193813c
--- /dev/null
+++ b/spec/models/reminder_notification_spec.rb
@@ -0,0 +1,36 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+
+RSpec.describe ReminderNotification do
+ describe "Associations" do
+ it { is_expected.to belong_to(:reminder) }
+ it { is_expected.to belong_to(:notification) }
+ end
+end
diff --git a/spec/models/reminder_spec.rb b/spec/models/reminder_spec.rb
index e87cff1a990..bb1398e1125 100644
--- a/spec/models/reminder_spec.rb
+++ b/spec/models/reminder_spec.rb
@@ -32,6 +32,7 @@ RSpec.describe Reminder do
describe "Associations" do
it { is_expected.to belong_to(:remindable) }
it { is_expected.to belong_to(:creator).class_name("User") }
+ it { is_expected.to have_many(:reminder_notifications).dependent(:destroy) }
end
describe "#scheduled?" do
diff --git a/spec/workers/reminders/schedule_reminder_job_spec.rb b/spec/workers/reminders/schedule_reminder_job_spec.rb
index 835aa7cf39a..a24ced8c510 100644
--- a/spec/workers/reminders/schedule_reminder_job_spec.rb
+++ b/spec/workers/reminders/schedule_reminder_job_spec.rb
@@ -49,7 +49,7 @@ RSpec.describe Reminders::ScheduleReminderJob do
it "creates a notification from the reminder" do
notification_svc = nil
- expect { notification_svc = subject }.to change(Notification, :count).by(1)
+ expect { notification_svc = subject }.to change(Notification, :count).by(1) & change(ReminderNotification, :count).by(1)
aggregate_failures "notification attributes" do
notification = notification_svc.result