Skip to content

A platform for community discussion. Free, open, simple.

FIX: Featuring topic on other users profile shows their topics (#8769)

Mark VanLandinghamc5eec1936875
diff --git a/app/assets/javascripts/discourse/controllers/feature-topic-on-profile.js.es6 b/app/assets/javascripts/discourse/controllers/feature-topic-on-profile.js.es6
index 39c89b5f79b..9b183a67a4e 100644
--- a/app/assets/javascripts/discourse/controllers/feature-topic-on-profile.js.es6
+++ b/app/assets/javascripts/discourse/controllers/feature-topic-on-profile.js.es6
@@ -3,12 +3,18 @@ import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { none } from "@ember/object/computed";
+import discourseComputed from "discourse-common/utils/decorators";
export default Controller.extend(ModalFunctionality, {
newFeaturedTopic: null,
saving: false,
noTopicSelected: none("newFeaturedTopic"),
+ @discourseComputed("model")
+ additionalFilters(model) {
+ return `status:public created:@${model.username}`;
+ },
+
onClose() {
this.set("newFeaturedTopic", null);
},
diff --git a/app/assets/javascripts/discourse/templates/modal/feature-topic-on-profile.hbs b/app/assets/javascripts/discourse/templates/modal/feature-topic-on-profile.hbs
index 751789e66de..8417e7e74c5 100644
--- a/app/assets/javascripts/discourse/templates/modal/feature-topic-on-profile.hbs
+++ b/app/assets/javascripts/discourse/templates/modal/feature-topic-on-profile.hbs
@@ -1,7 +1,7 @@
{{#d-modal-body class="feature-topic-on-profile" id='choosing-topic'}}
{{choose-topic currentTopicId=model.featured_topic.id
selectedTopicId=newFeaturedTopicId
- additionalFilters="in:created status:public"
+ additionalFilters=additionalFilters
label="user.feature_topic_on_profile.search_label"
topicChangedCallback=(action "newTopicSelected")
loadOnInit=true
diff --git a/lib/search.rb b/lib/search.rb
index 32dbd2b6fb0..8492ade669e 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -382,6 +382,11 @@ class Search
posts.where(user_id: @guardian.user.id, post_number: 1) if @guardian.user
end
+ advanced_filter(/^created:@(.*)$/) do |posts, match|
+ user_id = User.where(username: match.downcase).pluck_first(:id)
+ posts.where(user_id: user_id, post_number: 1)
+ end
+
advanced_filter(/^in:(watching|tracking)$/) do |posts, match|
if @guardian.user
level = TopicUser.notification_levels[match.to_sym]
diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb
index e33e71431c5..caa4d98accf 100644
--- a/spec/components/search_spec.rb
+++ b/spec/components/search_spec.rb
@@ -1044,12 +1044,20 @@ describe Search do
expect(Search.execute('test in:posted', guardian: Guardian.new(topic.user)).posts.length).to eq(2)
- expect(Search.execute('test in:created', guardian: Guardian.new(topic.user)).posts.length).to eq(1)
+ in_created = Search.execute('test in:created', guardian: Guardian.new(topic.user)).posts
+ created_by_user = Search.execute("test created:@#{topic.user.username}", guardian: Guardian.new(topic.user)).posts
+ expect(in_created.length).to eq(1)
+ expect(created_by_user.length).to eq(1)
+ expect(in_created).to eq(created_by_user)
+
+ expect(Search.execute("test created:@#{second_topic.user.username}", guardian: Guardian.new(topic.user)).posts.length).to eq(1)
+
+ new_user = Fabricate(:user)
+ expect(Search.execute("test created:@#{new_user.username}", guardian: Guardian.new(topic.user)).posts.length).to eq(0)
TopicUser.change(topic.user.id, topic.id, notification_level: TopicUser.notification_levels[:tracking])
expect(Search.execute('test in:watching', guardian: Guardian.new(topic.user)).posts.length).to eq(0)
expect(Search.execute('test in:tracking', guardian: Guardian.new(topic.user)).posts.length).to eq(1)
-
end
it 'can find posts with images' do