summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/issues_calendar.rb
diff options
context:
space:
mode:
authorImre Farkas <ifarkas@gitlab.com>2018-06-12 11:35:34 +0200
committerImre Farkas <ifarkas@gitlab.com>2018-06-15 16:03:38 +0200
commita0ac000ad397fb4111d3184d084a9d293eb184c7 (patch)
treeb8ab4b315437cf1aee270ccf83d031cba01cea11 /app/controllers/concerns/issues_calendar.rb
parent1ed954e8a7abd3a8bc1649d0deec6d1ee2149496 (diff)
downloadgitlab-ce-47672-set_inline_content_type_for_ics.tar.gz
Render calendar feed inline when accessed from GitLab47672-set_inline_content_type_for_ics
With text/calendar as Content-Type, the browser always downloads the content as a file (even ignoring the Content-Disposition header). We want to display the content inline when accessed from Gitlab, similarly to the RSS feed.
Diffstat (limited to 'app/controllers/concerns/issues_calendar.rb')
-rw-r--r--app/controllers/concerns/issues_calendar.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/controllers/concerns/issues_calendar.rb b/app/controllers/concerns/issues_calendar.rb
new file mode 100644
index 00000000000..96f6d1865e9
--- /dev/null
+++ b/app/controllers/concerns/issues_calendar.rb
@@ -0,0 +1,24 @@
+module IssuesCalendar
+ extend ActiveSupport::Concern
+
+ # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ def render_issues_calendar(issuables)
+ @issues = issuables
+ .non_archived
+ .with_due_date
+ .limit(100)
+
+ respond_to do |format|
+ format.ics do
+ # NOTE: with text/calendar as Content-Type, the browser always downloads
+ # the content as a file (even ignoring the Content-Disposition
+ # header). We want to display the content inline when accessed
+ # from Gitlab, similarly to the RSS feed.
+ if request.referer&.start_with?(::Settings.gitlab.base_url)
+ response.headers['Content-Type'] = 'text/plain'
+ end
+ end
+ end
+ end
+ # rubocop:enable Gitlab/ModuleWithInstanceVariables
+end