Skip to content

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

add DELETE viewpoint to bcf api

ulferts2a130045a319
diff --git a/modules/bcf/app/contracts/bcf/viewpoints/delete_contract.rb b/modules/bcf/app/contracts/bcf/viewpoints/delete_contract.rb
new file mode 100644
index 00000000000..4605b58ace7
--- /dev/null
+++ b/modules/bcf/app/contracts/bcf/viewpoints/delete_contract.rb
@@ -0,0 +1,33 @@
+#-- 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::Viewpoints
+ class DeleteContract < ::DeleteContract
+ delete_permission :manage_bcf
+ end
+end
diff --git a/modules/bcf/app/controllers/bcf/api/v2_1/viewpoints/api.rb b/modules/bcf/app/controllers/bcf/api/v2_1/viewpoints/api.rb
index ac874e2133a..85bdb6ee512 100644
--- a/modules/bcf/app/controllers/bcf/api/v2_1/viewpoints/api.rb
+++ b/modules/bcf/app/controllers/bcf/api/v2_1/viewpoints/api.rb
@@ -53,13 +53,19 @@ module Bcf::API::V2_1
namespace = key == :/ ? :Full : key.to_s.camelize
get key, &::Bcf::API::V2_1::Endpoints::Show
- .new(model: Bcf::Issue,
+ .new(model: Bcf::Viewpoint,
api_name: 'Viewpoints',
render_representer: "::Bcf::API::V2_1::Viewpoints::#{namespace}Representer".constantize,
instance_generator: ->(*) { @issue.viewpoints.where(uuid: params[:viewpoint_uuid]) })
.mount
end
+ delete &::Bcf::API::V2_1::Endpoints::Delete
+ .new(model: Bcf::Viewpoint,
+ api_name: 'Viewpoints',
+ instance_generator: ->(*) { @issue.viewpoints.find_by!(uuid: params[:viewpoint_uuid]) })
+ .mount
+
get :bitmaps do
raise NotImplementedError, 'Bitmaps are not yet implemented.'
end
diff --git a/modules/bcf/app/services/bcf/viewpoints/delete_service.rb b/modules/bcf/app/services/bcf/viewpoints/delete_service.rb
new file mode 100644
index 00000000000..1c32b1f41e3
--- /dev/null
+++ b/modules/bcf/app/services/bcf/viewpoints/delete_service.rb
@@ -0,0 +1,34 @@
+#-- 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::Viewpoints
+ class DeleteService < ::BaseServices::Delete
+ end
+end
diff --git a/modules/bcf/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb
index 91d07a91ce3..7135d1364be 100644
--- a/modules/bcf/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb
+++ b/modules/bcf/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb
@@ -114,6 +114,45 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, wit
end
end
+ describe 'DELETE /api/bcf/2.1/projects/:project_id/topics/:uuid/viewpoints/:uuid' do
+ let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/viewpoints/#{viewpoint.uuid}" }
+ let(:current_user) { create_user }
+
+ before do
+ login_as(current_user)
+ bcf_issue
+ delete path
+ end
+
+ it_behaves_like 'bcf api successful response' do
+ let(:expected_status) { 204 }
+ let(:expected_body) { nil }
+ let(:no_content) { true }
+ end
+
+ it 'deletes the viewpoint' do
+ expect(Bcf::Viewpoint.where(id: viewpoint.id)).not_to be_exist
+ end
+
+ context 'lacking permission to see project' do
+ let(:current_user) { non_member_user }
+
+ it_behaves_like 'bcf api not found response'
+ end
+
+ context 'lacking permission to delete' do
+ let(:current_user) { view_only_user }
+
+ it_behaves_like 'bcf api not allowed response'
+ end
+
+ context 'invalid uuid' do
+ let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/viewpoints/#{viewpoint.uuid}1" }
+
+ it_behaves_like 'bcf api not found response'
+ end
+ end
+
%w[selection coloring visibility].each do |section|
describe "GET /api/bcf/2.1/projects/:project_id/topics/:uuid/viewpoints/:uuid/#{section}" do
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/viewpoints/#{viewpoint.uuid}/#{section}" }