FIX: User's topic lists weren't consistent WRT visibility

This commit is contained in:
Robin Ward 2015-03-23 18:12:37 -04:00
parent 6930c8919e
commit ff3e1e1dd7
3 changed files with 21 additions and 13 deletions

View File

@ -256,12 +256,7 @@ const User = Discourse.Model.extend({
ua.action_type === Discourse.UserAction.TYPES.topics;
},
/**
The user's stat count, excluding PMs.
@property statsCountNonPM
@type {Integer}
**/
// The user's stat count, excluding PMs.
statsCountNonPM: function() {
var self = this;
@ -275,12 +270,7 @@ const User = Discourse.Model.extend({
return count;
}.property('statsExcludingPms.@each.count'),
/**
The user's stats, excluding PMs.
@property statsExcludingPms
@type {Array}
**/
// The user's stats, excluding PMs.
statsExcludingPms: function() {
if (this.blank('stats')) return [];
return this.get('stats').rejectProperty('isPM');

View File

@ -105,6 +105,7 @@ class TopicQuery
end
def list_topics_by(user)
@options[:filtered_to_user] = user.id
create_list(:user_topics) do |topics|
topics.where(user_id: user.id)
end
@ -281,6 +282,10 @@ class TopicQuery
options.reverse_merge!(@options)
options.reverse_merge!(per_page: per_page_setting)
# Whether to return visible topics
options[:visible] = true if @user.nil? || @user.regular?
options[:visible] = false if @user && @user.id == options[:filtered_to_user]
# Start with a list of all topics
result = Topic.unscoped
@ -310,7 +315,8 @@ class TopicQuery
end
result = result.limit(options[:per_page]) unless options[:limit] == false
result = result.visible if options[:visible] || @user.nil? || @user.regular?
result = result.visible if options[:visible]
result = result.where.not(topics: {id: options[:except_topic_ids]}).references(:topics) if options[:except_topic_ids]
result = result.offset(options[:page].to_i * options[:per_page]) if options[:page]

View File

@ -40,6 +40,18 @@ describe TopicQuery do
end
context "list_topics_by" do
it "allows users to view their own invisible topics" do
topic = Fabricate(:topic, user: user)
invisible_topic = Fabricate(:topic, user: user, visible: false)
expect(TopicQuery.new(nil).list_topics_by(user).topics.count).to eq(1)
expect(TopicQuery.new(user).list_topics_by(user).topics.count).to eq(2)
end
end
context 'bookmarks' do
it "filters and returns bookmarks correctly" do
post = Fabricate(:post)