calendar_subscriptions_controller.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class CalendarSubscriptionsController < ApplicationController
  3. prepend_before_action { authentication_check(basic_auth_prompt: true) && authorize! }
  4. # @path [GET] /calendar_subscriptions
  5. #
  6. # @summary Returns an iCal file with all objects matching the calendar subscriptions preferences of the current user as events.
  7. #
  8. # @response_message 200 [String] iCal file ready to import in calendar applications.
  9. # @response_message 403 Forbidden / Invalid session.
  10. # @response_message 422 Unprocessable Entity.
  11. def all
  12. calendar_subscriptions = CalendarSubscriptions.new(current_user)
  13. ical = calendar_subscriptions.all
  14. send_data(
  15. ical,
  16. filename: 'zammad.ical',
  17. type: 'text/plain',
  18. disposition: 'inline'
  19. )
  20. rescue => e
  21. logger.error e
  22. render json: { error: e.message }, status: :unprocessable_entity
  23. end
  24. # @path [GET] /calendar_subscriptions/:object
  25. # @path [GET] /calendar_subscriptions/:object/:method
  26. #
  27. # @summary Returns an iCal file of the given object (and method) matching the calendar subscriptions preferences of the current user as events.
  28. #
  29. # @response_message 200 [String] iCal file ready to import in calendar applications.
  30. # @response_message 403 Forbidden / Invalid session.
  31. # @response_message 422 Unprocessable Entity.
  32. def object
  33. calendar_subscriptions = CalendarSubscriptions.new(current_user)
  34. ical = calendar_subscriptions.generic(params[:object], params[:method].presence || 'all')
  35. send_data(
  36. ical,
  37. filename: 'zammad.ical',
  38. type: 'text/plain',
  39. disposition: 'inline'
  40. )
  41. rescue => e
  42. logger.error e
  43. render json: { error: e.message }, status: :unprocessable_entity
  44. end
  45. end