Skip to content

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

FEATURE: Users can feature any public topic on his/her profile (#8809)

Mark VanLandinghame29fef9e9937
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 9b183a67a4e..39c89b5f79b 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,18 +3,12 @@ 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 8417e7e74c5..82331a0ea3c 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=additionalFilters
+ additionalFilters="status:public"
label="user.feature_topic_on_profile.search_label"
topicChangedCallback=(action "newTopicSelected")
loadOnInit=true
diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rb
index 667888e29c0..6b28d5d8f3f 100644
--- a/lib/guardian/user_guardian.rb
+++ b/lib/guardian/user_guardian.rb
@@ -128,6 +128,6 @@ module UserGuardian
return false if !SiteSetting.allow_featured_topic_on_user_profiles?
return false if !is_me?(user) && !is_staff?
return false if topic.read_restricted_category? || topic.private_message?
- topic.user_id === user.id
+ true
end
end
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index 7d087cd6429..7e487b649e2 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -3895,6 +3895,7 @@ describe UsersController do
describe '#feature_topic' do
fab!(:topic) { Fabricate(:topic) }
+ fab!(:other_topic) { Fabricate(:topic) }
fab!(:other_user) { Fabricate(:user) }
fab!(:private_message) { Fabricate(:private_message_topic, user: other_user) }
fab!(:category) { Fabricate(:category_with_definition) }
@@ -3909,14 +3910,7 @@ describe UsersController do
expect(response.status).to eq(403)
end
- it 'returns an error if the the current user does not have access' do
- sign_in(user)
- topic.update(user_id: other_user.id)
- put "/u/#{user.username}/feature-topic.json", params: { topic_id: topic.id }
- expect(response.status).to eq(403)
- end
-
- it 'returns an error if the user did not create the topic' do
+ it 'returns an error if the user tries to set for another user' do
sign_in(user)
topic.update(user_id: other_user.id)
put "/u/#{other_user.username}/feature-topic.json", params: { topic_id: topic.id }
@@ -3937,7 +3931,7 @@ describe UsersController do
expect(response.status).to eq(403)
end
- it 'sets the user_profiles featured_topic correctly' do
+ it 'sets featured_topic correctly for user created topic' do
sign_in(user)
topic.update(user_id: user.id)
put "/u/#{user.username}/feature-topic.json", params: { topic_id: topic.id }
@@ -3945,6 +3939,13 @@ describe UsersController do
expect(user.user_profile.featured_topic).to eq topic
end
+ it 'sets featured_topic correctly for non-user-created topic' do
+ sign_in(user)
+ put "/u/#{user.username}/feature-topic.json", params: { topic_id: other_topic.id }
+ expect(response.status).to eq(200)
+ expect(user.user_profile.featured_topic).to eq other_topic
+ end
+
describe "site setting disabled" do
before do
SiteSetting.allow_featured_topic_on_user_profiles = false