mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Merge pull request #4306 from tgxworld/add_discourse_event_trigger_when_user_logs_out
FEATURE: Add event trigger when a user is logged out.
This commit is contained in:
commit
e4a82cdd85
4 changed files with 19 additions and 4 deletions
|
@ -56,7 +56,7 @@ class Admin::UsersController < Admin::AdminController
|
||||||
@user.save!
|
@user.save!
|
||||||
@user.revoke_api_key
|
@user.revoke_api_key
|
||||||
StaffActionLogger.new(current_user).log_user_suspend(@user, params[:reason])
|
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
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class Admin::UsersController < Admin::AdminController
|
||||||
if @user
|
if @user
|
||||||
@user.auth_token = nil
|
@user.auth_token = nil
|
||||||
@user.save!
|
@user.save!
|
||||||
MessageBus.publish "/logout", @user.id, user_ids: [@user.id]
|
@user.logged_out
|
||||||
render json: success_json
|
render json: success_json
|
||||||
else
|
else
|
||||||
render json: {error: I18n.t('admin_js.admin.users.id_not_found')}, status: 404
|
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?
|
User.where(admin: true).where.not(id: id).where.not(id: Discourse::SYSTEM_USER_ID).blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def logged_out
|
||||||
|
MessageBus.publish "/logout", self.id, user_ids: [self.id]
|
||||||
|
DiscourseEvent.trigger(:user_logged_out, self)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def badge_grant
|
def badge_grant
|
||||||
|
@ -999,7 +1004,6 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
|
|
@ -100,7 +100,7 @@ class Auth::DefaultCurrentUserProvider
|
||||||
cookies["__profilin"] = nil
|
cookies["__profilin"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
MessageBus.publish "/logout", user.id, user_ids: [user.id]
|
user.logged_out
|
||||||
end
|
end
|
||||||
cookies[TOKEN_COOKIE] = nil
|
cookies[TOKEN_COOKIE] = nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1276,4 +1276,15 @@ describe User do
|
||||||
|
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue