calendar_subscriptions_controller.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
  2. require 'icalendar'
  3. class CalendarSubscriptionsController < ApplicationController
  4. prepend_before_action { authentication_check( { basic_auth_promt: true, permission: 'user_preferences.calendar' } ) }
  5. # @path [GET] /calendar_subscriptions
  6. #
  7. # @summary Returns an iCal file with all objects matching the calendar subscriptions preferences of the current user as events.
  8. #
  9. # @response_message 200 [String] iCal file ready to import in calendar applications.
  10. # @response_message 401 Permission denied.
  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 401 Permission denied.
  31. def object
  32. calendar_subscriptions = CalendarSubscriptions.new(current_user)
  33. ical = calendar_subscriptions.generic(params[:object], params[:method])
  34. send_data(
  35. ical,
  36. filename: 'zammad.ical',
  37. type: 'text/plain',
  38. disposition: 'inline'
  39. )
  40. rescue => e
  41. logger.error e
  42. render json: { error: e.message }, status: :unprocessable_entity
  43. end
  44. end