From 769223014caed31145c7c900ead8cd754a8facb5 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 29 Nov 2013 14:29:28 -0500 Subject: [PATCH] FIX: Allow link redirects inside oneboxed posts --- app/assets/javascripts/discourse/lib/click_track.js | 5 ++--- app/models/topic_link_click.rb | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/click_track.js b/app/assets/javascripts/discourse/lib/click_track.js index 0628b080e..50611cf53 100644 --- a/app/assets/javascripts/discourse/lib/click_track.js +++ b/app/assets/javascripts/discourse/lib/click_track.js @@ -38,10 +38,9 @@ Discourse.ClickTrack = { userId = $link.data('user-id'); if (!userId) userId = $article.data('user-id'); - var ownLink = userId && (userId === Discourse.User.currentProp('id')); - // Build a Redirect URL - var trackingUrl = Discourse.getURL("/clicks/track?url=" + encodeURIComponent(href)); + var ownLink = userId && (userId === Discourse.User.currentProp('id')), + trackingUrl = Discourse.getURL("/clicks/track?url=" + encodeURIComponent(href)); if (postId && (!$link.data('ignore-post-id'))) { trackingUrl += "&post_id=" + encodeURI(postId); } diff --git a/app/models/topic_link_click.rb b/app/models/topic_link_click.rb index 68a03d883..5fa832a84 100644 --- a/app/models/topic_link_click.rb +++ b/app/models/topic_link_click.rb @@ -22,7 +22,11 @@ class TopicLinkClick < ActiveRecord::Base # If no link is found, return the url for relative links unless link.present? return args[:url] if args[:url] =~ /^\// - return nil + + # If we have it somewhere else on the site, just allow the redirect. This is + # likely due to a onebox of another topic. + link = TopicLink.where(url: args[:url]).first + return link.present? ? link.url : nil end return args[:url] if (args[:user_id] && (link.user_id == args[:user_id]))