Add specs for xmpp default bookmarks, refactor xmpp job usage
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Râu Cao
2023-04-08 16:37:21 +02:00
parent 705bd63b42
commit ad90fcd539
5 changed files with 68 additions and 47 deletions

View File

@@ -1,18 +1,21 @@
class XmppExchangeContactsJob < ApplicationJob
queue_as :default
def perform(inviter, username, domain)
def perform(inviter, invitee)
return unless inviter.services_enabled.include?("ejabberd") &&
invitee.services_enabled.include?("ejabberd")
ejabberd = EjabberdApiClient.new
ejabberd.add_rosteritem({
"localuser": username, "localhost": domain,
"localuser": invitee.cn, "localhost": invitee.ou,
"user": inviter.cn, "host": inviter.ou,
"nick": inviter.cn, "group": Setting.ejabberd_buddy_roster, "subs": "both"
})
ejabberd.add_rosteritem({
"localuser": inviter.cn, "localhost": inviter.ou,
"user": username, "host": domain,
"nick": username, "group": Setting.ejabberd_buddy_roster, "subs": "both"
"user": invitee.cn, "host": invitee.ou,
"nick": invitee.cn, "group": Setting.ejabberd_buddy_roster, "subs": "both"
})
end
end

View File

@@ -59,11 +59,10 @@ class User < ApplicationRecord
enable_service %w[ discourse ejabberd gitea mediawiki ]
#TODO enable in development when we have easy setup of ejabberd etc.
return if Rails.env.development?
return if Rails.env.development? || !Setting.ejabberd_enabled?
if inviter.present?
exchange_xmpp_contact_with_inviter if Setting.ejabberd_enabled?
end
XmppExchangeContactsJob.perform_later(inviter, self) if inviter.present?
XmppSetDefaultBookmarksJob.perform_later(self)
end
def send_devise_notification(notification, *args)
@@ -134,12 +133,6 @@ class User < ApplicationRecord
ldap.delete_attribute(dn,:service)
end
def exchange_xmpp_contact_with_inviter
return unless inviter.services_enabled.include?("ejabberd") &&
services_enabled.include?("ejabberd")
XmppExchangeContactsJob.perform_later(inviter, self.cn, self.ou)
end
private
def ldap