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 all usages of Setting.plugin_costs
Klaus Zandersd7f5496b6c66
diff --git a/app/models/work_package/exports/formatters/costs.rb b/app/models/work_package/exports/formatters/costs.rbindex 9133f3cfe02..310f864aff4 100644--- a/app/models/work_package/exports/formatters/costs.rb+++ b/app/models/work_package/exports/formatters/costs.rb@@ -38,8 +38,8 @@ module WorkPackage::Exportsdef number_format_string# [$CUR] makes sure we have an actually working currency format with arbitrary currencies- curr = "[$CUR]".gsub "CUR", ERB::Util.h(Setting.plugin_costs["costs_currency"])- format = ERB::Util.h Setting.plugin_costs["costs_currency_format"]+ curr = "[$CUR]".gsub "CUR", ERB::Util.h(Setting.costs_currency)+ format = ERB::Util.h Setting.costs_currency_formatnumber = "#,##0.00"format.gsub("%n", number).gsub("%u", curr)diff --git a/modules/budgets/app/controllers/budgets_controller.rb b/modules/budgets/app/controllers/budgets_controller.rbindex 7f01d8adf16..f820b9b9fd8 100644--- a/modules/budgets/app/controllers/budgets_controller.rb+++ b/modules/budgets/app/controllers/budgets_controller.rb@@ -229,7 +229,7 @@ class BudgetsController < ApplicationControllerdef render_item_as_json(element_id, costs, unit, project, permission)response = {"#{element_id}_unit_name" => ActionController::Base.helpers.sanitize(unit),- "#{element_id}_currency" => Setting.plugin_costs["costs_currency"]+ "#{element_id}_currency" => Setting.costs_currency}if current_user.allowed_in_project?(permission, project)diff --git a/modules/budgets/app/views/budgets/items/_budget_override_cost_form.html.erb b/modules/budgets/app/views/budgets/items/_budget_override_cost_form.html.erbindex b58df02221d..101ee5b6e8a 100644--- a/modules/budgets/app/views/budgets/items/_budget_override_cost_form.html.erb+++ b/modules/budgets/app/views/budgets/items/_budget_override_cost_form.html.erb@@ -12,7 +12,7 @@) %></div><div class="form--field-affix">- <%= Setting.plugin_costs['costs_currency'] %>+ <%= Setting.costs_currency %></div></div></div>diff --git a/modules/budgets/spec/features/budgets/update_budget_spec.rb b/modules/budgets/spec/features/budgets/update_budget_spec.rbindex 8958488a8d4..5da73d7fae4 100644--- a/modules/budgets/spec/features/budgets/update_budget_spec.rb+++ b/modules/budgets/spec/features/budgets/update_budget_spec.rb@@ -205,13 +205,7 @@ RSpec.describe "updating a budget", :js doexpect(material_budget_item_2.costs).to eq(543.0)end- context "with a reversed currency format" do- before do- allow(Setting)- .to receive(:plugin_costs)- .and_return({ costs_currency_format: "%u %n", costs_currency: "USD" }.with_indifferent_access)- end-+ context "with a reversed currency format", with_settings: { costs_currency_format: "%u %n", costs_currency: "USD" } doit "can still update budgets (Regression test #32664)" dobudget_page.visit!click_on "Update"@@ -282,13 +276,7 @@ RSpec.describe "updating a budget", :js doexpect(labor_budget_item_2.costs).to eq(987.0)end- context "with a reversed currency format" do- before do- allow(Setting)- .to receive(:plugin_costs)- .and_return({ costs_currency_format: "%u %n", costs_currency: "USD" }.with_indifferent_access)- end-+ context "with a reversed currency format", with_settings: { costs_currency_format: "%u %n", costs_currency: "USD" } doit "can still update budgets (Regression test #32664)" dobudget_page.visit!click_on "Update"diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rbindex 23489e88d08..c4ea44097a1 100644--- a/modules/costs/app/models/time_entry.rb+++ b/modules/costs/app/models/time_entry.rb@@ -101,9 +101,11 @@ class TimeEntry < ApplicationRecord(user_id == usr.id && usr.allowed_in_project?(:view_own_hourly_rate, project))end- def self.can_track_start_and_end_time?+ def self.can_track_start_and_end_time?(_project: nil)OpenProject::FeatureDecisions.track_start_and_end_times_for_time_entries_active? &&- ActiveRecord::Type::Boolean.new.cast(Setting.plugin_costs["costs_currency"])+ Setting.allow_tracking_start_and_end_times++ # TODO: Add project check when we have decided if we also want a project specific flagendprivatediff --git a/modules/costs/app/views/cost_types/_list.html.erb b/modules/costs/app/views/cost_types/_list.html.erbindex 0e721aa7390..f5c50f77d51 100644--- a/modules/costs/app/views/cost_types/_list.html.erb+++ b/modules/costs/app/views/cost_types/_list.html.erb@@ -98,7 +98,7 @@ See COPYRIGHT and LICENSE files for more details.placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),id: "rate_field_#{cost_type.id}" %><span class="form-label">- <%= Setting.plugin_costs['costs_currency'] %>+ <%= Setting.costs_currency %></span><button type="submit"class="button submit_cost_type">diff --git a/modules/costs/app/views/cost_types/_rate.html.erb b/modules/costs/app/views/cost_types/_rate.html.erbindex a23bef31d88..91ca6a373f8 100644--- a/modules/costs/app/views/cost_types/_rate.html.erb+++ b/modules/costs/app/views/cost_types/_rate.html.erb@@ -71,7 +71,7 @@ See COPYRIGHT and LICENSE files for more details.no_field_container: true,required: templated ? false : true %><span class="form-label">- <%= Setting.plugin_costs['costs_currency'] %>+ <%= Setting.costs_currency %></span></span></td>diff --git a/modules/costs/app/views/costlog/edit.html.erb b/modules/costs/app/views/costlog/edit.html.erbindex 8b41038d4e5..32a26bcab40 100644--- a/modules/costs/app/views/costlog/edit.html.erb+++ b/modules/costs/app/views/costlog/edit.html.erb@@ -132,7 +132,7 @@ See COPYRIGHT and LICENSE files for more details.value: @cost_entry.overridden_costs ? unitless_currency_number(@cost_entry.overridden_costs).strip : '',placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),no_label: true,- suffix: Setting.plugin_costs['costs_currency'],+ suffix: Setting.costs_currency,id: 'cost_entry_cost_value',container_class: '-middle',size: 7 %>diff --git a/modules/costs/app/views/hourly_rates/_rate.html.erb b/modules/costs/app/views/hourly_rates/_rate.html.erbindex fa6f9ab67c9..63f6755b886 100644--- a/modules/costs/app/views/hourly_rates/_rate.html.erb+++ b/modules/costs/app/views/hourly_rates/_rate.html.erb@@ -61,7 +61,7 @@ See COPYRIGHT and LICENSE files for more details.value: rate.rate ? unitless_currency_number(rate.rate.round(2)) : "",required: true %><span class="form-label">- <%= Setting.plugin_costs['costs_currency'] %>+ <%= Setting.costs_currency %></span></span></td>diff --git a/modules/costs/lib/costs/patches/number_to_currency_converter_patch.rb b/modules/costs/lib/costs/patches/number_to_currency_converter_patch.rbindex 7343ab9dfc3..6a7489fb39b 100644--- a/modules/costs/lib/costs/patches/number_to_currency_converter_patch.rb+++ b/modules/costs/lib/costs/patches/number_to_currency_converter_patch.rb@@ -33,8 +33,8 @@ module Costs::Patches::NumberToCurrencyConverterPatchmodule InstanceMethodsdef i18n_opts- super.merge(unit: ERB::Util.h(Setting.plugin_costs["costs_currency"]),- format: ERB::Util.h(Setting.plugin_costs["costs_currency_format"]))+ super.merge(unit: ERB::Util.h(Setting.costs_currency),+ format: ERB::Util.h(Setting.costs_currency_format))endendenddiff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rbindex 4fa4b63e93c..7bb2348fe4b 100644--- a/modules/costs/spec/models/time_entry_spec.rb+++ b/modules/costs/spec/models/time_entry_spec.rb@@ -74,7 +74,7 @@ RSpec.describe TimeEntry docomments: "lorem")end- def is_member(project, user, permissions)+ def ensure_membership(project, user, permissions)create(:member,project:,user:,@@ -296,7 +296,7 @@ RSpec.describe TimeEntry dodescribe "WHEN the time_entry is assigned to the user " \"WHEN the user has the view_own_hourly_rate permission" dobefore do- is_member(project, user, [:view_own_hourly_rate])+ ensure_membership(project, user, [:view_own_hourly_rate])time_entry.user = userend@@ -307,7 +307,7 @@ RSpec.describe TimeEntry dodescribe "WHEN the time_entry is assigned to the user " \"WHEN the user lacks permissions" dobefore do- is_member(project, user, [])+ ensure_membership(project, user, [])time_entry.user = userend@@ -318,7 +318,7 @@ RSpec.describe TimeEntry dodescribe "WHEN the time_entry is assigned to another user " \"WHEN the user has the view_hourly_rates permission" dobefore do- is_member(project, user2, [:view_hourly_rates])+ ensure_membership(project, user2, [:view_hourly_rates])time_entry.user = userend@@ -329,7 +329,7 @@ RSpec.describe TimeEntry dodescribe "WHEN the time_entry is assigned to another user " \"WHEN the user has the view_hourly_rates permission in another project" dobefore do- is_member(project2, user2, [:view_hourly_rates])+ ensure_membership(project2, user2, [:view_hourly_rates])time_entry.user = userend@@ -342,7 +342,7 @@ RSpec.describe TimeEntry dodescribe "visible_by?" docontext "when not having the necessary permissions" dobefore do- is_member(project, user, [])+ ensure_membership(project, user, [])endit "is visible" do@@ -352,7 +352,7 @@ RSpec.describe TimeEntry docontext "when having the view_time_entries permission" dobefore do- is_member(project, user, [:view_time_entries])+ ensure_membership(project, user, [:view_time_entries])endit "is visible" do@@ -363,7 +363,7 @@ RSpec.describe TimeEntry docontext "when having the view_own_time_entries permission " \"and being the owner of the time entry" dobefore do- is_member(project, user, [:view_own_time_entries])+ ensure_membership(project, user, [:view_own_time_entries])time_entry.user = userend@@ -376,7 +376,7 @@ RSpec.describe TimeEntry docontext "when having the view_own_time_entries permission " \"and not being the owner of the time entry" dobefore do- is_member(project, user, [:view_own_time_entries])+ ensure_membership(project, user, [:view_own_time_entries])time_entry.user = build :userend@@ -386,4 +386,26 @@ RSpec.describe TimeEntry doendendend++ describe ".can_track_start_and_end_time?" do+ context "with the feature flag enabled", with_flag: { track_start_and_end_times_for_time_entries: true } do+ context "with the setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do+ it { expect(described_class).to be_can_track_start_and_end_time }+ end++ context "with the setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do+ it { expect(described_class).not_to be_can_track_start_and_end_time }+ end+ end++ context "with the feature flag disabled", with_flag: { track_start_and_end_times_for_time_entries: false } do+ context "with the setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do+ it { expect(described_class).not_to be_can_track_start_and_end_time }+ end++ context "with the setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do+ it { expect(described_class).not_to be_can_track_start_and_end_time }+ end+ end+ endenddiff --git a/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb b/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rbindex ddf0e0c5b33..b75de5b0f1e 100644--- a/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb+++ b/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb@@ -215,7 +215,7 @@ module OpenProject::XlsExportenddef currency_sign- Setting.plugin_costs["costs_currency"]+ Setting.costs_currencyenddef escaped_worksheet_name(name)diff --git a/modules/xls_export/lib/open_project/xls_export/xls_views.rb b/modules/xls_export/lib/open_project/xls_export/xls_views.rbindex 4b9dba6566b..1c64b2eb3e1 100644--- a/modules/xls_export/lib/open_project/xls_export/xls_views.rb+++ b/modules/xls_export/lib/open_project/xls_export/xls_views.rb@@ -32,7 +32,7 @@ class OpenProject::XlsExport::XlsViewsdef cost_type_unit_label(cost_type_id, cost_type_inst = nil, plural = true)case cost_type_idwhen -1 then l_hours(2).split[1..-1].join(" ") # get the plural for hours- when 0 then Setting.plugin_costs["costs_currency"]+ when 0 then Setting.costs_currencyelse cost_type_label(cost_type_id, cost_type_inst, plural)endenddiff --git a/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rb b/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rbindex 99e2d51463f..9e79822d749 100644--- a/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rb+++ b/modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rb@@ -161,7 +161,7 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doendend- describe "with cost and time entries" do+ describe "with cost and time entries", with_settings: { costs_currency: "EUR", costs_currency_format: "%n %u" } do# Since this test has to work without the actual costs plugin we'll just add# a custom field called 'costs' to emulate it.@@ -198,12 +198,6 @@ RSpec.describe XlsExport::WorkPackage::Exporter::XLS doendlet(:column_names) { ["subject", "status", "estimated_hours", custom_field.column_name] }- before do- allow(Setting)- .to receive(:plugin_costs)- .and_return("costs_currency" => "EUR", "costs_currency_format" => "%n %u")- end-it "exports successfully the work packages with a cost column" doexpect(sheet.rows.size).to eq(4 + 1)