mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: Add event trigger when a user is logged out.
This commit is contained in:
parent
0ffe8402a9
commit
22ade1f811
4 changed files with 19 additions and 4 deletions
|
@ -56,7 +56,7 @@ class Admin::UsersController < Admin::AdminController
|
|||
@user.save!
|
||||
@user.revoke_api_key
|
||||
StaffActionLogger.new(current_user).log_user_suspend(@user, params[:reason])
|
||||
MessageBus.publish "/logout", @user.id, user_ids: [@user.id]
|
||||
@user.logged_out
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
|
@ -73,7 +73,7 @@ class Admin::UsersController < Admin::AdminController
|
|||
if @user
|
||||
@user.auth_token = nil
|
||||
@user.save!
|
||||
MessageBus.publish "/logout", @user.id, user_ids: [@user.id]
|
||||
@user.logged_out
|
||||
render json: success_json
|
||||
else
|
||||
render json: {error: I18n.t('admin_js.admin.users.id_not_found')}, status: 404
|
||||
|
|
|
@ -854,6 +854,11 @@ class User < ActiveRecord::Base
|
|||
User.where(admin: true).where.not(id: id).where.not(id: Discourse::SYSTEM_USER_ID).blank?
|
||||
end
|
||||
|
||||
def logged_out
|
||||
MessageBus.publish "/logout", self.id, user_ids: [self.id]
|
||||
DiscourseEvent.trigger(:user_logged_out, self)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def badge_grant
|
||||
|
@ -999,7 +1004,6 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -100,7 +100,7 @@ class Auth::DefaultCurrentUserProvider
|
|||
cookies["__profilin"] = nil
|
||||
end
|
||||
|
||||
MessageBus.publish "/logout", user.id, user_ids: [user.id]
|
||||
user.logged_out
|
||||
end
|
||||
cookies[TOKEN_COOKIE] = nil
|
||||
end
|
||||
|
|
|
@ -1270,4 +1270,15 @@ describe User do
|
|||
|
||||
end
|
||||
|
||||
describe "#logged_out" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it 'should publish the right message' do
|
||||
message = MessageBus.track_publish { user.logged_out }.first
|
||||
|
||||
expect(message.channel).to eq('/logout')
|
||||
expect(message.data).to eq(user.id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue