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 link offering turning the work package into a bcf topic

ulfertsf8a519d06f05
diff --git a/modules/bim/lib/api/bim/utilities/path_helper.rb b/modules/bim/lib/api/bim/utilities/path_helper.rb
index c550330df30..16d602669b2 100644
--- a/modules/bim/lib/api/bim/utilities/path_helper.rb
+++ b/modules/bim/lib/api/bim/utilities/path_helper.rb
@@ -54,8 +54,12 @@ module API
"#{root}projects/#{identifier}"
end
+ def self.topics(project_identifier)
+ "#{project(project_identifier)}/topics"
+ end
+
def self.topic(project_identifier, uuid)
- "#{project(project_identifier)}/topics/#{uuid}"
+ "#{topics(project_identifier)}/#{uuid}"
end
def self.viewpoint(project_identifier, topic_uuid, viewpoint_topic)
diff --git a/modules/bim/lib/open_project/bim/engine.rb b/modules/bim/lib/open_project/bim/engine.rb
index de67100a2e7..98e8d434b8e 100644
--- a/modules/bim/lib/open_project/bim/engine.rb
+++ b/modules/bim/lib/open_project/bim/engine.rb
@@ -114,6 +114,18 @@ module OpenProject::Bim
}
end
+ link :convertBCF,
+ cache_if: -> { current_user_allowed_to(:manage_bcf) } do
+ next if represented.bcf_issue?
+
+ {
+ href: bcf_v2_1_paths.topics(represented.project.identifier),
+ title: 'Convert to BCF',
+ payload: { reference_links: [api_v3_paths.work_package(represented.id)] },
+ method: :post
+ }
+ end
+
links :bcfViewpoints,
cache_if: -> { current_user_allowed_to(:view_linked_issues) } do
next unless represented.bcf_issue?
diff --git a/modules/bim/spec/api/v3/work_packages/work_package_representer_spec.rb b/modules/bim/spec/api/v3/work_packages/work_package_representer_spec.rb
index 1e6151c110a..5c44ffef052 100644
--- a/modules/bim/spec/api/v3/work_packages/work_package_representer_spec.rb
+++ b/modules/bim/spec/api/v3/work_packages/work_package_representer_spec.rb
@@ -35,7 +35,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:project) do
work_package.project
end
- let(:permissions) { %i[view_linked_issues view_work_packages] }
+ let(:permissions) { %i[view_linked_issues view_work_packages manage_bcf] }
let(:user) do
FactoryBot.build_stubbed(:user).tap do |u|
allow(u)
@@ -136,5 +136,35 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
end
+
+ describe 'convertBCF' do
+ let(:link) { 'convertBCF' }
+
+ context 'if no bcf issue is assigned yet' do
+ let(:bcf_topic) { nil }
+
+ it_behaves_like 'has a titled link' do
+ let(:title) { 'Convert to BCF' }
+ let(:href) { "/api/bcf/2.1/projects/#{project.identifier}/topics" }
+ end
+
+ it 'signalizes the payload' do
+ is_expected
+ .to be_json_eql({ "reference_links": ["/api/v3/work_packages/#{work_package.id}"] }.to_json)
+ .at_path('_links/convertBCF/payload')
+ end
+ end
+
+ context 'if a bcf issue is assigned' do
+ it_behaves_like 'has no link'
+ end
+
+ context 'if no bcf issue iss assigned but the user lacks permission' do
+ let(:bcf_topic) { nil }
+ let(:permissions) { %i[view_linked_issues view_work_packages] }
+
+ it_behaves_like 'has no link'
+ end
+ end
end
end