diff --git a/app/services/principals/replace_references_service.rb b/app/services/principals/replace_references_service.rb index e1c0810a49c1..14d46adac922 100644 --- a/app/services/principals/replace_references_service.rb +++ b/app/services/principals/replace_references_service.rb @@ -43,6 +43,7 @@ def call(from:, to:) def 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 @@ def rewrite_author(from, to) end end + 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 @@ def journal_classes end def 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] end def 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.rb new file mode 100644 index 000000000000..6eae46e8fc7e --- /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 +end diff --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.rb index 2f8e8238d2e5..4e4889495100 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 @@ def self.included(base) # :nodoc: module InstanceMethods private - 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|