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:
Sojan Jose
2025-09-23 20:14:02 +05:30
committed by GitHub
parent 36cbd5745e
commit 114c25cae8
3 changed files with 40 additions and 6 deletions

View File

@@ -13,11 +13,11 @@ class SuperAdmin::UsersController < SuperAdmin::ApplicationController
redirect_to new_super_admin_user_path, notice: notice
end
end
#
# def update
# super
# send_foo_updated_email(requested_resource)
# end
def update
requested_resource.skip_reconfirmation! if resource_params[:confirmed_at].present?
super
end
# Override this method to specify custom lookup behavior.
# This will be used to set the resource for the `show`, `edit`, and `update`

View File

@@ -59,11 +59,11 @@ class UserDashboard < Administrate::BaseDashboard
SHOW_PAGE_ATTRIBUTES = %i[
id
avatar_url
unconfirmed_email
name
type
display_name
email
unconfirmed_email
created_at
updated_at
confirmed_at

View File

@@ -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