user_info.rb 595 B

123456789101112131415161718192021222324252627
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module UserInfo
  3. def self.current_user_id
  4. Thread.current[:user_id]
  5. end
  6. def self.current_user_id=(user_id)
  7. Thread.current[:user_id] = user_id
  8. Thread.current[:assets] = UserInfo::Assets.new(user_id)
  9. end
  10. def self.assets
  11. Thread.current[:assets]
  12. end
  13. def self.ensure_current_user_id
  14. if UserInfo.current_user_id.nil?
  15. UserInfo.current_user_id = 1
  16. reset_current_user_id = true
  17. end
  18. yield
  19. ensure
  20. UserInfo.current_user_id = nil if reset_current_user_id
  21. end
  22. end