Merge branch 'master' into feature/rs-oauth
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

# Conflicts:
#	app/models/user.rb
#	config/routes.rb
#	db/schema.rb
This commit is contained in:
2023-06-20 14:07:46 +02:00
93 changed files with 1625 additions and 504 deletions

View File

@@ -1,6 +1,8 @@
class User < ApplicationRecord
include EmailValidatable
attr_accessor :display_name
serialize :preferences, UserPreferences
# Relations
@@ -18,8 +20,8 @@ class User < ApplicationRecord
has_many :remote_storage_authorizations
validates_uniqueness_of :cn
validates_length_of :cn, :minimum => 3
validates_uniqueness_of :cn, scope: :ou
validates_length_of :cn, minimum: 3
validates_format_of :cn, with: /\A([a-z0-9\-])*\z/,
if: Proc.new{ |u| u.cn.present? },
message: "is invalid. Please use only letters, numbers and -"
@@ -33,8 +35,14 @@ class User < ApplicationRecord
validates_uniqueness_of :email
validates :email, email: true
scope :confirmed, -> { where.not(confirmed_at: nil) }
scope :pending, -> { where(confirmed_at: nil) }
validates_length_of :display_name, minimum: 3, maximum: 35, allow_blank: true,
if: -> { defined?(@display_name) }
validates_uniqueness_of :nostr_pubkey, allow_blank: true
scope :confirmed, -> { where.not(confirmed_at: nil) }
scope :pending, -> { where(confirmed_at: nil) }
scope :all_except, -> (user) { where.not(id: user) }
has_encrypted :ln_login, :ln_password
@@ -60,16 +68,18 @@ class User < ApplicationRecord
end
def devise_after_confirmation
enable_service %w[ discourse gitea mediawiki xmpp ]
if ldap_entry[:mail] != self.email
# E-Mail update confirmed
LdapManager::UpdateEmail.call(self.dn, self.email)
else
# E-Mail from signup confirmed (i.e. account activation)
enable_service %w[ discourse gitea mediawiki xmpp ]
#TODO enable in development when we have easy setup of ejabberd etc.
return if Rails.env.development?
#TODO enable in development when we have easy setup of ejabberd etc.
return if Rails.env.development? || !Setting.ejabberd_enabled?
if inviter.present?
if Setting.ejabberd_enabled? &&
inviter.preferences[:xmpp_exchange_contacts_with_invitees]
exchange_xmpp_contact_with_inviter
end
XmppExchangeContactsJob.perform_later(inviter, self) if inviter.present?
XmppSetDefaultBookmarksJob.perform_later(self)
end
end
@@ -115,8 +125,13 @@ class User < ApplicationRecord
@dn = Devise::LDAP::Adapter.get_dn(self.cn)
end
def ldap_entry
ldap.fetch_users(uid: self.cn, ou: self.ou).first
def ldap_entry(reload: false)
return @ldap_entry if defined?(@ldap_entry) && !reload
@ldap_entry = ldap.fetch_users(uid: self.cn, ou: self.ou).first
end
def display_name
@display_name ||= ldap_entry[:display_name]
end
def services_enabled
@@ -141,12 +156,6 @@ class User < ApplicationRecord
ldap.delete_attribute(dn,:service)
end
def exchange_xmpp_contact_with_inviter
return unless inviter.services_enabled.include?("xmpp") &&
services_enabled.include?("xmpp")
XmppExchangeContactsJob.perform_later(inviter, self.cn, self.ou)
end
private
def ldap