FIX: Don't create two reviewable scores for a user

This commit is contained in:
Robin Ward 2019-04-03 16:03:32 -04:00
parent c1ea63bdc1
commit 82bddcbe51
3 changed files with 5 additions and 4 deletions

View File

@ -5,7 +5,7 @@ class Jobs::CreateUserReviewable < Jobs::Base
if user = User.find_by(id: args[:user_id])
return if user.approved?
reviewable = ReviewableUser.needs_review!(target: user, created_by: Discourse.system_user, reviewable_by_moderator: true)
reviewable = ReviewableUser.create!(target: user, created_by: Discourse.system_user, reviewable_by_moderator: true)
reviewable.add_score(
Discourse.system_user,
ReviewableScore.types[:needs_approval],

View File

@ -57,7 +57,7 @@ class EmailToken < ActiveRecord::Base
end
end
def self.confirm(token)
def self.confirm(token, skip_reviewable: false)
User.transaction do
result = atomic_confirm(token)
user = result[:user]
@ -65,8 +65,9 @@ class EmailToken < ActiveRecord::Base
# If we are activating the user, send the welcome message
user.send_welcome_message = !user.active?
user.email = result[:email_token].email
user.active = true
user.save!
user.activate
user.create_reviewable unless skip_reviewable
user.set_automatic_groups
end

View File

@ -892,7 +892,7 @@ class User < ActiveRecord::Base
def activate
if email_token = self.email_tokens.active.where(email: self.email).first
user = EmailToken.confirm(email_token.token)
user = EmailToken.confirm(email_token.token, skip_reviewable: true)
self.update!(active: true) if user.nil?
else
self.update!(active: true)