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
Extend `WorkPackageMembers::DeleteService` with cleanup feature
Aaron Contrerasec05e41b0988
diff --git a/app/services/work_package_members/delete_service.rb b/app/services/work_package_members/delete_service.rbindex 0f52468c696..118658007a5 100644--- a/app/services/work_package_members/delete_service.rb+++ b/app/services/work_package_members/delete_service.rb@@ -27,4 +27,23 @@# ++class WorkPackageMembers::DeleteService < BaseServices::Delete+ include Members::Concerns::CleanedUp++ protected++ def after_perform(service_call)+ super(service_call).tap do |call|+ work_package_member = call.result++ cleanup_for_group(work_package_member)+ end+ end++ def cleanup_for_group(work_package_member)+ return unless work_package_member.principal.is_a?(Group)++ Groups::CleanupInheritedRolesService+ .new(work_package_member.principal, current_user: user, contract_class: EmptyContract)+ .call+ endenddiff --git a/spec/features/work_packages/share_spec.rb b/spec/features/work_packages/share_spec.rbindex 1f66d0be49d..a767762c548 100644--- a/spec/features/work_packages/share_spec.rb+++ b/spec/features/work_packages/share_spec.rb@@ -167,6 +167,19 @@ RSpec.describe 'Work package sharing',share_modal.expect_shared_with(not_shared_yet_with_group, 'Comment')share_modal.expect_shared_with(dinesh, 'Comment')share_modal.expect_shared_with(gilfoyle, 'Comment')++ # When removing a group's share, its users also get their share removed+ share_modal.remove_user(not_shared_yet_with_group)+ share_modal.expect_not_shared_with(not_shared_yet_with_group)+ share_modal.close+ share_modal.expect_closed++ click_button 'Share'++ share_modal.expect_open+ share_modal.expect_not_shared_with(not_shared_yet_with_group)+ share_modal.expect_not_shared_with(dinesh)+ share_modal.expect_not_shared_with(gilfoyle)endenddiff --git a/spec/services/work_package_members/delete_service_spec.rb b/spec/services/work_package_members/delete_service_spec.rbnew file mode 100644index 00000000000..872937415a8--- /dev/null+++ b/spec/services/work_package_members/delete_service_spec.rb@@ -0,0 +1,81 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2023 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 'services/base_services/behaves_like_delete_service'++RSpec.describe WorkPackageMembers::DeleteService, type: :model do+ it_behaves_like 'BaseServices delete service' do+ let(:model_class) { Member }+ let(:model_instance) { build_stubbed(:work_package_member, principal:) }+ let(:principal) { user }++ let!(:cleanup_service_instance) do+ instance_double(Members::CleanupService, call: nil).tap do |service_double|+ allow(Members::CleanupService)+ .to receive(:new)+ .with(principal, model_instance.project_id)+ .and_return(service_double)+ end+ end++ describe '#call' do+ context 'when contract validates and the model is destroyed successfully' do+ it 'calls the cleanup service' do+ service_call++ expect(cleanup_service_instance)+ .to have_received(:call)+ end++ context "when the model's principal is a group" do+ let(:principal) { build_stubbed(:group) }+ let!(:cleanup_inherited_roles_service_instance) do+ instance_double(Groups::CleanupInheritedRolesService, call: nil).tap do |service_double|+ allow(Groups::CleanupInheritedRolesService)+ .to receive(:new)+ .with(principal,+ current_user: user,+ contract_class: EmptyContract)+ .and_return(service_double)+ end+ end++ it "calls the cleanup inherited roles service" do+ service_call++ expect(cleanup_inherited_roles_service_instance)+ .to have_received(:call)+ end+ end+ end+ end+ end+end