Refactor user preferences, add defaults from file
* Turn prefs into a flat hash structure, since nesting is not worth the trouble * Add a custom serializer class for prefs * Add a config file for defaults and merge set prefs with unset ones * Use booleans for "true" and "false", and integers where appropriate
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class User < ApplicationRecord
|
||||
include EmailValidatable
|
||||
|
||||
serialize :preferences, Hash, default: {}
|
||||
serialize :preferences, UserPreferences
|
||||
|
||||
# Relations
|
||||
has_many :invitations, dependent: :destroy
|
||||
@@ -64,7 +64,7 @@ class User < ApplicationRecord
|
||||
|
||||
if inviter.present?
|
||||
if Setting.ejabberd_enabled? &&
|
||||
inviter.pref_enabled?("xmpp:exchange_contacts_with_invitees")
|
||||
inviter.preferences[:xmpp_exchange_contacts_with_invitees]
|
||||
exchange_xmpp_contact_with_inviter
|
||||
end
|
||||
end
|
||||
@@ -138,11 +138,6 @@ class User < ApplicationRecord
|
||||
ldap.delete_attribute(dn,:service)
|
||||
end
|
||||
|
||||
def pref_enabled?(key)
|
||||
value = preferences.dig(*key.split(":"))
|
||||
[true, "true", "enabled", 1].include?(value)
|
||||
end
|
||||
|
||||
def exchange_xmpp_contact_with_inviter
|
||||
return unless inviter.services_enabled.include?("xmpp") &&
|
||||
services_enabled.include?("xmpp")
|
||||
|
||||
Reference in New Issue
Block a user