Merge branch 'master' into feature/rs-oauth
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
class Setting < RailsSettings::Base
|
||||
cache_prefix { "v1" }
|
||||
|
||||
#
|
||||
# Internal services
|
||||
#
|
||||
|
||||
field :redis_url, type: :string, readonly: true,
|
||||
default: ENV["REDIS_URL"] || "redis://localhost:6379/0"
|
||||
|
||||
#
|
||||
# Registrations
|
||||
#
|
||||
@@ -10,6 +17,13 @@ class Setting < RailsSettings::Base
|
||||
account accounts donations mail webmaster support
|
||||
]
|
||||
|
||||
#
|
||||
# Sentry
|
||||
#
|
||||
|
||||
field :sentry_enabled, type: :boolean, readonly: true,
|
||||
default: (ENV["SENTRY_DSN"].present?.to_s || false)
|
||||
|
||||
#
|
||||
# Discourse
|
||||
#
|
||||
|
||||
@@ -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'
|
||||
@@ -24,6 +26,7 @@ class User < ApplicationRecord
|
||||
validates_format_of :cn, without: /\A-/,
|
||||
if: Proc.new{ |u| u.cn.present? },
|
||||
message: "is invalid. Usernames need to start with a letter."
|
||||
# FIXME This needs a server restart to apply values
|
||||
validates_format_of :cn, without: /\A(#{Setting.reserved_usernames.join('|')})\z/i,
|
||||
message: "has already been taken"
|
||||
|
||||
@@ -40,7 +43,9 @@ class User < ApplicationRecord
|
||||
devise :ldap_authenticatable,
|
||||
:confirmable,
|
||||
:recoverable,
|
||||
:validatable
|
||||
:validatable,
|
||||
:timeoutable,
|
||||
:rememberable
|
||||
|
||||
def ldap_before_save
|
||||
self.email = Devise::LDAP::Adapter.get_ldap_param(self.cn, "mail").first
|
||||
@@ -55,16 +60,23 @@ 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
|
||||
|
||||
def send_devise_notification(notification, *args)
|
||||
devise_mailer.send(notification, self, *args).deliver_later
|
||||
end
|
||||
|
||||
def reset_password(new_password, new_password_confirmation)
|
||||
self.password = new_password
|
||||
self.password_confirmation = new_password_confirmation
|
||||
@@ -130,8 +142,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