calendar_subscriptions_controller.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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, permission: 'user_preferences.calendar' } ) }
  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 401 Permission denied.
  10. def all
  11. calendar_subscriptions = CalendarSubscriptions.new(current_user)
  12. ical = calendar_subscriptions.all
  13. send_data(
  14. ical,
  15. filename: 'zammad.ical',
  16. type: 'text/plain',
  17. disposition: 'inline'
  18. )
  19. rescue => e
  20. logger.error e
  21. render json: { error: e.message }, status: :unprocessable_entity
  22. end
  23. # @path [GET] /calendar_subscriptions/:object
  24. # @path [GET] /calendar_subscriptions/:object/:method
  25. #
  26. # @summary Returns an iCal file of the given object (and method) matching the calendar subscriptions preferences of the current user as events.
  27. #
  28. # @response_message 200 [String] iCal file ready to import in calendar applications.
  29. # @response_message 401 Permission denied.
  30. def object
  31. calendar_subscriptions = CalendarSubscriptions.new(current_user)
  32. ical = calendar_subscriptions.generic(params[:object], params[:method])
  33. send_data(
  34. ical,
  35. filename: 'zammad.ical',
  36. type: 'text/plain',
  37. disposition: 'inline'
  38. )
  39. rescue => e
  40. logger.error e
  41. render json: { error: e.message }, status: :unprocessable_entity
  42. end
  43. end