mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
If you turn it on now, default all users to approved since they were previously. Also support approving a user that doesn't have a reviewable record (it will be created first.) This also includes a refactor to move class method calls to `DiscourseEvent` into an initializer. Otherwise the load order of classes makes a difference in the test environment and some settings might be triggered and others not, randomly.
35 lines
879 B
Ruby
35 lines
879 B
Ruby
class Jobs::CreateUserReviewable < Jobs::Base
|
|
attr_reader :reviewable
|
|
|
|
def execute(args)
|
|
raise Discourse::InvalidParameters unless args[:user_id].present?
|
|
|
|
reason = nil
|
|
reason ||= :must_approve_users if SiteSetting.must_approve_users?
|
|
reason ||= :invite_only if SiteSetting.invite_only?
|
|
|
|
return unless reason
|
|
|
|
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,
|
|
payload: {
|
|
username: user.username,
|
|
name: user.name,
|
|
email: user.email
|
|
}
|
|
)
|
|
@reviewable.add_score(
|
|
Discourse.system_user,
|
|
ReviewableScore.types[:needs_approval],
|
|
reason: reason,
|
|
force_review: true
|
|
)
|
|
end
|
|
end
|
|
end
|