who_am_i.rb 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class Sessions::Event::WhoAmI < Sessions::Event::Base
  3. database_connection_required
  4. =begin
  5. Event module to send `who am i` to client connection.
  6. To execute this manually, just paste the following into the browser console
  7. App.WebSocket.send({event:'who_am_i'})
  8. =end
  9. def run
  10. if !@session || !@session['id']
  11. return {
  12. event: 'who_am_i',
  13. data: {
  14. message: 'session not authenticated',
  15. },
  16. }
  17. end
  18. user = User.find_by(id: @session['id'])
  19. if !user
  20. return {
  21. event: 'who_am_i',
  22. data: {
  23. message: "No such user with id #{@session['id']}",
  24. },
  25. }
  26. end
  27. attributes = user.attributes
  28. attributes.delete('password')
  29. {
  30. event: 'who_am_i',
  31. data: {
  32. message: 'session authenticated',
  33. user: attributes,
  34. },
  35. }
  36. end
  37. end