From 03bc6f70f9e329e5df44df67e9f73c8e548e788a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 13 Dec 2016 14:37:37 -0500 Subject: [PATCH] Better error messages when embedding fails --- app/assets/stylesheets/embed.css.scss | 20 ++++++++++++++++++-- app/controllers/embed_controller.rb | 10 ++++++++++ app/views/embed/embed_error.html.erb | 25 +++++++++++++++++++++++++ app/views/embed/loading.html.erb | 8 ++++---- config/locales/server.en.yml | 5 +++++ 5 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 app/views/embed/embed_error.html.erb diff --git a/app/assets/stylesheets/embed.css.scss b/app/assets/stylesheets/embed.css.scss index ae15f2cc66e..afb4a40c403 100644 --- a/app/assets/stylesheets/embed.css.scss +++ b/app/assets/stylesheets/embed.css.scss @@ -116,17 +116,33 @@ img.emoji { color: #999; } +.clearfix { + clear: both; +} + + header.discourse { padding-left: 10px; + padding-right: 10px; padding-bottom: 8px; font-size: 1.286em; border-bottom: 3px solid #ddd; - .button { - float:right; + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + + h3 { + margin: 0 auto 0 0; + font-size: 1.0em; } } +.embed-error { + padding: 0 10px; +} + footer { font-size: 1.286em; margin-top: 0.5em; diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb index 3286eaead1b..9407f847f20 100644 --- a/app/controllers/embed_controller.rb +++ b/app/controllers/embed_controller.rb @@ -6,6 +6,16 @@ class EmbedController < ApplicationController layout 'embed' + rescue_from Discourse::InvalidAccess do + response.headers['X-Frame-Options'] = "ALLOWALL" + if current_user.try(:admin?) + @setup_url = "#{Discourse.base_url}/admin/customize/embedding" + @show_reason = true + @hosts = EmbeddableHost.all + end + render 'embed_error' + end + def comments embed_url = params[:embed_url] embed_username = params[:discourse_username] diff --git a/app/views/embed/embed_error.html.erb b/app/views/embed/embed_error.html.erb new file mode 100644 index 00000000000..65f4c3c43df --- /dev/null +++ b/app/views/embed/embed_error.html.erb @@ -0,0 +1,25 @@ +
+

<%= t 'embed.error' %>

+ <%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url) %> +
+
+<%- if @show_reason %> +
+ <%- if @hosts.present? %> +

<%= t 'embed.referer' %><%= request.referer %>

+

<%= t 'embed.mismatch' %>

+ + + <%- else %> +

<%= t 'embed.no_hosts' %>

+ <%- end %> + +

<%= link_to(t('embed.configure'), @setup_url, target: '_blank') %>

+
+<%- end %> diff --git a/app/views/embed/loading.html.erb b/app/views/embed/loading.html.erb index e4c6ccd5d98..2a5621de827 100644 --- a/app/views/embed/loading.html.erb +++ b/app/views/embed/loading.html.erb @@ -1,12 +1,12 @@ -
- <%= t 'embed.loading' %> +
+

<%= t 'embed.loading' %>

<%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url) %> +
- \ No newline at end of file + diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 81580737a2f..2260ce3ab94 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -158,6 +158,11 @@ en: embed: start_discussion: "Start Discussion" continue: "Continue Discussion" + error: "Error Embedding" + referer: "Referer:" + mismatch: "The referer did not match any of the following hosts:" + no_hosts: "No hosts were set up for embedding." + configure: "Configure Embedding" more_replies: one: "1 more reply" other: "%{count} more replies"