FIX: Show a json api response when deleting a user with posts
A 500 error was actually caused with no response when using the api, so it wasn't very clear that you need to delete the posts first when using the api.
This commit is contained in:
parent
186623acd0
commit
bd352a17bf
|
@ -379,7 +379,10 @@ class Admin::UsersController < Admin::AdminController
|
|||
}
|
||||
end
|
||||
rescue UserDestroyer::PostsExistError
|
||||
raise Discourse::InvalidAccess.new("User #{user.username} has #{user.post_count} posts, so can't be deleted.")
|
||||
render json: {
|
||||
deleted: false,
|
||||
message: "User #{user.username} has #{user.post_count} posts, so they can't be deleted."
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -529,9 +529,11 @@ describe Admin::UsersController do
|
|||
_post = create_post(topic: topic, user: delete_me)
|
||||
end
|
||||
|
||||
it "returns an error" do
|
||||
it "returns an api response that the user can't be deleted because it has posts" do
|
||||
delete :destroy, params: { id: delete_me.id }, format: :json
|
||||
expect(response).to be_forbidden
|
||||
expect(response).to be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json['deleted']).to eq(false)
|
||||
end
|
||||
|
||||
it "doesn't return an error if delete_posts == true" do
|
||||
|
|
Loading…
Reference in New Issue