calendar_subscriptions_controller.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.message
  22. logger.error e.backtrace.inspect
  23. render json: { error: e.message }, status: :unprocessable_entity
  24. end
  25. # @path [GET] /calendar_subscriptions/:object
  26. # @path [GET] /calendar_subscriptions/:object/:method
  27. #
  28. # @summary Returns an iCal file of the given object (and method) matching the calendar subscriptions preferences of the current user as events.
  29. #
  30. # @response_message 200 [String] iCal file ready to import in calendar applications.
  31. # @response_message 401 Permission denied.
  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.message
  43. logger.error e.backtrace.inspect
  44. render json: { error: e.message }, status: :unprocessable_entity
  45. end
  46. end