mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
FIX: If creating an active user via the API, create reviewables
This commit is contained in:
parent
f7ebfb1acc
commit
ef1af53e05
@ -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?,
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user