2015-06-25 14:17:57 +00:00
|
|
|
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
|
2015-06-26 12:00:10 +00:00
|
|
|
class CalendarSubscriptionsController < ApplicationController
|
2017-02-15 12:29:25 +00:00
|
|
|
prepend_before_action { authentication_check( { basic_auth_promt: true, permission: 'user_preferences.calendar' } ) }
|
2015-06-25 14:17:57 +00:00
|
|
|
|
2015-06-26 12:00:10 +00:00
|
|
|
# @path [GET] /calendar_subscriptions
|
2015-06-25 14:17:57 +00:00
|
|
|
#
|
2015-06-26 12:00:10 +00:00
|
|
|
# @summary Returns an iCal file with all objects matching the calendar subscriptions preferences of the current user as events.
|
2015-06-25 14:17:57 +00:00
|
|
|
#
|
|
|
|
# @response_message 200 [String] iCal file ready to import in calendar applications.
|
|
|
|
# @response_message 401 Permission denied.
|
|
|
|
def all
|
2016-08-17 11:48:11 +00:00
|
|
|
calendar_subscriptions = CalendarSubscriptions.new(current_user)
|
2015-06-26 12:00:10 +00:00
|
|
|
ical = calendar_subscriptions.all
|
2015-06-25 14:17:57 +00:00
|
|
|
|
|
|
|
send_data(
|
|
|
|
ical,
|
2018-12-19 17:31:51 +00:00
|
|
|
filename: 'zammad.ical',
|
|
|
|
type: 'text/plain',
|
2015-06-25 14:17:57 +00:00
|
|
|
disposition: 'inline'
|
|
|
|
)
|
|
|
|
rescue => e
|
2017-04-19 10:09:54 +00:00
|
|
|
logger.error e
|
2015-06-25 14:17:57 +00:00
|
|
|
render json: { error: e.message }, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
|
2015-06-26 12:00:10 +00:00
|
|
|
# @path [GET] /calendar_subscriptions/:object
|
|
|
|
# @path [GET] /calendar_subscriptions/:object/:method
|
2015-06-25 14:17:57 +00:00
|
|
|
#
|
2015-06-26 12:00:10 +00:00
|
|
|
# @summary Returns an iCal file of the given object (and method) matching the calendar subscriptions preferences of the current user as events.
|
2015-06-25 14:17:57 +00:00
|
|
|
#
|
|
|
|
# @response_message 200 [String] iCal file ready to import in calendar applications.
|
|
|
|
# @response_message 401 Permission denied.
|
|
|
|
def object
|
2016-08-17 11:48:11 +00:00
|
|
|
calendar_subscriptions = CalendarSubscriptions.new(current_user)
|
|
|
|
ical = calendar_subscriptions.generic(params[:object], params[:method])
|
2015-06-25 14:17:57 +00:00
|
|
|
|
|
|
|
send_data(
|
|
|
|
ical,
|
2018-12-19 17:31:51 +00:00
|
|
|
filename: 'zammad.ical',
|
|
|
|
type: 'text/plain',
|
2015-06-25 14:17:57 +00:00
|
|
|
disposition: 'inline'
|
|
|
|
)
|
|
|
|
rescue => e
|
2017-04-19 10:09:54 +00:00
|
|
|
logger.error e
|
2015-06-25 14:17:57 +00:00
|
|
|
render json: { error: e.message }, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|