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
Add Bcf Topic DeleteService and DeleteEndpoint
Henriette Dinger69debf8c0c6a
diff --git a/app/services/base_services/base_contracted.rb b/app/services/base_services/base_contracted.rbindex b32e451bb4a..13f421a2f1c 100644--- a/app/services/base_services/base_contracted.rb+++ b/app/services/base_services/base_contracted.rb@@ -88,5 +88,9 @@ module BaseServicesdef default_contract_classraise NotImplementedErrorend++ def namespace+ self.class.name.deconstantize.pluralize+ endendenddiff --git a/app/services/base_services/delete.rb b/app/services/base_services/delete.rbindex a3ea5511328..e6b481aceee 100644--- a/app/services/base_services/delete.rb+++ b/app/services/base_services/delete.rb@@ -49,7 +49,7 @@ module BaseServicesprotecteddef default_contract_class- "#{model.class.name.demodulize.pluralize}::DeleteContract".constantize+ "#{namespace}::DeleteContract".constantizeendendenddiff --git a/app/services/base_services/write.rb b/app/services/base_services/write.rbindex 03be3b55eca..cc01e4e7a11 100644--- a/app/services/base_services/write.rb+++ b/app/services/base_services/write.rb@@ -73,10 +73,6 @@ module BaseServicesraise NotImplementedErrorend- def namespace- self.class.name.deconstantize- end-def instance_classnamespace.singularize.constantizeenddiff --git a/lib/api/utilities/endpoints/delete.rb b/lib/api/utilities/endpoints/delete.rbindex 4fc3243b422..baf0e0ecc6c 100644--- a/lib/api/utilities/endpoints/delete.rb+++ b/lib/api/utilities/endpoints/delete.rb@@ -38,10 +38,12 @@ module APIdef initialize(model:,instance_generator: default_instance_generator(model),- process_service: nil)+ process_service: nil,+ api_name: model.name.demodulize)self.model = modelself.instance_generator = instance_generatorself.process_service = process_service || deduce_process_service+ self.api_name = api_nameenddef mount@@ -67,6 +69,7 @@ module APIdef render(call)if success?(call)yield+ present_success(call)elsepresent_error(call)end@@ -78,7 +81,8 @@ module APIattr_accessor :model,:instance_generator,- :process_service+ :process_service,+ :api_nameprivate@@ -86,21 +90,29 @@ module APIfail ::API::Errors::ErrorBase.create_and_merge_errors(call.errors)end+ def present_success(call)+ # Handle success cases by subclasses+ end+def success?(call)call.success?enddef deduce_process_service- "::#{deduce_namespace}::DeleteService".constantize+ "::#{deduce_backend_namespace}::DeleteService".constantizeend- def deduce_namespace+ def deduce_backend_namespacedemodulized_name.pluralizeenddef demodulized_namemodel.name.demodulizeend++ def deduce_api_namespace+ api_name.pluralize+ endendendenddiff --git a/modules/bcf/app/contracts/bcf/issues/delete_contract.rb b/modules/bcf/app/contracts/bcf/issues/delete_contract.rbnew file mode 100644index 00000000000..30f19e64c56--- /dev/null+++ b/modules/bcf/app/contracts/bcf/issues/delete_contract.rb@@ -0,0 +1,34 @@+#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)+#+# 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-2017 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 doc/COPYRIGHT.rdoc for more details.+#++++module Bcf::Issues+ class DeleteContract < ::DeleteContract+ delete_permission :manage_bcf++ end+enddiff --git a/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/delete.rb b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/delete.rbnew file mode 100644index 00000000000..e1ced89ac52--- /dev/null+++ b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/delete.rb@@ -0,0 +1,54 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module Bcf::API::V2_1::Endpoints+ class Delete < API::Utilities::Endpoints::Delete+ include ModifyMixin++ def render_success(call)+ render_representer+ .new(call.result)+ end++ def success_status+ 200+ end++ private++ def render_representer+ "::Bcf::API::V2_1::#{deduce_api_namespace}::SingleRepresenter".constantize+ end++ def deduce_process_service+ "::Bcf::#{deduce_backend_namespace}::DeleteService".constantize+ end+ end+enddiff --git a/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb b/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rbindex e9f47446017..323c32e3df6 100644--- a/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb+++ b/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb@@ -75,6 +75,11 @@ module Bcf::API::V2_1.new(model: Bcf::Issue,api_name: 'Topics').mount++ delete &::Bcf::API::V2_1::Endpoints::Delete+ .new(model: Bcf::Issue,+ api_name: 'Topics')+ .mountendendenddiff --git a/modules/bcf/app/services/bcf/issues/delete_service.rb b/modules/bcf/app/services/bcf/issues/delete_service.rbnew file mode 100644index 00000000000..ccfece7acfb--- /dev/null+++ b/modules/bcf/app/services/bcf/issues/delete_service.rb@@ -0,0 +1,49 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2019 the OpenProject Foundation (OPF)+#+# 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-2017 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 doc/COPYRIGHT.rdoc for more details.+#++++module Bcf::Issues+ class DeleteService < ::BaseServices::Delete+ private++ def before_perform(params)+ associated_wp = WorkPackage.find(model.work_package_id)+ wp_call = WorkPackages::DeleteService+ .new(user: user,+ model: associated_wp.reload)+ .call(params)++ if wp_call.success?+ super(params)+ else+ wp_call+ end+ end+ end+enddiff --git a/modules/bcf/lib/open_project/bcf/engine.rb b/modules/bcf/lib/open_project/bcf/engine.rbindex cf10abb9d90..8d556ba82a9 100644--- a/modules/bcf/lib/open_project/bcf/engine.rb+++ b/modules/bcf/lib/open_project/bcf/engine.rb@@ -48,7 +48,7 @@ module OpenProject::Bcfdependencies: %i[view_work_packages]permission :manage_bcf,{ 'bcf/issues': %i[index upload prepare_import configure_import perform_import] },- dependencies: %i[view_linked_issues view_work_packages add_work_packages edit_work_packages]+ dependencies: %i[view_linked_issues view_work_packages add_work_packages edit_work_packages delete_work_packages]endOpenProject::AccessControl.permission(:view_work_packages).actions << 'bcf/issues/redirect_to_bcf_issues_list'diff --git a/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rbindex f949708d8d9..afcae075671 100644--- a/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb+++ b/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb@@ -48,7 +48,12 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_malet(:edit_member_user) doFactoryBot.create(:user,member_in_project: project,- member_with_permissions: %i[manage_bcf add_work_packages view_linked_issues])+ member_with_permissions: %i[manage_bcf add_work_packages view_linked_issues delete_work_packages])+ end+ let(:edit_work_package_member_user) do+ FactoryBot.create(:user,+ member_in_project: project,+ member_with_permissions: %i[add_work_packages delete_work_packages])endlet(:non_member_user) doFactoryBot.create(:user)@@ -172,6 +177,59 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_maendend+ describe 'DELETE /api/bcf/2.1/projects/:project_id/topics/:uuid' do+ let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}" }+ let(:current_user) { edit_member_user }++ before do+ login_as(current_user)+ bcf_issue+ work_package+ delete path+ end++ it_behaves_like 'bcf api successful response' do+ let(:expected_body) do+ {+ "assigned_to": assignee.mail,+ "creation_author": work_package.author.mail,+ "creation_date": work_package.created_at.iso8601,+ "description": work_package.description,+ "due_date": nil,+ "guid": bcf_issue.uuid,+ "index": bcf_issue.index,+ "labels": bcf_issue.labels,+ "priority": work_package.priority.name,+ "modified_author": current_user.mail,+ "modified_date": work_package.updated_at.iso8601,+ "reference_links": [+ api_v3_paths.work_package(work_package.id)+ ],+ "stage": bcf_issue.stage,+ "title": work_package.subject,+ "topic_status": work_package.status.name,+ "topic_type": work_package.type.name+ }+ end+ end++ it 'deletes the Bcf Issue as well as the belonging Work Package' do+ expect(WorkPackage.where(id: work_package.id)).to match_array []+ expect(Bcf::Issue.where(id: bcf_issue.id)).to match_array []+ end++ context 'lacking permission to manage bcf' do+ let(:current_user) { edit_work_package_member_user }++ it_behaves_like 'bcf api not allowed response'++ it 'deletes neither the Work Package nor the Bcf Issue' do+ expect(WorkPackage.where(id: work_package.id)).to match_array [work_package]+ expect(Bcf::Issue.where(id: bcf_issue.id)).to match_array [bcf_issue]+ end+ end+ end+describe 'POST /api/bcf/2.1/projects/:project_id/topics' dolet(:path) { "/api/bcf/2.1/projects/#{project.id}/topics" }let(:current_user) { edit_member_user }