[#40833] On deletion of user set all file-links, storages and projects_storages to DeletedUser

https://community.openproject.org/work_packages/40833
pull/10391/head
Wieland Lindenthal 3 years ago
parent 9441fa907c
commit 8cfec8458c
No known key found for this signature in database
GPG Key ID: 7ACCABE64832A0C6
  1. 28
      modules/storages/config/routes.rb
  2. 2
      modules/storages/lib/open_project/storages/engine.rb
  3. 22
      modules/storages/lib/open_project/storages/patches/replace_references_service_patch.rb
  4. 77
      modules/storages/spec/services/principals/replace_references_service_call_integration_spec.rb

@ -1,3 +1,31 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2022 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.
#++
OpenProject::Application.routes.draw do
scope 'admin/settings' do
resources :storages, controller: 'storages/admin/storages'

@ -79,6 +79,8 @@ module OpenProject::Storages
parent: :settings
end
patch_with_namespace :Principals, :ReplaceReferencesService
# This hook is executed when the module is loaded.
config.to_prepare do
# We have a bunch of filters defined within the module. Here we register the filters.

@ -0,0 +1,22 @@
module OpenProject::Storages::Patches::ReplaceReferencesServicePatch
def self.included(base) # :nodoc:
base.prepend InstanceMethods
end
module InstanceMethods
private
def rewrite_active_models(from, to)
super
rewrite_creator(from, to)
end
def rewrite_creator(from, to)
[::Storages::Storage,
::Storages::ProjectStorage,
::Storages::FileLink].each do |klass|
klass.where(creator_id: from.id).update_all(creator_id: to.id)
end
end
end
end

@ -0,0 +1,77 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2022 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'
describe Principals::ReplaceReferencesService, '#call', type: :model do
shared_let(:principal) { create(:user) }
shared_let(:to_principal) { create :user }
subject(:service_call) { instance.call(from: principal, to: to_principal) }
let(:instance) do
described_class.new
end
shared_examples 'replaces the creator' do
before do
model
end
it 'is successful' do
expect(service_call)
.to be_success
end
it 'replaces principal with to_principal' do
service_call
model.reload
expect(model.creator).to eql to_principal
end
end
context 'with Storage' do
it_behaves_like 'replaces the creator' do
let(:model) { create(:storage, creator: principal) }
end
end
context 'with ProjectStorage' do
it_behaves_like 'replaces the creator' do
let(:model) { create(:project_storage, creator: principal) }
end
end
context 'with FileLink' do
it_behaves_like 'replaces the creator' do
let(:work_package) { create(:work_package) }
let(:model) { create(:file_link, creator: principal, container: work_package) }
end
end
end
Loading…
Cancel
Save