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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Replace references
Oliver Günther6dc3ede58459
diff --git a/app/services/principals/replace_references_service.rb b/app/services/principals/replace_references_service.rbindex e1c0810a49c..14d46adac92 100644--- a/app/services/principals/replace_references_service.rb+++ b/app/services/principals/replace_references_service.rb@@ -43,6 +43,7 @@ module Principalsdef rewrite_active_models(from, to)rewrite_author(from, to)+ rewrite_creator(from, to)rewrite_user(from, to)rewrite_assigned_to(from, to)rewrite_responsible(from, to)@@ -92,6 +93,12 @@ module Principalsendend+ def rewrite_creator(from, to)+ [AuthProvider].each do |klass|+ rewrite(klass, :creator_id, from, to)+ end+ end+def rewrite_user(from, to)[TimeEntry,CostEntry,@@ -149,7 +156,7 @@ module Principalsenddef foreign_keys- %w[author_id user_id assigned_to_id responsible_id logged_by_id presenter_id]+ %w[author_id creator_id user_id assigned_to_id responsible_id logged_by_id presenter_id]enddef rewrite(klass, attribute, from, to)diff --git a/modules/auth_saml/spec/services/principals/replace_references_service_call_integration_spec.rb b/modules/auth_saml/spec/services/principals/replace_references_service_call_integration_spec.rbnew file mode 100644index 00000000000..6eae46e8fc7--- /dev/null+++ b/modules/auth_saml/spec/services/principals/replace_references_service_call_integration_spec.rb@@ -0,0 +1,59 @@+# frozen_string_literal: true++#-- 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"+require_module_spec_helper+require Rails.root.join("spec/services/principals/replace_references_context")++RSpec.describe Principals::ReplaceReferencesService, "#call", type: :model do+ subject(:service_call) { instance.call(from: principal, to: to_principal) }++ shared_let(:other_user) { create(:user, firstname: "other user") }+ shared_let(:principal) { create(:user, firstname: "old principal") }+ shared_let(:to_principal) { create(:user, firstname: "new principal") }++ let(:instance) do+ described_class.new+ end++ context "with Saml::Provider" do+ it_behaves_like "rewritten record",+ :saml_provider,+ :creator_id do+ let(:attributes) do+ {+ type: "'Saml::Provider'",+ slug: "'saml-foo'",+ display_name: "'foo'"+ }+ end+ end+ end+enddiff --git a/modules/storages/lib/open_project/storages/patches/replace_references_service_patch.rb b/modules/storages/lib/open_project/storages/patches/replace_references_service_patch.rbindex 2f8e8238d2e..4e488949510 100644--- a/modules/storages/lib/open_project/storages/patches/replace_references_service_patch.rb+++ b/modules/storages/lib/open_project/storages/patches/replace_references_service_patch.rb@@ -6,12 +6,9 @@ module OpenProject::Storages::Patches::ReplaceReferencesServicePatchmodule InstanceMethodsprivate- def rewrite_active_models(from, to)+ def rewrite_creator(from, to)super- rewrite_creator(from, to)- end- def rewrite_creator(from, to)[::Storages::Storage,::Storages::ProjectStorage,::Storages::FileLink].each do |klass|