Skip to content

Commit

Permalink
Replace references
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Dec 18, 2024
1 parent cbd70ae commit 6dc3ede
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
9 changes: 8 additions & 1 deletion app/services/principals/replace_references_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 6dc3ede

Please sign in to comment.