Skip to content

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

Add workdays index and default values

Oliver Günther83ad86ee7d68
diff --git a/config/schemas/user_preferences.schema.json b/config/schemas/user_preferences.schema.json
index 1d4e14c27aa..4c4de6f51d7 100644
--- a/config/schemas/user_preferences.schema.json
+++ b/config/schemas/user_preferences.schema.json
@@ -22,6 +22,12 @@
"auto_hide_popups": {
"type": "boolean"
},
+ "workdays": {
+ "type": "array",
+ "items": {
+ "type": "number"
+ }
+ },
"daily_reminders": {
"$ref": "#/definitions/DailyReminders"
},
diff --git a/db/migrate/20210928133538_add_reminder_workdays.rb b/db/migrate/20210928133538_add_reminder_workdays.rb
new file mode 100644
index 00000000000..e5d2857fd5a
--- /dev/null
+++ b/db/migrate/20210928133538_add_reminder_workdays.rb
@@ -0,0 +1,37 @@
+require_relative './migration_utils/utils'
+
+class AddReminderWorkdays < ActiveRecord::Migration[6.1]
+ include ::Migration::Utils
+
+ def change
+ reversible do |dir|
+ dir.up do
+ execute <<~SQL.squish
+ UPDATE user_preferences
+ SET settings = settings || '{ "workdays": [1,2,3,4,5] }'
+ SQL
+ end
+
+ dir.down do
+ execute <<~SQL.squish
+ UPDATE user_preferences
+ SET settings = settings - 'workdays'
+ SQL
+ end
+ end
+
+ reversible do |dir|
+ dir.up do
+ add_index :user_preferences,
+ "(settings->'workdays')",
+ using: :gin,
+ name: :index_user_prefs_settings_workdays
+
+ end
+
+ dir.down do
+ remove_index_if_exists :user_preferences, :index_user_prefs_settings_workdays
+ end
+ end
+ end
+end
diff --git a/lib/api/v3/user_preferences/user_preference_representer.rb b/lib/api/v3/user_preferences/user_preference_representer.rb
index 92f9c8247b3..c49585903dd 100644
--- a/lib/api/v3/user_preferences/user_preference_representer.rb
+++ b/lib/api/v3/user_preferences/user_preference_representer.rb
@@ -81,6 +81,8 @@ module API
property :immediate_reminders
+ property :workdays
+
property :notification_settings,
as: :notifications,
exec_context: :decorator,