mirror of
https://github.com/discourse/discourse.git
synced 2025-04-03 05:39:41 +08:00
FIX: do not show PM topics when moving posts to an existing public topic (#6876)
This commit is contained in:
parent
78748f1501
commit
a121d40771
@ -32,8 +32,11 @@ export default Ember.Component.extend({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchForTerm(title, { typeFilter: "topic", searchForId: true }).then(
|
searchForTerm(title, {
|
||||||
function(results) {
|
typeFilter: "topic",
|
||||||
|
searchForId: true,
|
||||||
|
restrictToArchetype: "regular"
|
||||||
|
}).then(function(results) {
|
||||||
if (results && results.posts && results.posts.length > 0) {
|
if (results && results.posts && results.posts.length > 0) {
|
||||||
self.set(
|
self.set(
|
||||||
"topics",
|
"topics",
|
||||||
@ -44,8 +47,7 @@ export default Ember.Component.extend({
|
|||||||
} else {
|
} else {
|
||||||
self.setProperties({ topics: null, loading: false });
|
self.setProperties({ topics: null, loading: false });
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}, 300),
|
}, 300),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -107,6 +107,8 @@ export function searchForTerm(term, opts) {
|
|||||||
const data = { term: term, include_blurbs: "true" };
|
const data = { term: term, include_blurbs: "true" };
|
||||||
if (opts.typeFilter) data.type_filter = opts.typeFilter;
|
if (opts.typeFilter) data.type_filter = opts.typeFilter;
|
||||||
if (opts.searchForId) data.search_for_id = true;
|
if (opts.searchForId) data.search_for_id = true;
|
||||||
|
if (opts.restrictToArchetype)
|
||||||
|
data.restrict_to_archetype = opts.restrictToArchetype;
|
||||||
|
|
||||||
if (opts.searchContext) {
|
if (opts.searchContext) {
|
||||||
data.search_context = {
|
data.search_context = {
|
||||||
|
@ -68,6 +68,7 @@ class SearchController < ApplicationController
|
|||||||
search_args[:search_type] = :header
|
search_args[:search_type] = :header
|
||||||
search_args[:ip_address] = request.remote_ip
|
search_args[:ip_address] = request.remote_ip
|
||||||
search_args[:user_id] = current_user.id if current_user.present?
|
search_args[:user_id] = current_user.id if current_user.present?
|
||||||
|
search_args[:restrict_to_archetype] = params[:restrict_to_archetype] if params[:restrict_to_archetype].present?
|
||||||
|
|
||||||
search = Search.new(params[:term], search_args)
|
search = Search.new(params[:term], search_args)
|
||||||
result = search.execute
|
result = search.execute
|
||||||
|
@ -227,7 +227,7 @@ class Search
|
|||||||
end
|
end
|
||||||
|
|
||||||
# If the term is a number or url to a topic, just include that topic
|
# If the term is a number or url to a topic, just include that topic
|
||||||
if @opts[:search_for_id] && @results.type_filter == 'topic'
|
if @opts[:search_for_id] && (@results.type_filter == 'topic' || @results.type_filter == 'private_messages')
|
||||||
if @term =~ /^\d+$/
|
if @term =~ /^\d+$/
|
||||||
single_topic(@term.to_i)
|
single_topic(@term.to_i)
|
||||||
else
|
else
|
||||||
@ -629,7 +629,14 @@ class Search
|
|||||||
|
|
||||||
# If we're searching for a single topic
|
# If we're searching for a single topic
|
||||||
def single_topic(id)
|
def single_topic(id)
|
||||||
|
if @opts[:restrict_to_archetype].present?
|
||||||
|
archetype = @opts[:restrict_to_archetype] == Archetype.default ? Archetype.default : Archetype.private_message
|
||||||
|
post = Post.joins(:topic)
|
||||||
|
.where("topics.id = :id AND topics.archetype = :archetype AND posts.post_number = 1", id: id, archetype: archetype)
|
||||||
|
.first
|
||||||
|
else
|
||||||
post = Post.find_by(topic_id: id, post_number: 1)
|
post = Post.find_by(topic_id: id, post_number: 1)
|
||||||
|
end
|
||||||
return nil unless @guardian.can_see?(post)
|
return nil unless @guardian.can_see?(post)
|
||||||
|
|
||||||
@results.add(post)
|
@results.add(post)
|
||||||
|
@ -341,12 +341,32 @@ describe Search do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "search for a topic by url" do
|
context "search for a topic by url" do
|
||||||
let(:result) { Search.execute(topic.relative_url, search_for_id: true, type_filter: 'topic') }
|
|
||||||
|
|
||||||
it 'returns the topic' do
|
it 'returns the topic' do
|
||||||
|
result = Search.execute(topic.relative_url, search_for_id: true, type_filter: 'topic')
|
||||||
expect(result.posts.length).to eq(1)
|
expect(result.posts.length).to eq(1)
|
||||||
expect(result.posts.first.id).to eq(post.id)
|
expect(result.posts.first.id).to eq(post.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'restrict_to_archetype' do
|
||||||
|
let(:personal_message) { Fabricate(:private_message_topic) }
|
||||||
|
let!(:p1) { Fabricate(:post, topic: personal_message, post_number: 1) }
|
||||||
|
|
||||||
|
it 'restricts result to topics' do
|
||||||
|
result = Search.execute(personal_message.relative_url, search_for_id: true, type_filter: 'topic', restrict_to_archetype: Archetype.default)
|
||||||
|
expect(result.posts.length).to eq(0)
|
||||||
|
|
||||||
|
result = Search.execute(topic.relative_url, search_for_id: true, type_filter: 'topic', restrict_to_archetype: Archetype.default)
|
||||||
|
expect(result.posts.length).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'restricts result to messages' do
|
||||||
|
result = Search.execute(topic.relative_url, search_for_id: true, type_filter: 'private_messages', guardian: Guardian.new(Fabricate(:admin)), restrict_to_archetype: Archetype.private_message)
|
||||||
|
expect(result.posts.length).to eq(0)
|
||||||
|
|
||||||
|
result = Search.execute(personal_message.relative_url, search_for_id: true, type_filter: 'private_messages', guardian: Guardian.new(Fabricate(:admin)), restrict_to_archetype: Archetype.private_message)
|
||||||
|
expect(result.posts.length).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'security' do
|
context 'security' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user