From 545d2973999b1b7fa9743dad7f7c97a46872499b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 17 Dec 2024 09:09:16 +0100 Subject: [PATCH] Allow deletion of users that favored projects https://community.openproject.org/work_packages/60171 --- app/workers/principals/delete_job.rb | 5 +++++ .../workers/principals/delete_job_integration_spec.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/workers/principals/delete_job.rb b/app/workers/principals/delete_job.rb index 4df2dafba025..60a2c5fa2d75 100644 --- a/app/workers/principals/delete_job.rb +++ b/app/workers/principals/delete_job.rb @@ -66,6 +66,7 @@ def delete_associated(principal) delete_notifications(principal) delete_private_queries(principal) delete_tokens(principal) + delete_favorites(principal) end def delete_notifications(principal) @@ -77,6 +78,10 @@ def delete_private_queries(principal) 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 17596286a579..2db3e9a989c0 100644 --- a/spec/workers/principals/delete_job_integration_spec.rb +++ b/spec/workers/principals/delete_job_integration_spec.rb @@ -475,6 +475,17 @@ 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