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 viewpoints/:uuid/selection endpoint

Oliver Günther31313da3c339
diff --git a/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb b/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb
index 5720f55fe66..6bff40eef32 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
@@ -57,7 +57,7 @@ module Bcf::API::V2_1
api_name: 'Topics')
.mount
- mount Bcf::API::V2_1::ViewpointsAPI
+ mount Bcf::API::V2_1::Viewpoints::API
end
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
similarity index 57%
rename from modules/bcf/app/controllers/bcf/api/v2_1/viewpoints_api.rb
rename to modules/bcf/app/controllers/bcf/api/v2_1/viewpoints/api.rb
index e6ff51c3388..08aaa5bf069 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
@@ -29,40 +29,44 @@
#++
module Bcf::API::V2_1
- class ViewpointsAPI < ::API::OpenProjectAPI
- resources :viewpoints do
- get &::Bcf::API::V2_1::Endpoints::Index
- .new(model: Bcf::Viewpoint,
- api_name: 'Viewpoints',
- scope: -> { @issue.viewpoints })
- .mount
+ module Viewpoints
+ class API < ::API::OpenProjectAPI
+ resources :viewpoints do
+ get &::Bcf::API::V2_1::Endpoints::Index
+ .new(model: Bcf::Viewpoint,
+ api_name: 'Viewpoints',
+ scope: -> { @issue.viewpoints })
+ .mount
- route_param :viewpoint_uuid, regexp: /\A[a-f0-9\-]+\z/ do
- after_validation do
- @viewpoint = @issue.viewpoints.find_by_uuid!(params[:viewpoint_uuid])
- end
-
- get &::Bcf::API::V2_1::Endpoints::Show
- .new(model: Bcf::Viewpoint,
- api_name: 'Viewpoints')
- .mount
+ route_param :viewpoint_uuid, regexp: /\A[a-f0-9\-]+\z/ do
+ after_validation do
+ @viewpoint = @issue.viewpoints.find_by_uuid!(params[:viewpoint_uuid])
+ end
- namespace :snapshot do
- helpers ::API::Helpers::AttachmentRenderer
+ get &::Bcf::API::V2_1::Endpoints::Show
+ .new(model: Bcf::Viewpoint,
+ api_name: 'Viewpoints')
+ .mount
- get do
- if snapshot = @viewpoint.snapshot
- respond_with_attachment snapshot
- else
- raise ActiveRecord::RecordNotFound
- end
+ get :selection do
+ SelectionRepresenter.new(@viewpoint)
end
- end
- namespace :bitmaps do
- get do
+ get :bitmaps do
raise NotImplementedError, 'Bitmaps are not yet implemented.'
end
+
+ namespace :snapshot do
+ helpers ::API::Helpers::AttachmentRenderer
+
+ get do
+ if snapshot = @viewpoint.snapshot
+ respond_with_attachment snapshot
+ else
+ raise ActiveRecord::RecordNotFound
+ end
+ end
+ end
end
end
end
diff --git a/modules/bcf/app/representers/bcf/api/v2_1/viewpoints/selection_representer.rb b/modules/bcf/app/representers/bcf/api/v2_1/viewpoints/selection_representer.rb
new file mode 100644
index 00000000000..e7f08c22ae5
--- /dev/null
+++ b/modules/bcf/app/representers/bcf/api/v2_1/viewpoints/selection_representer.rb
@@ -0,0 +1,39 @@
+#-- 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
+ module Viewpoints
+ class SelectionRepresenter < SingleRepresenter
+ def to_hash
+ { selection: super.dig('components', 'selection') }
+ end
+ end
+ end
+end
diff --git a/modules/bcf/app/representers/bcf/api/v2_1/viewpoints/single_representer.rb b/modules/bcf/app/representers/bcf/api/v2_1/viewpoints/single_representer.rb
index 453ef9dbd53..50263e1043d 100644
--- a/modules/bcf/app/representers/bcf/api/v2_1/viewpoints/single_representer.rb
+++ b/modules/bcf/app/representers/bcf/api/v2_1/viewpoints/single_representer.rb
@@ -29,17 +29,19 @@
#++
module Bcf::API::V2_1
- class Viewpoints::SingleRepresenter
- attr_reader :represented
+ module Viewpoints
+ class SingleRepresenter
+ attr_reader :represented
- def initialize(represented)
- @represented = represented
- end
+ def initialize(represented)
+ @represented = represented
+ end
- def to_hash
- # Uses mapper to avoid saving JSON for now.
- # We will likely want a migration to move away from XML and render viewpoint JSON directly
- ::OpenProject::Bcf::BcfJson::ViewpointMapper.new(represented).result
+ def to_hash
+ # Uses mapper to avoid saving JSON for now.
+ # We will likely want a migration to move away from XML and render viewpoint JSON directly
+ ::OpenProject::Bcf::BcfJson::ViewpointMapper.new(represented).result
+ end
end
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 32ddfe2426d..ff528da34fd 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
@@ -104,6 +104,23 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, wit
end
end
+ describe 'GET /api/bcf/2.1/projects/:project_id/topics/:uuid/viewpoints/:uuid/selection' do
+ let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/viewpoints/#{viewpoint.uuid}/selection" }
+ let(:current_user) { view_only_user }
+
+ before do
+ login_as(current_user)
+ bcf_issue
+ get path
+ end
+
+ it_behaves_like 'bcf api successful response' do
+ let(:expected_body) do
+ { selection: viewpoint_json.dig('components', 'selection') }
+ end
+ end
+ end
+
describe 'GET /api/bcf/2.1/projects/:project_id/topics/:uuid/viewpoints/:uuid/snapshot' do
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/viewpoints/#{viewpoint.uuid}/snapshot" }
let(:current_user) { view_only_user }