mirror of
https://github.com/discourse/discourse.git
synced 2025-06-16 01:33:59 +08:00
FIX: identify slug-less topic urls everywhere
In 91c89df6, I fixed the onebox to support local topics with a slug-less URL. This commit fixes all the other spots (search, topic links and user badges) where we look up for a local topic. Follow-up-to: 91c89df6
This commit is contained in:
@ -65,10 +65,11 @@ class UserBadgesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
if route = Discourse.route_for(params[:reason])
|
if route = Discourse.route_for(params[:reason])
|
||||||
topic_id = route[:topic_id].to_i
|
if route[:controller] == "topics" && route[:action] == "show"
|
||||||
|
topic_id = (route[:id] || route[:topic_id]).to_i
|
||||||
post_number = route[:post_number] || 1
|
post_number = route[:post_number] || 1
|
||||||
|
post_id = Post.find_by(topic_id: topic_id, post_number: post_number)&.id if topic_id > 0
|
||||||
post_id = Post.find_by(topic_id: topic_id, post_number: post_number).try(:id) if topic_id > 0
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -276,20 +276,25 @@ class TopicLink < ActiveRecord::Base
|
|||||||
internal = true
|
internal = true
|
||||||
|
|
||||||
# We aren't interested in tracking internal links to users
|
# We aren't interested in tracking internal links to users
|
||||||
return nil if route[:controller] == 'users'
|
return nil if route[:controller] == "users"
|
||||||
|
|
||||||
topic_id = route[:topic_id].to_i
|
topic_id = route[:topic_id]
|
||||||
|
topic_slug = route[:slug]
|
||||||
post_number = route[:post_number] || 1
|
post_number = route[:post_number] || 1
|
||||||
topic_slug = route[:id]
|
|
||||||
|
|
||||||
# Store the canonical URL
|
if route[:controller] == "topics" && route[:action] == "show"
|
||||||
topic = Topic.find_by(id: topic_id)
|
topic_id ||= route[:id]
|
||||||
topic ||= Topic.find_by(slug: topic_slug) if topic_slug
|
topic_slug ||= route[:id]
|
||||||
topic_id = nil unless topic
|
end
|
||||||
|
|
||||||
|
topic = Topic.find_by(id: topic_id) if topic_id
|
||||||
|
topic ||= Topic.find_by(slug: topic_slug) if topic_slug.present?
|
||||||
|
|
||||||
if topic.present?
|
if topic.present?
|
||||||
url = +"#{Discourse.base_url_no_prefix}#{topic.relative_url}"
|
url = +"#{Discourse.base_url_no_prefix}#{topic.relative_url}"
|
||||||
url << "/#{post_number}" if post_number.to_i > 1
|
url << "/#{post_number}" if post_number.to_i > 1
|
||||||
|
else
|
||||||
|
topic_id = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -314,7 +319,7 @@ class TopicLink < ActiveRecord::Base
|
|||||||
domain: parsed.host,
|
domain: parsed.host,
|
||||||
internal: internal,
|
internal: internal,
|
||||||
link_topic_id: topic&.id,
|
link_topic_id: topic&.id,
|
||||||
link_post_id: reflected_post.try(:id),
|
link_post_id: reflected_post&.id,
|
||||||
quote: link.is_quote,
|
quote: link.is_quote,
|
||||||
extension: file_extension,
|
extension: file_extension,
|
||||||
)
|
)
|
||||||
|
@ -247,8 +247,12 @@ class Search
|
|||||||
single_topic(@term.to_i)
|
single_topic(@term.to_i)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
route = Rails.application.routes.recognize_path(@term)
|
if route = Discourse.route_for(@term)
|
||||||
single_topic(route[:topic_id]) if route[:topic_id].present?
|
if route[:controller] == "topics" && route[:action] == "show"
|
||||||
|
topic_id = (route[:id] || route[:topic_id]).to_i
|
||||||
|
single_topic(topic_id) if topic_id > 0
|
||||||
|
end
|
||||||
|
end
|
||||||
rescue ActionController::RoutingError
|
rescue ActionController::RoutingError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user