Allow email address updates on account settings page
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-05-25 16:58:53 +02:00
parent b1a693e7cf
commit 134c81460a
9 changed files with 188 additions and 17 deletions

View File

@@ -103,9 +103,16 @@ RSpec.describe User, type: :model do
describe "#devise_after_confirmation" do
include ActiveJob::TestHelper
after { clear_enqueued_jobs }
let(:user) { create :user, cn: "willherschel", ou: "kosmos.org" }
let(:user) { create :user, cn: "willherschel", ou: "kosmos.org", email: "will@hrsch.el" }
before do
allow(user).to receive(:ldap_entry).and_return({
uid: "willherschel", ou: "kosmos.org", mail: "will@hrsch.el"
})
end
after { clear_enqueued_jobs }
it "enables default services" do
expect(user).to receive(:enable_service).with(%w[ discourse gitea mediawiki xmpp ])
@@ -124,10 +131,11 @@ 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)
allow(guest).to receive(:ldap_entry).and_return({
uid: "isaacnewton", ou: "kosmos.org", mail: "newt@example.com"
})
end
it "enqueues jobs to exchange XMPP contacts between inviter and invitee" do
@@ -138,5 +146,31 @@ RSpec.describe User, type: :model do
expect(job["arguments"][1]['_aj_globalid']).to eq('gid://akkounts/User/2')
end
end
context "for email address update of existing account" do
before do
allow(user).to receive(:ldap_entry)
.and_return({ uid: "willherschel", ou: "kosmos.org", mail: "willyboy@aol.com" })
allow(user).to receive(:dn)
.and_return("cn=willherschel,ou=kosmos.org,cn=users,dc=kosmos,dc=org")
allow(LdapManager::UpdateEmail).to receive(:call)
end
it "updates the LDAP 'mail' attribute" do
expect(LdapManager::UpdateEmail).to receive(:call)
.with("cn=willherschel,ou=kosmos.org,cn=users,dc=kosmos,dc=org", "will@hrsch.el")
user.send :devise_after_confirmation
end
it "does not re-enable default services" do
expect(user).not_to receive(:enable_service)
user.send :devise_after_confirmation
end
it "does not enqueue any delayed jobs" do
user.send :devise_after_confirmation
expect(enqueued_jobs).to be_empty
end
end
end
end