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

Restore adding array-style accessing

Oliver Günther3eff4f1ace54
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index d925a72dcee..97e7245fdd1 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -55,9 +55,6 @@ class UserPreference < ApplicationRecord
end
end
- # Allow previous array-style accessing as well
- # delegate :[], :[]=, to: :settings
-
##
# We respond to all methods as we retrieve
# the key from settings
@@ -65,6 +62,22 @@ class UserPreference < ApplicationRecord
true
end
+ def [](attr_name)
+ if attribute?(attr_name)
+ super
+ else
+ send attr_name
+ end
+ end
+
+ def []=(attr_name, value)
+ if attribute?(attr_name)
+ super
+ else
+ send :"#{attr_name}=", value
+ end
+ end
+
def comments_sorting
settings.fetch(:comments_sorting, OpenProject::Configuration.default_comment_sort_order)
end
@@ -96,7 +109,7 @@ class UserPreference < ApplicationRecord
alias :auto_hide_popups :auto_hide_popups?
def comments_in_reverse_order=(value)
- others[:comments_sorting] = to_boolean(value) ? 'desc' : 'asc'
+ settings[:comments_sorting] = to_boolean(value) ? 'desc' : 'asc'
end
def time_zone
@@ -116,6 +129,10 @@ class UserPreference < ApplicationRecord
ActiveRecord::Type::Boolean.new.cast(value)
end
+ def attribute?(name)
+ %i[user user_id].include?(name.to_sym)
+ end
+
def init_settings
self.settings ||= {}
end