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

Allow deletion of users that favored projects

Oliver Güntherd9c84896265f
diff --git a/app/workers/principals/delete_job.rb b/app/workers/principals/delete_job.rb
index 4df2dafba02..60a2c5fa2d7 100644
--- a/app/workers/principals/delete_job.rb
+++ b/app/workers/principals/delete_job.rb
@@ -66,6 +66,7 @@ class Principals::DeleteJob < ApplicationJob
delete_notifications(principal)
delete_private_queries(principal)
delete_tokens(principal)
+ delete_favorites(principal)
end
def delete_notifications(principal)
@@ -77,6 +78,10 @@ class Principals::DeleteJob < ApplicationJob
CostQuery.where(user_id: principal.id, is_public: false).delete_all
end
+ def delete_favorites(principal)
+ Favorite.where(user_id: principal.id).delete_all
+ end
+
def delete_tokens(principal)
::Token::Base.where(user_id: principal.id).destroy_all
end
diff --git a/spec/workers/principals/delete_job_integration_spec.rb b/spec/workers/principals/delete_job_integration_spec.rb
index 17596286a57..2db3e9a989c 100644
--- a/spec/workers/principals/delete_job_integration_spec.rb
+++ b/spec/workers/principals/delete_job_integration_spec.rb
@@ -475,6 +475,17 @@ RSpec.describe Principals::DeleteJob, type: :model do
it_behaves_like "cost_query handling"
it_behaves_like "project query handling"
it_behaves_like "mention rewriting"
+
+ describe "favorites" do
+ before do
+ project.add_favoring_user(principal)
+ job
+ end
+
+ it "removes the assigned_to association to the principal" do
+ expect(project.favoring_users.reload).to be_empty
+ end
+ end
end
context "with a group" do