FIX: If creating an active user via the API, create reviewables

This commit is contained in:
Robin Ward 2019-04-12 15:25:02 -04:00
parent f7ebfb1acc
commit ef1af53e05
2 changed files with 34 additions and 1 deletions

View File

@ -402,6 +402,9 @@ class UsersController < ApplicationController
session["user_created_message"] = activation.message
session[SessionController::ACTIVATE_USER_KEY] = user.id
# If the user was created as active, they might need to be approved
user.create_reviewable if user.active?
render json: {
success: true,
active: user.active?,

View File

@ -676,7 +676,7 @@ describe UsersController do
let(:admin) { Fabricate(:admin) }
let(:api_key) { Fabricate(:api_key, user: admin) }
it "creates the user as active with a regular key" do
it "creates the user as active with a an admin key" do
SiteSetting.send_welcome_message = true
SiteSetting.must_approve_users = true
@ -699,6 +699,36 @@ describe UsersController do
expect(new_user.approved_at).to_not eq(nil)
end
it "will create a reviewable when a user is created as active but not approved" do
Jobs.run_immediately!
SiteSetting.must_approve_users = true
post "/u.json", params: post_user_params.merge(active: true, api_key: api_key.key)
expect(response.status).to eq(200)
json = JSON.parse(response.body)
new_user = User.find(json["user_id"])
expect(json['active']).to be_truthy
expect(new_user.approved).to eq(false)
expect(ReviewableUser.pending.find_by(target: new_user)).to be_present
end
it "won't create a reviewable when a user is not active" do
Jobs.run_immediately!
SiteSetting.must_approve_users = true
post "/u.json", params: post_user_params.merge(api_key: api_key.key)
expect(response.status).to eq(200)
json = JSON.parse(response.body)
new_user = User.find(json["user_id"])
expect(json['active']).to eq(false)
expect(new_user.approved).to eq(false)
expect(ReviewableUser.pending.find_by(target: new_user)).to be_blank
end
it "won't create the developer as active" do
UsernameCheckerService.expects(:is_developer?).returns(true)