2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-02 00:01:53 -04:00
|
|
|
class Jobs::CreateUserReviewable < ::Jobs::Base
|
2019-04-16 14:42:47 -04:00
|
|
|
attr_reader :reviewable
|
|
|
|
|
2019-04-03 12:04:05 -04:00
|
|
|
def execute(args)
|
|
|
|
raise Discourse::InvalidParameters unless args[:user_id].present?
|
|
|
|
|
2019-04-11 11:11:35 -04:00
|
|
|
reason = nil
|
|
|
|
reason ||= :must_approve_users if SiteSetting.must_approve_users?
|
|
|
|
reason ||= :invite_only if SiteSetting.invite_only?
|
|
|
|
|
|
|
|
return unless reason
|
|
|
|
|
2019-04-03 12:04:05 -04:00
|
|
|
if user = User.find_by(id: args[:user_id])
|
|
|
|
return if user.approved?
|
|
|
|
|
2019-04-16 14:42:47 -04:00
|
|
|
@reviewable =
|
|
|
|
ReviewableUser.needs_review!(
|
2019-04-03 16:41:04 -04:00
|
|
|
target: user,
|
|
|
|
created_by: Discourse.system_user,
|
|
|
|
reviewable_by_moderator: true,
|
|
|
|
payload: {
|
|
|
|
username: user.username,
|
|
|
|
name: user.name,
|
2020-02-19 10:18:05 -05:00
|
|
|
email: user.email,
|
|
|
|
website: user.user_profile&.website,
|
2019-04-03 16:41:04 -04:00
|
|
|
},
|
|
|
|
)
|
2019-04-23 15:46:18 -04:00
|
|
|
|
2019-04-23 15:53:37 -04:00
|
|
|
if @reviewable.created_new
|
|
|
|
@reviewable.add_score(
|
|
|
|
Discourse.system_user,
|
|
|
|
ReviewableScore.types[:needs_approval],
|
|
|
|
reason: reason,
|
|
|
|
force_review: true,
|
|
|
|
)
|
|
|
|
end
|
2019-04-03 12:04:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|