Merge pull request 'Add user preferences and configurable notifications' (#113) from feature/user_preferences into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #113 Reviewed-by: galfert <garret.alfert@gmail.com>
This commit was merged in pull request #113.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
class User < ApplicationRecord
|
||||
include EmailValidatable
|
||||
|
||||
serialize :preferences, UserPreferences
|
||||
|
||||
# Relations
|
||||
has_many :invitations, dependent: :destroy
|
||||
has_one :invitation, inverse_of: :invitee, foreign_key: 'invited_user_id'
|
||||
@@ -56,13 +58,16 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def devise_after_confirmation
|
||||
enable_service %w[ discourse ejabberd gitea mediawiki ]
|
||||
enable_service %w[ discourse gitea mediawiki xmpp ]
|
||||
|
||||
#TODO enable in development when we have easy setup of ejabberd etc.
|
||||
return if Rails.env.development?
|
||||
|
||||
if inviter.present?
|
||||
exchange_xmpp_contact_with_inviter if Setting.ejabberd_enabled?
|
||||
if Setting.ejabberd_enabled? &&
|
||||
inviter.preferences[:xmpp_exchange_contacts_with_invitees]
|
||||
exchange_xmpp_contact_with_inviter
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -135,8 +140,8 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def exchange_xmpp_contact_with_inviter
|
||||
return unless inviter.services_enabled.include?("ejabberd") &&
|
||||
services_enabled.include?("ejabberd")
|
||||
return unless inviter.services_enabled.include?("xmpp") &&
|
||||
services_enabled.include?("xmpp")
|
||||
XmppExchangeContactsJob.perform_later(inviter, self.cn, self.ou)
|
||||
end
|
||||
|
||||
|
||||
29
app/models/user_preferences.rb
Normal file
29
app/models/user_preferences.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
DEFAULT_PREFS = YAML.load_file("#{Rails.root}/config/default_preferences.yml")
|
||||
|
||||
class UserPreferences
|
||||
def self.dump(value)
|
||||
process(value).to_yaml
|
||||
end
|
||||
|
||||
def self.load(string)
|
||||
stored_prefs = YAML.load(string || "{}")
|
||||
DEFAULT_PREFS.merge(stored_prefs).with_indifferent_access
|
||||
end
|
||||
|
||||
def self.is_integer?(value)
|
||||
value.to_i.to_s == value
|
||||
end
|
||||
|
||||
def self.process(hash)
|
||||
hash.each do |key, value|
|
||||
if value == "true"
|
||||
hash[key] = true
|
||||
elsif value == "false"
|
||||
hash[key] = false
|
||||
elsif value.is_a?(String) && is_integer?(value)
|
||||
hash[key] = value.to_i
|
||||
end
|
||||
end
|
||||
hash.stringify_keys!.to_h
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user