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 and viewpoint to work package
ulferts97dbb43ab84b
diff --git a/lib/api/decorators/single.rb b/lib/api/decorators/single.rbindex 061b471b47f..032fe228d87 100644--- a/lib/api/decorators/single.rb+++ b/lib/api/decorators/single.rb@@ -80,7 +80,7 @@ module APIclass_attribute :to_eager_loadclass_attribute :checked_permissions- def current_user_allowed_to(permission, context:)+ def current_user_allowed_to(permission, context: represented.respond_to?(:project) ? represented.project : nil)current_user.allowed_to?(permission, context)enddiff --git a/modules/bim/lib/api/bim/utilities/path_helper.rb b/modules/bim/lib/api/bim/utilities/path_helper.rbnew file mode 100644index 00000000000..ccc9413a3ea--- /dev/null+++ b/modules/bim/lib/api/bim/utilities/path_helper.rb@@ -0,0 +1,70 @@+#-- encoding: UTF-8+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# 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 API+ module Bim+ module Utilities+ module PathHelper+ include API::Utilities::UrlHelper++ # rubocop:disable Naming/ClassAndModuleCamelCase+ class BCF2_1Path+ extend API::Utilities::UrlHelper++ # Determining the root_path on every url we want to render is+ # expensive. As the root_path will not change within a+ # request, we can cache the first response on each request.+ def self.root_path+ RequestStore.store[:cached_root_path] ||= super+ end++ def self.root+ "#{root_path}api/bcf/2.1/"+ end++ def self.project(identifier)+ "#{root}projects/#{identifier}"+ end++ def self.topic(project_identifier, uuid)+ "#{project(project_identifier)}/topics/#{uuid}"+ end++ def self.viewpoint(project_identifier, topic_uuid, viewpoint_topic)+ "#{topic(project_identifier, topic_uuid)}/viewpoints/#{viewpoint_topic}"+ end+ end++ def bcf_v2_1_paths+ BCF2_1Path+ end+ end+ end+ end+enddiff --git a/modules/bim/lib/open_project/bim/engine.rb b/modules/bim/lib/open_project/bim/engine.rbindex 4d16fa59c41..9df1ca102dc 100644--- a/modules/bim/lib/open_project/bim/engine.rb+++ b/modules/bim/lib/open_project/bim/engine.rb@@ -103,6 +103,8 @@ module OpenProject::Bimpatch_with_namespace :DemoData, :WorkPackageBoardSeederextend_api_response(:v3, :work_packages, :work_package) do+ include API::Bim::Utilities::PathHelper+property :bcf,exec_context: :decorator,getter: ->(*) {@@ -119,6 +121,26 @@ module OpenProject::Bimif: ->(*) {represented.bcf_issue.present?}++ link :bcfTopic,+ cache_if: -> { current_user_allowed_to(:view_linked_issues) } do+ next unless represented.bcf_issue?++ {+ href: bcf_v2_1_paths.topic(represented.project.identifier, represented.bcf_issue.uuid)+ }+ end++ links :bcfViewpoints,+ cache_if: -> { current_user_allowed_to(:view_linked_issues) } do+ next unless represented.bcf_issue?++ represented.bcf_issue.viewpoints.map do |viewpoint|+ {+ href: bcf_v2_1_paths.viewpoint(represented.project.identifier, represented.bcf_issue.uuid, viewpoint.uuid)+ }+ end+ endendextend_api_response(:v3, :work_packages, :work_package_collection) dodiff --git a/modules/bim/lib/open_project/bim/patches/work_package_patch.rb b/modules/bim/lib/open_project/bim/patches/work_package_patch.rbindex fac56af9cc3..0260d997609 100644--- a/modules/bim/lib/open_project/bim/patches/work_package_patch.rb+++ b/modules/bim/lib/open_project/bim/patches/work_package_patch.rb@@ -32,6 +32,10 @@ module OpenProject::Bim::Patches::WorkPackagePatchdef self.included(base)base.class_eval dohas_one :bcf_issue, class_name: '::Bim::Bcf::Issue', foreign_key: 'work_package_id'++ def bcf_issue?+ bcf_issue.present?+ endendendenddiff --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.rbindex 384095f8721..3e2a53ad360 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@@ -30,6 +30,7 @@ require 'spec_helper'describe ::API::V3::WorkPackages::WorkPackageRepresenter doinclude API::V3::Utilities::PathHelper+ include API::Bim::Utilities::PathHelperlet(:project) dowork_package.project@@ -44,11 +45,11 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doendendend- let(:bcf_issue) do+ let(:bcf_topic) doFactoryBot.build_stubbed(:bcf_issue_with_comment)endlet(:work_package) do- FactoryBot.build_stubbed(:stubbed_work_package, bcf_issue: bcf_issue)+ FactoryBot.build_stubbed(:stubbed_work_package, bcf_issue: bcf_topic)endlet(:representer) dodescribed_class.new(work_package,@@ -68,12 +69,85 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doit "contains viewpoints" dois_expected.to be_json_eql([{- file_name: bcf_issue.viewpoints.first.attachments.first.filename,- id: bcf_issue.viewpoints.first.attachments.first.id+ file_name: bcf_topic.viewpoints.first.attachments.first.filename,+ id: bcf_topic.viewpoints.first.attachments.first.id}].to_json).including('id').at_path('bcf/viewpoints/')endend++ describe '_links' do+ describe 'bcfTopic' do+ context 'if a topic is present' do+ it_behaves_like 'has an untitled link' do+ let(:link) { 'bcfTopic' }+ let(:href) { "/api/bcf/2.1/projects/#{project.identifier}/topics/#{bcf_topic.uuid}" }+ end+ end++ context 'if no topic is present' do+ let(:bcf_topic) { nil }++ it_behaves_like 'has no link' do+ let(:link) { 'bcfTopic' }+ end+ end++ context 'if permission is lacking' do+ let(:permissions) { %i[view_work_packages] }++ it_behaves_like 'has no link' do+ let(:link) { 'bcfTopic' }+ end+ end+ end++ describe 'bcfViewpoints' do+ context 'if a viewpoint is present' do+ it_behaves_like 'has a link collection' do+ let(:link) { 'bcfViewpoints' }+ let(:hrefs) do+ [+ {+ href: bcf_v2_1_paths.viewpoint(project.identifier, bcf_topic.uuid, bcf_topic.viewpoints[0].uuid)+ }+ ]+ end+ end++ context 'if no topic is present' do+ let(:bcf_topic) { nil }++ it_behaves_like 'has no link' do+ let(:link) { 'bcfViewpoints' }+ end+ end++ context 'if no viewpoint is present' do+ before do+ allow(bcf_topic)+ .to receive(:viewpoints)+ .and_return []+ end++ it_behaves_like 'has a link collection' do+ let(:link) { 'bcfViewpoints' }+ let(:hrefs) do+ []+ end+ end+ end++ context 'if permission is lacking' do+ let(:permissions) { %i[view_work_packages] }++ it_behaves_like 'has no link' do+ let(:link) { 'bcfViewpoints' }+ end+ end+ end+ end+ endend