feat: Auto confirm user email when super admin make changes (#12418)
- If super admin updates a user email from super admin panel , it will be confirmed automatically if confirmed at is present - Also unconfirmed emails will be visible for super admins on dashboard fixes: https://github.com/chatwoot/chatwoot/issues/8958
This commit is contained in:
@@ -66,4 +66,38 @@ RSpec.describe 'Super Admin Users API', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /super_admin/users/:id' do
|
||||
let!(:user) { create(:user) }
|
||||
let(:request_path) { "/super_admin/users/#{user.id}" }
|
||||
|
||||
before { sign_in(super_admin, scope: :super_admin) }
|
||||
|
||||
it 'skips reconfirmation when confirmed_at is provided' do
|
||||
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
|
||||
patch request_path, params: { user: { email: 'updated@example.com', confirmed_at: Time.current } }
|
||||
|
||||
expect(response).to have_http_status(:redirect)
|
||||
expect(user.reload.email).to eq('updated@example.com')
|
||||
expect(user.reload.unconfirmed_email).to be_nil
|
||||
|
||||
mail_jobs = ActiveJob::Base.queue_adapter.enqueued_jobs.select do |job|
|
||||
job[:job].to_s == 'ActionMailer::MailDeliveryJob'
|
||||
end
|
||||
expect(mail_jobs.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'does not skip reconfirmation when confirmed_at is blank' do
|
||||
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
|
||||
patch request_path, params: { user: { email: 'updated-again@example.com' } }
|
||||
|
||||
expect(response).to have_http_status(:redirect)
|
||||
expect(user.reload.unconfirmed_email).to eq('updated-again@example.com')
|
||||
|
||||
mail_jobs = ActiveJob::Base.queue_adapter.enqueued_jobs.select do |job|
|
||||
job[:job].to_s == 'ActionMailer::MailDeliveryJob'
|
||||
end
|
||||
expect(mail_jobs.count).to be >= 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user