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
Remove days per month and days per week from admin
Christophe Bliardb5b0c411bf79
diff --git a/app/contracts/settings/working_days_and_hours_params_contract.rb b/app/contracts/settings/working_days_and_hours_params_contract.rbindex c6dbd9864c4..81cb129fe60 100644--- a/app/contracts/settings/working_days_and_hours_params_contract.rb+++ b/app/contracts/settings/working_days_and_hours_params_contract.rb@@ -32,11 +32,8 @@ module Settingsvalidate :working_days_are_presentvalidate :hours_per_day_are_present- validate :days_per_week_are_present- validate :days_per_month_are_presentvalidate :durations_are_positive_valuesvalidate :durations_are_within_bounds- validate :days_per_week_and_days_per_month_are_consistentvalidate :unique_jobprotected@@ -53,45 +50,19 @@ module Settingsendend- def days_per_week_are_present- if days_per_week.blank?- errors.add :base, :days_per_week_are_missing- end- end-- def days_per_month_are_present- if days_per_month.blank?- errors.add :base, :days_per_month_are_missing- end- end-def durations_are_positive_valuesif hours_per_day &&- days_per_week &&- days_per_month &&- any_duration_is_negative_or_zero?+ hours_per_day_is_negative_or_zero?errors.add :base, :durations_are_not_positive_numbersendenddef durations_are_within_boundserrors.add :base, :hours_per_day_is_out_of_bounds if hours_per_day.to_i > 24- errors.add :base, :days_per_week_is_out_of_bounds if days_per_week.to_i > 7- errors.add :base, :days_per_month_is_out_of_bounds if days_per_month.to_i > 31end- def any_duration_is_negative_or_zero?- !hours_per_day.to_i.positive? ||- !days_per_week.to_i.positive? ||- !days_per_month.to_i.positive?- end-- def days_per_week_and_days_per_month_are_consistent- if days_per_week &&- days_per_month &&- days_per_week.to_i != days_per_month.to_i / ChronicDuration::FULL_WEEKS_PER_MONTH- errors.add :base, :days_per_week_and_days_per_month_are_inconsistent- end+ def hours_per_day_is_negative_or_zero?+ !hours_per_day.to_i.positive?enddef unique_job@@ -107,13 +78,5 @@ module Settingsdef hours_per_dayparams[:hours_per_day]end-- def days_per_week- params[:days_per_week]- end-- def days_per_month- params[:days_per_month]- endendenddiff --git a/app/services/duration_converter.rb b/app/services/duration_converter.rbindex e1f7a921292..2746f65ef88 100644--- a/app/services/duration_converter.rb+++ b/app/services/duration_converter.rb@@ -123,8 +123,7 @@ class DurationConverterdef duration_length_options{ hours_per_day: Setting.hours_per_day,- days_per_month: Setting.days_per_month,- weeks: true }+ days_per_month: Setting.days_per_month }endendenddiff --git a/app/views/admin/settings/working_days_and_hours_settings/show.html.erb b/app/views/admin/settings/working_days_and_hours_settings/show.html.erbindex 26e2c8552c9..5f3c776c519 100644--- a/app/views/admin/settings/working_days_and_hours_settings/show.html.erb+++ b/app/views/admin/settings/working_days_and_hours_settings/show.html.erb@@ -35,9 +35,7 @@ See COPYRIGHT and LICENSE files for more details.class: 'op-working-days-admin-settings') do %>- <section class="form--section"- data-application-target="dynamic"- data-controller="admin--working-days-and-hours">+ <section class="form--section"><fieldset class="form--fieldset"><div class="form--field"><%= setting_text_field :hours_per_day,@@ -45,25 +43,6 @@ See COPYRIGHT and LICENSE files for more details.container_class: "-wide" %><div class="form--field-instructions"><%= t("setting_hours_per_day_explanation") %></div></div>-- <div class="form--field">- <%= setting_text_field :days_per_week,- type: :number,- container_class: "-wide",- data: { admin__working_days_and_hours_target: 'daysPerWeekInput',- action: 'blur->admin--working-days-and-hours#recalculateDaysPerMonth' } %>- <div class="form--field-instructions"><%= t("setting_days_per_week_explanation") %></div>- </div>-- <div class="form--field">- <%= setting_text_field :days_per_month,- type: :number,- container_class: "-wide",- data: { admin__working_days_and_hours_target: 'daysPerMonthInput',- action: 'blur->admin--working-days-and-hours#recalculateDaysPerWeek' } %>- <div class="form--field-instructions"><%= t("setting_days_per_month_explanation") %></div>- </div>-</fieldset></section>diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 038088dc084..39a0ec4c9e8 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -533,12 +533,6 @@ module Settingsdefault: 8,format: :integer},- days_per_week: {- description: "This will define what is considered a “week” when displaying duration in a more natural way " \- "(for example, if a week is 5 days, 15 days would be 3 weeks).",- default: 5,- format: :integer- },# Health check configurationhealth_checks_authentication_password: {description: "Add an authentication challenge for the /health_check endpoint",diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 270d815a5b0..6b4c6d0d120 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1047,13 +1047,8 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}working_days_are_missing: "At least one day of the week must be defined as a working day."previous_working_day_changes_unprocessed: "The previous changes to the working days configuration have not been applied yet."hours_per_day_are_missing: "The number of hours per day must be defined."- days_per_week_are_missing: "The number of days per week must be defined."- days_per_month_are_missing: "The number of days per month must be defined."durations_are_not_positive_numbers: "The durations must be positive numbers."hours_per_day_is_out_of_bounds: "Hours per day can't be more than 24"- days_per_week_is_out_of_bounds: "Days per week can't be more than 7"- days_per_month_is_out_of_bounds: "Days per month can't be more than 31"- days_per_week_and_days_per_month_are_inconsistent: "The number of days per week and the number of days per month must be consistent."time_entry:attributes:hours:@@ -3111,10 +3106,6 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}setting_cross_project_work_package_relations: "Allow cross-project work package relations"setting_first_week_of_year: "First week in year contains"setting_date_format: "Date"- setting_days_per_month: "Days per month"- setting_days_per_month_explanation: >-- This will define what is considered a "month" when displaying duration in a more natural- way (for example, if a month is 20 days, 60 days would be 3 months.setting_default_language: "Default language"setting_default_projects_modules: "Default enabled modules for new projects"setting_default_projects_public: "New projects are public by default"@@ -3134,10 +3125,6 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}setting_hours_per_day_explanation: >-This will define what is considered a "day" when displaying duration in a more naturalway (for example, if a day is 8 hours, 32 hours would be 4 days).- setting_days_per_week: "Days per week"- setting_days_per_week_explanation: >-- This will define what is considered a "week" when displaying duration in a more natural- way (for example, if a week is 5 days, 15 days would be 3 weeks).setting_invitation_expiration_days: "Activation email expires after"setting_work_package_done_ratio: "Progress calculation"setting_work_package_done_ratio_field: "Work-based"diff --git a/frontend/src/app/core/datetime/timezone.service.ts b/frontend/src/app/core/datetime/timezone.service.tsindex 9e7e8da0ceb..6ee46b52e3f 100644--- a/frontend/src/app/core/datetime/timezone.service.ts+++ b/frontend/src/app/core/datetime/timezone.service.ts@@ -151,11 +151,7 @@ export class TimezoneService {public formattedChronicDuration(durationString:string, opts = {format: 'daysAndHours',hoursPerDay: this.configurationService.hoursPerDay(),- // daysPerWeek is solely a convenience unit for the user's comprehension.- // It's not an accepted unit by chronicDuration. daysPerMonth is the value- // we provide it.daysPerMonth: this.configurationService.daysPerMonth(),- weeks: true,}):string {// Keep in sync with app/services/duration_converter#outputconst seconds = this.toSeconds(durationString) + 30;diff --git a/frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.tsindex f805ff85473..319a786854b 100644--- a/frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/admin/work-packages-settings.controller.ts@@ -30,9 +30,6 @@import { Controller } from '@hotwired/stimulus';-/*- * Helps keep daysPerWeek and daysPerMonth in-line with each other- */export default class WorkPackagesSettingsController extends Controller {static targets = ['progressCalculationModeSelect',diff --git a/frontend/src/stimulus/controllers/dynamic/admin/working-days-and-hours.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/working-days-and-hours.controller.tsdeleted file mode 100644index 69298a5fe7a..00000000000--- a/frontend/src/stimulus/controllers/dynamic/admin/working-days-and-hours.controller.ts+++ /dev/null@@ -1,58 +0,0 @@-/*- * -- copyright- * OpenProject is an open source project management software.- * Copyright (C) 2023 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 COPYRIGHT and LICENSE files for more details.- * ++- */--import { Controller } from '@hotwired/stimulus';--/*- * Helps keep daysPerWeek and daysPerMonth in-line with each other- */-export default class WorkingDaysAndHoursController extends Controller {- static targets = [- 'daysPerWeekInput',- 'daysPerMonthInput',- ];-- declare readonly daysPerWeekInputTarget:HTMLInputElement;- declare readonly daysPerMonthInputTarget:HTMLInputElement;-- connect() {}-- recalculateDaysPerWeek() {- const daysPerMonth = parseFloat(this.daysPerMonthInputTarget.value);- const daysPerWeek = daysPerMonth / 4;- this.daysPerWeekInputTarget.value = daysPerWeek.toString();- }-- recalculateDaysPerMonth() {- const daysPerWeek = parseFloat(this.daysPerWeekInputTarget.value);- const daysPerMonth = daysPerWeek * 4;- this.daysPerMonthInputTarget.value = daysPerMonth.toString();- }-}diff --git a/lib/api/v3/configuration/configuration_representer.rb b/lib/api/v3/configuration/configuration_representer.rbindex b10f31f8c55..d5f3728fd4e 100644--- a/lib/api/v3/configuration/configuration_representer.rb+++ b/lib/api/v3/configuration/configuration_representer.rb@@ -79,9 +79,6 @@ module APIproperty :hours_per_day,render_nil: true- property :days_per_week,- render_nil: true-property :days_per_month,render_nil: truediff --git a/spec/contracts/settings/working_days_and_hours_params_contract_spec.rb b/spec/contracts/settings/working_days_and_hours_params_contract_spec.rbindex 37fe7cdd54e..c05a362e2aa 100644--- a/spec/contracts/settings/working_days_and_hours_params_contract_spec.rb+++ b/spec/contracts/settings/working_days_and_hours_params_contract_spec.rb@@ -33,16 +33,16 @@ RSpec.describe Settings::WorkingDaysAndHoursParamsContract doinclude_context "ModelContract shared context"shared_let(:current_user) { create(:admin) }let(:setting) { Setting }- let(:params) { { working_days: [1], hours_per_day: 8, days_per_week: 5, days_per_month: 20 } }+ let(:params) { { working_days: [1], hours_per_day: 8 } }let(:contract) dodescribed_class.new(setting, current_user, params:)endit_behaves_like "contract is valid for active admins and invalid for regular users"- %i[working_days hours_per_day days_per_week days_per_month].each do |attribute|+ %i[working_days hours_per_day].each do |attribute|context "without #{attribute}" do- let(:params) { { working_days: [1], hours_per_day: 8, days_per_week: 5, days_per_month: 20 }.except(attribute) }+ let(:params) { { working_days: [1], hours_per_day: 8 }.except(attribute) }include_examples "contract is invalid", base: :"#{attribute}_are_missing"end@@ -50,7 +50,7 @@ RSpec.describe Settings::WorkingDaysAndHoursParamsContract docontext "with an ApplyWorkingDaysChangeJob already existing",with_good_job: WorkPackages::ApplyWorkingDaysChangeJob do- let(:params) { { working_days: [1, 2, 3], hours_per_day: 8, days_per_week: 5, days_per_month: 20 } }+ let(:params) { { working_days: [1, 2, 3], hours_per_day: 8 } }before doWorkPackages::ApplyWorkingDaysChangeJob@@ -63,58 +63,31 @@ RSpec.describe Settings::WorkingDaysAndHoursParamsContract doinclude_examples "contract is invalid", base: :previous_working_day_changes_unprocessedend- context "when days_per_week and days_per_month aren't consistent with each other" do- # There are 4 weeks per month on average, so 10 days per month in non-sensical given 5 days per week- let(:params) { { working_days: [1], hours_per_day: 8, days_per_week: 5, days_per_month: 10 } }-- include_examples "contract is invalid", base: :days_per_week_and_days_per_month_are_inconsistent- end-describe "0 durations" docontext "when hours_per_day is 0" do- let(:params) { { working_days: [1], hours_per_day: 0, days_per_week: 5, days_per_month: 20 } }-- include_examples "contract is invalid", base: :durations_are_not_positive_numbers- end-- # These two are correlated. Making only one of them 0 will also- # add the "incosistent" error tested for above.- context "when days_per_week or days_per_month is 0" do- let(:params) { { working_days: [1], hours_per_day: 8, days_per_week: 0, days_per_month: 0 } }-- include_examples "contract is invalid", base: :durations_are_not_positive_numbers- end-- context "when all durations are 0" do- let(:params) { { working_days: [1], hours_per_day: 0, days_per_week: 0, days_per_month: 0 } }+ let(:params) { { working_days: [1], hours_per_day: 0 } }include_examples "contract is invalid", base: :durations_are_not_positive_numbersendenddescribe "Text durations" do- let(:params) { { working_days: [1], hours_per_day: "blah", days_per_week: "5", days_per_month: "20" } }+ let(:params) { { working_days: [1], hours_per_day: "blah" } }include_examples "contract is invalid", base: :durations_are_not_positive_numbersenddescribe "Negative durations" do- let(:params) { { working_days: [1], hours_per_day: -2, days_per_week: -5, days_per_month: -20 } }+ let(:params) { { working_days: [1], hours_per_day: -2 } }include_examples "contract is invalid", base: :durations_are_not_positive_numbersenddescribe "Out-of-bounds durations" docontext "when hours_per_day is greater than 24" do- let(:params) { { working_days: [1], hours_per_day: 25, days_per_week: 5, days_per_month: 20 } }+ let(:params) { { working_days: [1], hours_per_day: 25 } }include_examples "contract is invalid", base: :hours_per_day_is_out_of_boundsend-- context "when days_per_week is greater than 7 and days_per_month is greater than 31" do- let(:params) { { working_days: [1], hours_per_day: 8, days_per_week: 8, days_per_month: 32 } }-- include_examples "contract is invalid", base: %i[days_per_week_is_out_of_bounds days_per_month_is_out_of_bounds]- endendenddiff --git a/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rb b/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rbindex 38e753137e9..3b70f8a0900 100644--- a/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rb+++ b/spec/controllers/admin/settings/working_days_and_hours_settings_controller_spec.rb@@ -39,10 +39,8 @@ RSpec.describe Admin::Settings::WorkingDaysAndHoursSettingsController dolet(:working_days) { [*"1".."7"] }let(:non_working_days_attributes) { {} }let(:hours_per_day) { 4 }- let(:days_per_week) { 5 }- let(:days_per_month) { 20 }let(:params) do- { settings: { working_days:, non_working_days_attributes:, hours_per_day:, days_per_week:, days_per_month: } }+ { settings: { working_days:, non_working_days_attributes:, hours_per_day: } }endsubject { patch "update", params: }