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

bug/61756 Cannot delete users who have work package reminders (#18067)

Kabiru Mwenjaf2c12315e6e4
diff --git a/app/models/reminder_notification.rb b/app/models/reminder_notification.rb
index c005f39a6ee..aae31fac943 100644
--- a/app/models/reminder_notification.rb
+++ b/app/models/reminder_notification.rb
@@ -28,5 +28,5 @@
class ReminderNotification < ApplicationRecord
belongs_to :reminder
- belongs_to :notification, dependent: :destroy
+ belongs_to :notification
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 88bbc9b697b..3be73675a2c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -92,6 +92,7 @@ class User < Principal
dependent: :destroy
has_many :emoji_reactions, dependent: :destroy
+ has_many :reminders, foreign_key: "creator_id", dependent: :destroy, inverse_of: :creator
has_many :remote_identities, dependent: :destroy
# Users blocked via brute force prevention
diff --git a/app/workers/principals/delete_job.rb b/app/workers/principals/delete_job.rb
index 60a2c5fa2d7..218b5767c2b 100644
--- a/app/workers/principals/delete_job.rb
+++ b/app/workers/principals/delete_job.rb
@@ -70,6 +70,10 @@ class Principals::DeleteJob < ApplicationJob
end
def delete_notifications(principal)
+ ::ReminderNotification.joins(:notification)
+ .where(notifications: { recipient: principal })
+ .delete_all
+
::Notification.where(recipient: principal).delete_all
end
diff --git a/spec/models/reminder_notification_spec.rb b/spec/models/reminder_notification_spec.rb
index d079c49aae0..708107c36c7 100644
--- a/spec/models/reminder_notification_spec.rb
+++ b/spec/models/reminder_notification_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -31,6 +33,6 @@ require "spec_helper"
RSpec.describe ReminderNotification do
describe "Associations" do
it { is_expected.to belong_to(:reminder) }
- it { is_expected.to belong_to(:notification).dependent(:destroy) }
+ it { is_expected.to belong_to(:notification) }
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 884b7dfd8d5..dc403a5400f 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -49,6 +49,7 @@ RSpec.describe User do
describe "Associations" do
it { is_expected.to have_many(:emoji_reactions).dependent(:destroy) }
+ it { is_expected.to have_many(:reminders).with_foreign_key(:creator_id).dependent(:destroy).inverse_of(:creator) }
end
describe "with long but allowed attributes" do