mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 13:09:33 -06:00
cb5b0cb9d8
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.
32 lines
758 B
Ruby
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
|