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
[37449] Prevent empty costs if user not allowed to see rates
Oliver Günther7522e41f8f34
diff --git a/modules/costs/app/controllers/costlog_controller.rb b/modules/costs/app/controllers/costlog_controller.rbindex 219702f9c8f..0d8521cb849 100644--- a/modules/costs/app/controllers/costlog_controller.rb+++ b/modules/costs/app/controllers/costlog_controller.rb@@ -173,7 +173,7 @@ class CostlogController < ApplicationControllerattributes = permitted_params.cost_entryattributes[:units] = Rate.parse_number_string_to_number(attributes[:units])- if attributes.key?(:overridden_costs)+ if attributes[:overridden_costs].present?attributes[:overridden_costs] = Rate.parse_number_string_to_number(attributes[:overridden_costs])enddiff --git a/modules/costs/spec/features/add_cost_entry_spec.rb b/modules/costs/spec/features/cost_entries/add_cost_entry_spec.rbsimilarity index 98%rename from modules/costs/spec/features/add_cost_entry_spec.rbrename to modules/costs/spec/features/cost_entries/add_cost_entry_spec.rbindex 83ae4f87014..261241c5251 100644--- a/modules/costs/spec/features/add_cost_entry_spec.rb+++ b/modules/costs/spec/features/cost_entries/add_cost_entry_spec.rb@@ -26,7 +26,7 @@# See docs/COPYRIGHT.rdoc for more details.#++-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')+require_relative '../../spec_helper'describe 'Work Package cost fields', type: :feature, js: true doshared_let(:type_task) { FactoryBot.create(:type_task) }diff --git a/modules/costs/spec/features/cost_entries/add_entry_without_rate_permission_spec.rb b/modules/costs/spec/features/cost_entries/add_entry_without_rate_permission_spec.rbnew file mode 100644index 00000000000..e6fc381ec68--- /dev/null+++ b/modules/costs/spec/features/cost_entries/add_entry_without_rate_permission_spec.rb@@ -0,0 +1,86 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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-2013 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_relative '../../spec_helper'++describe 'Create cost entry without rate permissions', type: :feature, js: true do+ shared_let(:type_task) { FactoryBot.create(:type_task) }+ shared_let(:status) { FactoryBot.create(:status, is_default: true) }+ shared_let(:priority) { FactoryBot.create(:priority, is_default: true) }+ shared_let(:project) do+ FactoryBot.create(:project, types: [type_task])+ end+ shared_let(:role) do+ FactoryBot.create :role, permissions: %i[view_work_packages+ log_costs+ view_cost_entries]+ end+ shared_let(:user) do+ FactoryBot.create :user,+ member_in_project: project,+ member_through_role: role+ end++ shared_let(:cost_type) do+ type = FactoryBot.create :cost_type, name: 'A', unit: 'A single', unit_plural: 'A plural'+ FactoryBot.create :cost_rate, cost_type: type, rate: 1.00+ type+ end++ shared_let(:work_package) { FactoryBot.create :work_package, project: project, status: status, type: type_task }+ shared_let(:full_view) { ::Pages::FullWorkPackage.new(work_package, project) }++ before do+ login_as user+ end++ it 'can create the item without seeing the costs' do+ full_view.visit!+ # Go to add cost entry page+ SeleniumHubWaiter.wait+ find('#action-show-more-dropdown-menu .button').click+ find('.menu-item', text: 'Log unit costs').click++ SeleniumHubWaiter.wait+ # Set single value, should update suffix+ select 'A', from: 'cost_entry_cost_type_id'+ fill_in 'cost_entry_units', with: '1'+ expect(page).to have_selector('#cost_entry_unit_name', text: 'A single')+ expect(page).to have_no_selector('#cost_entry_costs')++ click_on 'Save'++ # Expect correct costs+ expect(page).to have_selector('.flash.notice', text: I18n.t(:notice_cost_logged_successfully))+ entry = CostEntry.last+ expect(entry.cost_type_id).to eq(cost_type.id)+ expect(entry.units).to eq(1.0)+ expect(entry.costs).to eq(1.0)+ expect(entry.real_costs).to eq(1.0)+ end+end