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

Implement viewpoints/:uuid/snapshot

Oliver Günther64b4f3fb9f51
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 434fd22b675..5720f55fe66 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
@@ -47,9 +47,9 @@ module Bcf::API::V2_1
scope: -> { topics })
.mount
- route_param :uuid, regexp: /\A[a-f0-9\-]+\z/ do
+ route_param :topic_uuid, regexp: /\A[a-f0-9\-]+\z/ do
after_validation do
- @issue = topics.find_by_uuid!(params[:uuid])
+ @issue = topics.find_by_uuid!(params[:topic_uuid])
end
get &::Bcf::API::V2_1::Endpoints::Show
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 64bb9b666a9..493c95b1f38 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
@@ -37,15 +37,27 @@ module Bcf::API::V2_1
scope: -> { @issue.viewpoints })
.mount
- route_param :uuid, regexp: /\A[a-f0-9\-]+\z/ do
+ route_param :viewpoint_uuid, regexp: /\A[a-f0-9\-]+\z/ do
after_validation do
- @viewpoint = @issue.viewpoints.find_by_uuid!(params[:uuid])
+ @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
+
+ 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/spec/factories/bcf_viewpoint_factory.rb b/modules/bcf/spec/factories/bcf_viewpoint_factory.rb
index 81972de6e05..9f0d0acaf9f 100644
--- a/modules/bcf/spec/factories/bcf_viewpoint_factory.rb
+++ b/modules/bcf/spec/factories/bcf_viewpoint_factory.rb
@@ -156,8 +156,14 @@ FactoryBot.define do
MARKUP
end
- after(:create) do |viewpoint|
- create(:bcf_viewpoint_attachment, container: viewpoint)
+ transient do
+ snapshot { nil }
+ end
+
+ after(:create) do |viewpoint, evaluator|
+ unless evaluator.snapshot == false
+ create(:bcf_viewpoint_attachment, container: viewpoint)
+ 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 033d72b46b1..6c3699c3b67 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
@@ -103,4 +103,32 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, wit
it_behaves_like 'bcf api not found response'
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 }
+
+ context 'when snapshot present' do
+ before do
+ login_as(current_user)
+ bcf_issue
+ get path
+ end
+
+ it 'responds with the attachment' do
+ expect(subject.status).to eq 200
+ expect(subject.headers['Content-Type']).to eq 'image/jpeg'
+ end
+ end
+
+ context 'when snapshot not present' do
+ before do
+ login_as(current_user)
+ viewpoint.snapshot.destroy
+ get path
+ end
+
+ it_behaves_like 'bcf api not found response'
+ end
+ end
end