discourse/app/controllers/calendars_controller.rb
Krzysztof Kotlarek cb5b0cb9d8
FEATURE: save local date to calendar (#14486)
It allows saving local date to calendar.
Modal is giving option to pick between ics and google. User choice can be remembered as a default for the next actions.
2021-10-06 14:11:52 +11:00

32 lines
758 B
Ruby

# frozen_string_literal: true
class CalendarsController < ApplicationController
skip_before_action :check_xhr, only: [ :index ], if: :ics_request?
requires_login
def download
@post = Post.find(calendar_params[:post_id])
@title = calendar_params[:title]
@dates = calendar_params[:dates].values
guardian.ensure_can_see!(@post)
respond_to do |format|
format.ics do
filename = "events-#{@title.parameterize}"
response.headers['Content-Disposition'] = "attachment; filename=\"#{filename}.#{request.format.symbol}\""
end
end
end
private
def ics_request?
request.format.symbol == :ics
end
def calendar_params
params.permit(:post_id, :title, dates: [:starts_at, :ends_at])
end
end