[#40833] On deletion of user set all file-links, storages and projects_storages to DeletedUser
https://community.openproject.org/work_packages/40833pull/10391/head
parent
9441fa907c
commit
8cfec8458c
@ -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…
Reference in new issue