mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
UX: Make shared drafts behaviour consistent for non-staff users (#6734)
This makes it easier to diagnose the problem when a public category is set as the 'shared drafts category'. Doing this is not recommended.
This commit is contained in:
parent
ded3639f87
commit
0b1d660876
2 changed files with 20 additions and 12 deletions
|
@ -554,20 +554,17 @@ class TopicQuery
|
||||||
def apply_shared_drafts(result, category_id, options)
|
def apply_shared_drafts(result, category_id, options)
|
||||||
drafts_category_id = SiteSetting.shared_drafts_category.to_i
|
drafts_category_id = SiteSetting.shared_drafts_category.to_i
|
||||||
viewing_shared = category_id && category_id == drafts_category_id
|
viewing_shared = category_id && category_id == drafts_category_id
|
||||||
|
can_create_shared = guardian.can_create_shared_draft?
|
||||||
|
|
||||||
if guardian.can_create_shared_draft?
|
if can_create_shared && options[:destination_category_id]
|
||||||
if options[:destination_category_id]
|
destination_category_id = get_category_id(options[:destination_category_id])
|
||||||
destination_category_id = get_category_id(options[:destination_category_id])
|
topic_ids = SharedDraft.where(category_id: destination_category_id).pluck(:topic_id)
|
||||||
topic_ids = SharedDraft.where(category_id: destination_category_id).pluck(:topic_id)
|
result.where(id: topic_ids)
|
||||||
return result.where(id: topic_ids)
|
elsif can_create_shared && viewing_shared
|
||||||
elsif viewing_shared
|
result.includes(:shared_draft).references(:shared_draft)
|
||||||
result = result.includes(:shared_draft).references(:shared_draft)
|
else
|
||||||
else
|
result.where('topics.category_id != ?', drafts_category_id)
|
||||||
return result.where('topics.category_id != ?', drafts_category_id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_ordering(result, options)
|
def apply_ordering(result, options)
|
||||||
|
|
|
@ -1014,6 +1014,17 @@ describe TopicQuery do
|
||||||
list = TopicQuery.new(moderator).list_latest
|
list = TopicQuery.new(moderator).list_latest
|
||||||
expect(list.topics).not_to include(topic)
|
expect(list.topics).not_to include(topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't include shared draft topics for regular users" do
|
||||||
|
group.add(user)
|
||||||
|
SiteSetting.shared_drafts_category = nil
|
||||||
|
list = TopicQuery.new(user).list_latest
|
||||||
|
expect(list.topics).to include(topic)
|
||||||
|
|
||||||
|
SiteSetting.shared_drafts_category = shared_drafts_category.id
|
||||||
|
list = TopicQuery.new(user).list_latest
|
||||||
|
expect(list.topics).not_to include(topic)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue