Do not exchange XMPP contacts when turned off by inviter
Some checks are pending
continuous-integration/drone/push Build is running

This commit is contained in:
Râu Cao 2023-04-04 12:45:13 +02:00
parent 62cd0eb7d1
commit 595bb03c5a
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
2 changed files with 17 additions and 1 deletions

View File

@ -63,7 +63,10 @@ class User < ApplicationRecord
return if Rails.env.development?
if inviter.present?
exchange_xmpp_contact_with_inviter if Setting.ejabberd_enabled?
if Setting.ejabberd_enabled? &&
inviter.pref_enabled?("xmpp:exchange_contacts_with_invitees")
exchange_xmpp_contact_with_inviter
end
end
end

View File

@ -139,6 +139,8 @@ RSpec.describe User, type: :model do
let(:guest) { create :user, id: 2, cn: "isaacnewton", ou: "kosmos.org", email: "newt@example.com" }
before do
# TODO remove when defaults are implemented
user.update! preferences: {"xmpp" => { "exchange_contacts_with_invitees" => true }}
Invitation.create! user: user, invited_user_id: guest.id, used_at: DateTime.now
allow_any_instance_of(User).to receive(:enable_service).and_return(true)
end
@ -147,6 +149,17 @@ RSpec.describe User, type: :model do
expect(guest).to receive(:exchange_xmpp_contact_with_inviter)
guest.send(:devise_after_confirmation)
end
context "automatic contact exchange disabled" do
before do
user.update! preferences: {"xmpp" => { "exchange_contacts_with_invitees" => false }}
end
it "does not exchange XMPP contacts with the inviter" do
expect(guest).to_not receive(:exchange_xmpp_contact_with_inviter)
guest.send(:devise_after_confirmation)
end
end
end
end