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
Make hours/day, hours/week, days/month configurable
Aaron Contreras102b0cc252ae
diff --git a/app/contracts/settings/working_days_params_contract.rb b/app/contracts/settings/working_days_and_hours_params_contract.rbsimilarity index 68%rename from app/contracts/settings/working_days_params_contract.rbrename to app/contracts/settings/working_days_and_hours_params_contract.rbindex 42bacb779ba..70adb482c7d 100644--- a/app/contracts/settings/working_days_params_contract.rb+++ b/app/contracts/settings/working_days_and_hours_params_contract.rb@@ -27,10 +27,13 @@#++module Settings- class WorkingDaysParamsContract < ::ParamsContract+ class WorkingDaysAndHoursParamsContract < ::ParamsContractinclude RequiresAdminGuardvalidate :working_days_are_present+ validate :hours_per_day_are_present+ validate :hours_per_week_are_present+ validate :days_per_month_are_presentvalidate :unique_jobprotected@@ -41,6 +44,24 @@ module Settingsendend+ def hours_per_day_are_present+ if hours_per_day.blank?+ errors.add :base, :hours_per_day_are_missing+ end+ end++ def hours_per_week_are_present+ if hours_per_week.blank?+ errors.add :base, :hours_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 unique_jobWorkPackages::ApplyWorkingDaysChangeJob.new.check_concurrency doerrors.add :base, :previous_working_day_changes_unprocessed@@ -50,5 +71,17 @@ module Settingsdef working_daysparams[:working_days]end++ def hours_per_day+ params[:hours_per_day]+ end++ def hours_per_week+ params[:hours_per_week]+ end++ def days_per_month+ params[:days_per_month]+ endendenddiff --git a/app/controllers/admin/settings/working_days_and_hours_settings_controller.rb b/app/controllers/admin/settings/working_days_and_hours_settings_controller.rbindex 15366b7adb5..f6b40d0f822 100644--- a/app/controllers/admin/settings/working_days_and_hours_settings_controller.rb+++ b/app/controllers/admin/settings/working_days_and_hours_settings_controller.rb@@ -46,11 +46,14 @@ module Admin::Settingssettings = supersettings[:working_days] = working_days_params(settings)settings[:non_working_days] = non_working_days_params+ settings[:hours_per_day] = params[:settings][:hours_per_day]+ settings[:hours_per_week] = params[:settings][:hours_per_week]+ settings[:days_per_month] = params[:settings][:days_per_month]settingsenddef update_service- ::Settings::WorkingDaysUpdateService+ ::Settings::WorkingDaysAndHoursUpdateServiceendprivatediff --git a/app/services/duration_converter.rb b/app/services/duration_converter.rbindex 757c4928178..885ec15805a 100644--- a/app/services/duration_converter.rb+++ b/app/services/duration_converter.rb@@ -38,7 +38,7 @@ class DurationConverterdef parse(duration_string)# Keep 0 values and convert the extracted duration to hours# by dividing by 3600.- ChronicDuration.parse(duration_string, keep_zero: true, default_unit: "hours") / 3600.to_f+ ChronicDuration.parse(duration_string, keep_zero: true, default_unit: "hours", **duration_length_options) / 3600.to_fenddef output(duration_in_hours)@@ -52,10 +52,10 @@ class DurationConverter# keeping zeroes, we'd format this as "0 secs".## We want to override this behavior.- if ChronicDuration.output(duration_in_seconds, default_unit: "hours").nil?+ if ChronicDuration.output(duration_in_seconds, default_unit: "hours", **duration_length_options).nil?"0h"else- ChronicDuration.output(duration_in_seconds, default_unit: "hours", format: :short)+ ChronicDuration.output(duration_in_seconds, default_unit: "hours", format: :short, **duration_length_options)endend@@ -64,5 +64,9 @@ class DurationConverterdef convert_duration_to_seconds(duration_in_hours)(BigDecimal(duration_in_hours.to_s) * 3600).to_fend++ def duration_length_options+ { hours_per_day: Setting.hours_per_day, days_per_month: Setting.days_per_month }+ endendenddiff --git a/app/services/settings/working_days_update_service.rb b/app/services/settings/working_days_and_hours_update_service.rbsimilarity index 95%rename from app/services/settings/working_days_update_service.rbrename to app/services/settings/working_days_and_hours_update_service.rbindex 56575aed1e8..50f80557a3a 100644--- a/app/services/settings/working_days_update_service.rb+++ b/app/services/settings/working_days_and_hours_update_service.rb@@ -26,7 +26,7 @@# See COPYRIGHT and LICENSE files for more details.#++-class Settings::WorkingDaysUpdateService < Settings::UpdateService+class Settings::WorkingDaysAndHoursUpdateService < Settings::UpdateServicedef call(params)params = params.to_h.deep_symbolize_keysself.non_working_days_params = params.delete(:non_working_days) || []@@ -36,7 +36,8 @@ class Settings::WorkingDaysUpdateService < Settings::UpdateServiceenddef validate_params(params)- contract = Settings::WorkingDaysParamsContract.new(model, user, params:)+ binding.pry+ contract = Settings::WorkingDaysAndHoursParamsContract.new(model, user, params:)ServiceResult.new success: contract.valid?,errors: contract.errors,result: modeldiff --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 44314edcb32..8c77b003cf4 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@@ -29,20 +29,43 @@ See COPYRIGHT and LICENSE files for more details.<%= toolbar title: t(:label_working_days_and_hours) %>-<div class="op-toast -warning">- <div class="op-toast--content">- <p>- <%= t("working_days.warning").html_safe %>- </p>- </div>-</div>-<%= styled_form_tag(admin_settings_working_days_and_hours_path,method: :patch,class: 'op-working-days-admin-settings') do %>+ <section class="form--section">+ <fieldset class="form--fieldset">+ <div class="form--field">+ <%= setting_text_field :hours_per_day,+ type: :number %>+ <div class="form--field-instructions"><%= t("setting_hours_per_day_explanation") %></div>+ </div>++ <div class="form--field">+ <%= setting_text_field :hours_per_week,+ type: :number %>+ <div class="form--field-instructions"><%= t("setting_hours_per_week_explanation") %></div>+ </div>++ <div class="form--field">+ <%= setting_text_field :days_per_month,+ type: :number %>+ <div class="form--field-instructions"><%= t("setting_days_per_month_explanation") %></div>+ </div>++ </fieldset>+ </section>++ <div class="op-toast -warning">+ <div class="op-toast--content">+ <p>+ <%= t("working_days.warning").html_safe %>+ </p>+ </div>+ </div>+<section class="form--section"><fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= t('settings.working_days.section_work_week') %></legend>diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 479ed4fa1e4..1ae869b2f66 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -303,6 +303,12 @@ module Settings"%B %d, %Y"].freeze},+ days_per_month: {+ description: "This will define what is considered a “week” when displaying duration in a more natural way " \+ "(for example, if a month is 20 days, 60 days would be 3 months.",+ default: 20,+ format: :integer+ },default_auto_hide_popups: {description: "Whether to automatically hide success notifications by default",default: true@@ -518,6 +524,18 @@ module Settingshost_name: {default: "localhost:3000"},+ hours_per_day: {+ description: "This will define what is considered a “day” when displaying duration in a more natural way " \+ "(for example, if a day is 8 hours, 32 hours would be 4 days).",+ default: 8,+ format: :integer+ },+ hours_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 40 hours, 1260 hours would be 7.5 weeks).",+ default: 40,+ 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 d9906f57c96..7be9328bdde 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1018,6 +1018,9 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}base: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."+ hours_per_week_are_missing: "The number of hours per week must be defined."+ days_per_month_are_missing: "The number of days per month must be defined."time_entry:attributes:hours:@@ -3074,6 +3077,8 @@ 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 “week” 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"@@ -3089,6 +3094,12 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}setting_feeds_limit: "Feed content limit"setting_file_max_size_displayed: "Max size of text files displayed inline"setting_host_name: "Host name"+ setting_hours_per_day: "Hours per day"+ setting_hours_per_day_explanation: >+ This will define what is considered a “day” when displaying duration in a more natural way (for example, if a day is 8 hours, 32 hours would be 4 days).+ setting_hours_per_week: "Hours per week"+ setting_hours_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 40 hours, 1260 hours would be 7.5 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/spec/contracts/settings/working_days_params_contract_spec.rb b/spec/contracts/settings/working_days_and_hours_params_contract_spec.rbsimilarity index 97%rename from spec/contracts/settings/working_days_params_contract_spec.rbrename to spec/contracts/settings/working_days_and_hours_params_contract_spec.rbindex ddd60516a28..4272ed1c6bd 100644--- a/spec/contracts/settings/working_days_params_contract_spec.rb+++ b/spec/contracts/settings/working_days_and_hours_params_contract_spec.rb@@ -29,7 +29,7 @@require "spec_helper"require "contracts/shared/model_contract_shared_context"-RSpec.describe Settings::WorkingDaysParamsContract do+RSpec.describe Settings::WorkingDaysAndHoursParamsContract doinclude_context "ModelContract shared context"shared_let(:current_user) { create(:admin) }let(:setting) { Setting }diff --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 9e465ef9903..baca0292526 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@@ -38,8 +38,11 @@ RSpec.describe Admin::Settings::WorkingDaysAndHoursSettingsController dodescribe "update" dolet(:working_days) { [*"1".."7"] }let(:non_working_days_attributes) { {} }+ let(:hours_per_day) { 4 }+ let(:hours_per_week) { 16 }+ let(:days_per_month) { 25 }let(:params) do- { settings: { working_days:, non_working_days_attributes: } }+ { settings: { working_days:, non_working_days_attributes:, hours_per_day:, hours_per_week:, days_per_month: } }endsubject { patch "update", params: }diff --git a/spec/services/settings/working_days_update_service_spec.rb b/spec/services/settings/working_days_and_hours_update_service_spec.rbsimilarity index 94%rename from spec/services/settings/working_days_update_service_spec.rbrename to spec/services/settings/working_days_and_hours_update_service_spec.rbindex 597466215d6..cd7b8072c94 100644--- a/spec/services/settings/working_days_update_service_spec.rb+++ b/spec/services/settings/working_days_and_hours_update_service_spec.rb@@ -27,7 +27,7 @@require "spec_helper"require_relative "shared/shared_call_examples"-RSpec.describe Settings::WorkingDaysUpdateService do+RSpec.describe Settings::WorkingDaysAndHoursUpdateService dolet(:instance) dodescribed_class.new(user:)end@@ -39,7 +39,7 @@ RSpec.describe Settings::WorkingDaysUpdateService doendlet(:contract_success) { true }let(:params_contract) do- instance_double(Settings::WorkingDaysParamsContract,+ instance_double(Settings::WorkingDaysAndHoursParamsContract,valid?: params_contract_success,errors: instance_double(ActiveModel::Error))end@@ -55,20 +55,20 @@ RSpec.describe Settings::WorkingDaysUpdateService do# stub a setting definitionallow(Setting).to receive(:[])- .and_call_original+ .and_call_originalallow(Setting).to receive(:[]).with(setting_name)- .and_return(previous_setting_value)+ .and_return(previous_setting_value)allow(Setting).to receive(:[]=)# stub contractallow(Settings::UpdateContract).to receive(:new)- .and_return(contract)- allow(Settings::WorkingDaysParamsContract)+ .and_return(contract)+ allow(Settings::WorkingDaysAndHoursParamsContract).to receive(:new)- .and_return(params_contract)+ .and_return(params_contract)enddescribe "#call" do@@ -87,7 +87,7 @@ RSpec.describe Settings::WorkingDaysUpdateService doexpect(WorkPackages::ApplyWorkingDaysChangeJob).to have_received(:perform_later)- .with(user_id: user.id, previous_working_days:, previous_non_working_days:)+ .with(user_id: user.id, previous_working_days:, previous_non_working_days:)endend