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

This commit is contained in:
Mark VanLandingham 2020-01-29 10:10:23 -06:00 committed by GitHub
parent de2e857de6
commit e29fef9e99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 17 deletions

View File

@ -3,18 +3,12 @@ import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import { none } from "@ember/object/computed"; import { none } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators";
export default Controller.extend(ModalFunctionality, { export default Controller.extend(ModalFunctionality, {
newFeaturedTopic: null, newFeaturedTopic: null,
saving: false, saving: false,
noTopicSelected: none("newFeaturedTopic"), noTopicSelected: none("newFeaturedTopic"),
@discourseComputed("model")
additionalFilters(model) {
return `status:public created:@${model.username}`;
},
onClose() { onClose() {
this.set("newFeaturedTopic", null); this.set("newFeaturedTopic", null);
}, },

View File

@ -1,7 +1,7 @@
{{#d-modal-body class="feature-topic-on-profile" id='choosing-topic'}} {{#d-modal-body class="feature-topic-on-profile" id='choosing-topic'}}
{{choose-topic currentTopicId=model.featured_topic.id {{choose-topic currentTopicId=model.featured_topic.id
selectedTopicId=newFeaturedTopicId selectedTopicId=newFeaturedTopicId
additionalFilters=additionalFilters additionalFilters="status:public"
label="user.feature_topic_on_profile.search_label" label="user.feature_topic_on_profile.search_label"
topicChangedCallback=(action "newTopicSelected") topicChangedCallback=(action "newTopicSelected")
loadOnInit=true loadOnInit=true

View File

@ -128,6 +128,6 @@ module UserGuardian
return false if !SiteSetting.allow_featured_topic_on_user_profiles? return false if !SiteSetting.allow_featured_topic_on_user_profiles?
return false if !is_me?(user) && !is_staff? return false if !is_me?(user) && !is_staff?
return false if topic.read_restricted_category? || topic.private_message? return false if topic.read_restricted_category? || topic.private_message?
topic.user_id === user.id true
end end
end end

View File

@ -3895,6 +3895,7 @@ describe UsersController do
describe '#feature_topic' do describe '#feature_topic' do
fab!(:topic) { Fabricate(:topic) } fab!(:topic) { Fabricate(:topic) }
fab!(:other_topic) { Fabricate(:topic) }
fab!(:other_user) { Fabricate(:user) } fab!(:other_user) { Fabricate(:user) }
fab!(:private_message) { Fabricate(:private_message_topic, user: other_user) } fab!(:private_message) { Fabricate(:private_message_topic, user: other_user) }
fab!(:category) { Fabricate(:category_with_definition) } fab!(:category) { Fabricate(:category_with_definition) }
@ -3909,14 +3910,7 @@ describe UsersController do
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
it 'returns an error if the the current user does not have access' 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/#{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
sign_in(user) sign_in(user)
topic.update(user_id: other_user.id) topic.update(user_id: other_user.id)
put "/u/#{other_user.username}/feature-topic.json", params: { topic_id: topic.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) expect(response.status).to eq(403)
end end
it 'sets the user_profiles featured_topic correctly' do it 'sets featured_topic correctly for user created topic' do
sign_in(user) sign_in(user)
topic.update(user_id: user.id) topic.update(user_id: user.id)
put "/u/#{user.username}/feature-topic.json", params: { topic_id: topic.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 expect(user.user_profile.featured_topic).to eq topic
end 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 describe "site setting disabled" do
before do before do
SiteSetting.allow_featured_topic_on_user_profiles = false SiteSetting.allow_featured_topic_on_user_profiles = false