mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: If creating an active user via the API, create reviewables
This commit is contained in:
@ -402,6 +402,9 @@ class UsersController < ApplicationController
|
|||||||
session["user_created_message"] = activation.message
|
session["user_created_message"] = activation.message
|
||||||
session[SessionController::ACTIVATE_USER_KEY] = user.id
|
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: {
|
render json: {
|
||||||
success: true,
|
success: true,
|
||||||
active: user.active?,
|
active: user.active?,
|
||||||
|
@ -676,7 +676,7 @@ describe UsersController do
|
|||||||
let(:admin) { Fabricate(:admin) }
|
let(:admin) { Fabricate(:admin) }
|
||||||
let(:api_key) { Fabricate(:api_key, user: 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.send_welcome_message = true
|
||||||
SiteSetting.must_approve_users = true
|
SiteSetting.must_approve_users = true
|
||||||
|
|
||||||
@ -699,6 +699,36 @@ describe UsersController do
|
|||||||
expect(new_user.approved_at).to_not eq(nil)
|
expect(new_user.approved_at).to_not eq(nil)
|
||||||
end
|
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
|
it "won't create the developer as active" do
|
||||||
UsernameCheckerService.expects(:is_developer?).returns(true)
|
UsernameCheckerService.expects(:is_developer?).returns(true)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user