mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Have log_out method return json.
This commit helps improve the discourse_api experience so that we can check the json response if it was a success or not. This commit also checks that a 404 is sent instead of a 500 if a bad user_id is passed in.
This commit is contained in:
parent
a85a3da167
commit
bdc92eec70
3 changed files with 32 additions and 4 deletions
|
@ -66,10 +66,14 @@ class Admin::UsersController < Admin::AdminController
|
|||
end
|
||||
|
||||
def log_out
|
||||
if @user
|
||||
@user.auth_token = nil
|
||||
@user.save!
|
||||
MessageBus.publish "/logout", @user.id, user_ids: [@user.id]
|
||||
render nothing: true
|
||||
render json: success_json
|
||||
else
|
||||
render json: {error: I18n.t('admin_js.admin.users.id_not_found')}, status: 404
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_browsers
|
||||
|
|
|
@ -1887,6 +1887,7 @@ en:
|
|||
create: 'Add Admin User'
|
||||
last_emailed: "Last Emailed"
|
||||
not_found: "Sorry, that username doesn't exist in our system."
|
||||
id_not_found: "Sorry, that user id doesn't exist in our system."
|
||||
active: "Active"
|
||||
show_emails: "Show Emails"
|
||||
nav:
|
||||
|
|
|
@ -360,6 +360,29 @@ describe Admin::UsersController do
|
|||
end
|
||||
end
|
||||
|
||||
context 'log_out' do
|
||||
before do
|
||||
@reg_user = Fabricate(:user)
|
||||
end
|
||||
|
||||
it 'returns JSON' do
|
||||
xhr :put, :log_out, user_id: @reg_user.id
|
||||
::JSON.parse(response.body).should be_present
|
||||
end
|
||||
|
||||
it "returns success" do
|
||||
xhr :put, :log_out, user_id: @reg_user.id
|
||||
response.should be_success
|
||||
json = ::JSON.parse(response.body)
|
||||
json['success'].should == "OK"
|
||||
end
|
||||
|
||||
it "returns 404 when user_id does not exist" do
|
||||
xhr :put, :log_out, user_id: 123123
|
||||
response.should_not be_success
|
||||
end
|
||||
end
|
||||
|
||||
context 'block' do
|
||||
before do
|
||||
@reg_user = Fabricate(:user)
|
||||
|
|
Loading…
Reference in a new issue