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
fix assigning a buget to a work package
ulfertsbf531bf7300b
diff --git a/modules/costs/lib/open_project/costs/engine.rb b/modules/costs/lib/open_project/costs/engine.rbindex cc551a725b1..7019271bdcf 100644--- a/modules/costs/lib/open_project/costs/engine.rb+++ b/modules/costs/lib/open_project/costs/engine.rb@@ -242,6 +242,19 @@ module OpenProject::Costsendend+ # This should not be necessary as the payload representer inherits+ # from the work package representer. The patching probably happens after+ # the payload representer is already evaluated.+ extend_api_response(:v3, :work_packages, :work_package_payload) do+ prepend API::V3::CostsApiUserPermissionCheck++ associated_resource :cost_object,+ v3_path: :budget,+ link_title_attribute: :subject,+ representer: ::API::V3::Budgets::BudgetRepresenter,+ skip_render: ->(*) { !cost_object_visible? }+ end+extend_api_response(:v3, :work_packages, :schema, :work_package_schema) do# N.B. in the long term we should have a type like "Currency", but that requires a proper# format and not a string like "10 EUR"diff --git a/modules/costs/spec/features/costs_edit_fields_spec.rb b/modules/costs/spec/features/costs_edit_fields_spec.rbindex 3dd07706e9e..a65d68157a7 100644--- a/modules/costs/spec/features/costs_edit_fields_spec.rb+++ b/modules/costs/spec/features/costs_edit_fields_spec.rb@@ -32,34 +32,36 @@ describe 'Work Package cost fields', type: :feature, js: true dolet(:type_task) { FactoryBot.create(:type_task) }let!(:status) { FactoryBot.create(:status, is_default: true) }let!(:priority) { FactoryBot.create(:priority, is_default: true) }- let!(:project) {- FactoryBot.create(:project, types: [type_task])- }+ let!(:project) { FactoryBot.create(:project, types: [type_task]) }let(:user) { FactoryBot.create :admin }- let(:budget) { FactoryBot.create :cost_object, author: user, project: project }+ let!(:budget) { FactoryBot.create :cost_object, author: user, project: project }- let(:wp_table) { ::Pages::WorkPackagesTable.new(project) }- let(:split_create) { ::Pages::SplitWorkPackageCreate.new(project: project) }+ let(:create_page) { ::Pages::FullWorkPackageCreate.new(project: project) }+ let(:view_page) { ::Pages::FullWorkPackage.new(project: project) }before do- budgetlogin_as(user)end- it 'does not show read-only fields' do- wp_table.visit!- wp_table.expect_no_work_package_listed-- split_create.click_create_wp_button type_task- split_create.expect_fully_loaded+ it 'does not show read-only fields and allows setting the cost object' do+ create_page.visit!expect(page).to have_selector('.inline-edit--container.costObject')expect(page).to have_no_selector('.inline-edit--container.laborCosts')expect(page).to have_no_selector('.inline-edit--container.materialCosts')expect(page).to have_no_selector('.inline-edit--container.overallCosts')- field = split_create.edit_field(:costObject)- field.openSelectField+ field = create_page.edit_field(:costObject)field.set_value budget.name+ page.find('.ng-dropdown-panel .ng-option', text: budget.name).click++ field = create_page.edit_field(:subject)+ field.set_value 'Some subject'++ create_page.save!++ view_page.expect_notification(message: "Successful creation.")++ view_page.edit_field(:costObject).expect_display_value budget.nameendenddiff --git a/modules/costs/spec/lib/api/v3/work_packages/work_package_payload_representer_rendering_spec.rb b/modules/costs/spec/lib/api/v3/work_packages/work_package_payload_representer_rendering_spec.rbnew file mode 100644index 00000000000..ce6d94176ba--- /dev/null+++ b/modules/costs/spec/lib/api/v3/work_packages/work_package_payload_representer_rendering_spec.rb@@ -0,0 +1,90 @@+#-- 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.+#++++require 'spec_helper'++describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter, 'rendering' do+ include API::V3::Utilities::PathHelper++ let(:work_package) do+ FactoryBot.build_stubbed(:stubbed_work_package,+ start_date: Date.today.to_datetime,+ due_date: Date.today.to_datetime,+ created_at: DateTime.now,+ updated_at: DateTime.now,+ cost_object: cost_object,+ type: FactoryBot.build_stubbed(:type)) do |wp|+ end+ end++ let(:cost_object) { FactoryBot.build_stubbed(:cost_object) }++ let(:permissions) { %i(view_cost_objects edit_work_packages) }++ let(:project) { work_package.project }++ include_context 'user with stubbed permissions'++ let(:representer) do+ ::API::V3::WorkPackages::WorkPackagePayloadRepresenter+ .create(work_package, current_user: user)+ end++ subject(:generated) { representer.to_json }++ describe '_links' do+ describe 'costObject' do+ context 'without a cost object assigned' do+ let(:cost_object) { nil }++ it 'has an empty href' do+ expect(subject)+ .to be_json_eql(nil.to_json)+ .at_path '_links/costObject/href'+ end+ end++ context 'with a cost object assigned' do+ it 'has an href to the cost object' do+ expect(subject)+ .to be_json_eql(api_v3_paths.budget(cost_object.id).to_json)+ .at_path '_links/costObject/href'+ end+ end++ context 'without necessary permissions' do+ let(:permissions) { %i(edit_work_packages) }++ it 'has no href' do+ expect(subject)+ .not_to have_json_path('_links/costObject')+ end+ end+ end+ end+end