mirror of https://github.com/tootsuite/mastodon
Rename and refactor `User#confirm!` to `User#mark_email_as_confirmed!` (#28735)
parent
e621c1c44c
commit
98b5f85f10
|
@ -7,7 +7,7 @@ module Admin
|
||||||
|
|
||||||
def create
|
def create
|
||||||
authorize @user, :confirm?
|
authorize @user, :confirm?
|
||||||
@user.confirm!
|
@user.mark_email_as_confirmed!
|
||||||
log_action :confirm, @user
|
log_action :confirm, @user
|
||||||
redirect_to admin_accounts_path
|
redirect_to admin_accounts_path
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,7 +61,7 @@ module User::Omniauthable
|
||||||
user.account.avatar_remote_url = nil
|
user.account.avatar_remote_url = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
user.confirm! if email_is_verified
|
user.mark_email_as_confirmed! if email_is_verified
|
||||||
user.save!
|
user.save!
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
|
@ -190,37 +190,16 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def confirm
|
def confirm
|
||||||
new_user = !confirmed?
|
wrap_email_confirmation do
|
||||||
self.approved = true if grant_approval_on_confirmation?
|
super
|
||||||
|
|
||||||
super
|
|
||||||
|
|
||||||
if new_user
|
|
||||||
# Avoid extremely unlikely race condition when approving and confirming
|
|
||||||
# the user at the same time
|
|
||||||
reload unless approved?
|
|
||||||
|
|
||||||
if approved?
|
|
||||||
prepare_new_user!
|
|
||||||
else
|
|
||||||
notify_staff_about_pending_account!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def confirm!
|
# Mark current email as confirmed, bypassing Devise
|
||||||
new_user = !confirmed?
|
def mark_email_as_confirmed!
|
||||||
self.approved = true if grant_approval_on_confirmation?
|
wrap_email_confirmation do
|
||||||
|
skip_confirmation!
|
||||||
skip_confirmation!
|
save!
|
||||||
save!
|
|
||||||
|
|
||||||
if new_user
|
|
||||||
# Avoid extremely unlikely race condition when approving and confirming
|
|
||||||
# the user at the same time
|
|
||||||
reload unless approved?
|
|
||||||
|
|
||||||
prepare_new_user! if approved?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -435,6 +414,25 @@ class User < ApplicationRecord
|
||||||
open_registrations? && !sign_up_from_ip_requires_approval? && !sign_up_email_requires_approval?
|
open_registrations? && !sign_up_from_ip_requires_approval? && !sign_up_email_requires_approval?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wrap_email_confirmation
|
||||||
|
new_user = !confirmed?
|
||||||
|
self.approved = true if grant_approval_on_confirmation?
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
if new_user
|
||||||
|
# Avoid extremely unlikely race condition when approving and confirming
|
||||||
|
# the user at the same time
|
||||||
|
reload unless approved?
|
||||||
|
|
||||||
|
if approved?
|
||||||
|
prepare_new_user!
|
||||||
|
else
|
||||||
|
notify_staff_about_pending_account!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def sign_up_from_ip_requires_approval?
|
def sign_up_from_ip_requires_approval?
|
||||||
!sign_up_ip.nil? && IpBlock.where(severity: :sign_up_requires_approval).where('ip >>= ?', sign_up_ip.to_s).exists?
|
!sign_up_ip.nil? && IpBlock.where(severity: :sign_up_requires_approval).where('ip >>= ?', sign_up_ip.to_s).exists?
|
||||||
end
|
end
|
||||||
|
|
|
@ -105,7 +105,7 @@ module Mastodon::CLI
|
||||||
if user.save
|
if user.save
|
||||||
if options[:confirmed]
|
if options[:confirmed]
|
||||||
user.confirmed_at = nil
|
user.confirmed_at = nil
|
||||||
user.confirm!
|
user.mark_email_as_confirmed!
|
||||||
end
|
end
|
||||||
|
|
||||||
user.approve! if options[:approve]
|
user.approve! if options[:approve]
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe 'Using OAuth from an external app' do
|
||||||
let(:user) { Fabricate(:user, email: email, password: password) }
|
let(:user) { Fabricate(:user, email: email, password: password) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
user.confirm!
|
user.mark_email_as_confirmed!
|
||||||
user.approve!
|
user.approve!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -461,12 +461,12 @@ RSpec.describe User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#confirm!' do
|
describe '#mark_email_as_confirmed!' do
|
||||||
subject(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
|
subject(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
ActionMailer::Base.deliveries.clear
|
ActionMailer::Base.deliveries.clear
|
||||||
user.confirm!
|
user.mark_email_as_confirmed!
|
||||||
end
|
end
|
||||||
|
|
||||||
after { ActionMailer::Base.deliveries.clear }
|
after { ActionMailer::Base.deliveries.clear }
|
||||||
|
|
|
@ -64,7 +64,7 @@ RSpec.describe UserPolicy do
|
||||||
|
|
||||||
context 'when record.confirmed?' do
|
context 'when record.confirmed?' do
|
||||||
it 'denies' do
|
it 'denies' do
|
||||||
john.user.confirm!
|
john.user.mark_email_as_confirmed!
|
||||||
expect(subject).to_not permit(admin, john.user)
|
expect(subject).to_not permit(admin, john.user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue