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
Set default workdays for email reminders to Monday-Friday
Christophe Bliard4208661d1d9c
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rbindex 3c0f78a36a2..7d265b9e3df 100644--- a/app/models/user_preference.rb+++ b/app/models/user_preference.rb@@ -33,6 +33,9 @@ class UserPreference < ApplicationRecordvalidates :user,presence: true++ WORKDAYS_FROM_MONDAY_TO_FRIDAY = [1, 2, 3, 4, 5].freeze+### Retrieve keys from settings, and allow accessing# as boolean with ? suffix@@ -124,6 +127,10 @@ class UserPreference < ApplicationRecordsuper.presence || { enabled: true, times: ["08:00:00+00:00"] }.with_indifferent_accessend+ def workdays+ super || WORKDAYS_FROM_MONDAY_TO_FRIDAY+ end+def immediate_reminderssuper.presence || { mentioned: false }.with_indifferent_accessenddiff --git a/frontend/src/app/features/user-preferences/state/user-preferences.store.ts b/frontend/src/app/features/user-preferences/state/user-preferences.store.tsindex 4479bd38493..93546af053a 100644--- a/frontend/src/app/features/user-preferences/state/user-preferences.store.ts+++ b/frontend/src/app/features/user-preferences/state/user-preferences.store.ts@@ -44,7 +44,7 @@ function createInitialState():IUserPreference {enabled: true,times: ['08:00'],},- workdays: [],+ workdays: [1, 2, 3, 4, 5],immediateReminders: {mentioned: false,},diff --git a/spec/features/notifications/settings/workdays_settings_spec.rb b/spec/features/notifications/settings/workdays_settings_spec.rbindex a1557de4ef7..eff47677952 100644--- a/spec/features/notifications/settings/workdays_settings_spec.rb+++ b/spec/features/notifications/settings/workdays_settings_spec.rb@@ -14,7 +14,8 @@ describe "Workday notification settings", type: :feature, js: true do# Configure the reminderssettings_page.visit!- settings_page.expect_non_workdays %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]+ settings_page.expect_workdays %w[Monday Tuesday Wednesday Thursday Friday]+ settings_page.expect_non_workdays %w[Saturday Sunday]settings_page.set_workdays Monday: true,Tuesday: true,@@ -36,11 +37,12 @@ describe "Workday notification settings", type: :feature, js: true doexpect(pref.reload.workdays).to eq [1, 2, 5, 6, 7]end- it 'updates properly working days' do+ it 'can unselect all working days' do# Configure the reminderssettings_page.visit!- settings_page.expect_non_workdays %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]+ settings_page.expect_workdays %w[Monday Tuesday Wednesday Thursday Friday]+ settings_page.expect_non_workdays %w[Saturday Sunday]settings_page.set_workdays Monday: false,Tuesday: false,@@ -72,7 +74,8 @@ describe "Workday notification settings", type: :feature, js: true dosettings_page.visit!# Expect Mo-Fr to be checked- settings_page.expect_non_workdays %w[Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag]+ settings_page.expect_workdays %w[Montag Dienstag Mittwoch Donnerstag Freitag]+ settings_page.expect_non_workdays %w[Samstag Sonntag]settings_page.set_workdays Montag: true,Dienstag: true,diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rbindex 901ac73d8f4..ed531889029 100644--- a/spec/models/user_preference_spec.rb+++ b/spec/models/user_preference_spec.rb@@ -179,13 +179,48 @@ describe UserPreference do}end- it 'uses the defaults' do+ it 'returns the stored value' doexpect(subject.daily_reminders).to eql(settings["daily_reminders"])endendend+ describe '#workdays' do+ context 'without work days being stored' do+ it 'uses the defaults' do+ expect(subject.workdays)+ .to eq([1, 2, 3, 4, 5])+ end+ end++ context 'with work days being stored' do+ let(:settings) do+ {+ "workdays" => [1, 2, 4, 5]+ }+ end++ it 'returns the stored value' do+ expect(subject.workdays)+ .to eql([1, 2, 4, 5])+ end+ end++ context 'with work days being stored and empty' do+ let(:settings) do+ {+ "workdays" => []+ }+ end++ it 'return empty array' do+ expect(subject.workdays)+ .to eql([])+ end+ end+ end+describe '[]=' dolet(:user) { create(:user) }