event.rb 846 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sessions::Event
  3. include ApplicationLib
  4. def self.run(params)
  5. begin
  6. backend = "Sessions::Event::#{params[:event].to_classname}".constantize
  7. rescue => e
  8. Rails.logger.error e.inspect
  9. Rails.logger.error e.backtrace
  10. return { event: 'error', data: { error: "No such event #{params[:event]}: #{e.inspect}", payload: params[:payload] } }
  11. end
  12. begin
  13. instance = backend.new(params)
  14. result = instance.run
  15. instance.destroy
  16. result
  17. rescue => e
  18. Rails.logger.error e.inspect
  19. Rails.logger.error e.backtrace
  20. { event: 'error', data: { error: e.message, payload: params[:payload] } }
  21. end
  22. ensure
  23. UserInfo.current_user_id = nil
  24. ActiveSupport::CurrentAttributes.clear_all
  25. end
  26. end