2019-04-04 00:04:05 +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
|
|
|
return if @reviewable.score > 0
|
|
|
|
|
2019-04-17 02:42:47 +08:00
|
|
|
@reviewable.add_score(
|
2019-04-04 00:04:05 +08:00
|
|
|
Discourse.system_user,
|
|
|
|
ReviewableScore.types[:needs_approval],
|
2019-04-11 23:11:35 +08:00
|
|
|
reason: reason,
|
2019-04-04 00:04:05 +08:00
|
|
|
force_review: true
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|