calendar_subscriptions_controller.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
  2. class CalendarSubscriptionsController < ApplicationController
  3. prepend_before_action { authentication_check(basic_auth_promt: 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])
  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