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