ticket_preferences_with_urls.rb 901 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::CalendarSubscription::TicketPreferencesWithUrls < Service::Base
  3. attr_reader :user
  4. def initialize(user)
  5. super()
  6. @user = user
  7. end
  8. def execute
  9. output = {
  10. combined_url: generate_url,
  11. global_options: { alarm: preferences[:alarm] }
  12. }
  13. %i[new_open pending escalation].each_with_object(output) do |elem, memo|
  14. memo[elem] = { options: preferences[elem], url: generate_url(elem) }
  15. end
  16. end
  17. private
  18. def preferences
  19. @preferences ||= Service::User::CalendarSubscription::Preferences
  20. .new(user)
  21. .execute
  22. .fetch(:tickets)
  23. end
  24. def generate_url(suffix = nil)
  25. http_type = Setting.get('http_type')
  26. fqdn = Setting.get('fqdn')
  27. ["#{http_type}://#{fqdn}/ical/tickets", suffix]
  28. .compact
  29. .join('/')
  30. end
  31. end