Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX: Make shared drafts behaviour consistent for non-staff users #6734

Merged
merged 1 commit into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions lib/topic_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,20 +554,17 @@ def private_messages_for(user, type)
def apply_shared_drafts(result, category_id, options)
drafts_category_id = SiteSetting.shared_drafts_category.to_i
viewing_shared = category_id && category_id == drafts_category_id

if guardian.can_create_shared_draft?
if 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)
return result.where(id: topic_ids)
elsif viewing_shared
result = result.includes(:shared_draft).references(:shared_draft)
else
return result.where('topics.category_id != ?', drafts_category_id)
end
can_create_shared = guardian.can_create_shared_draft?

if can_create_shared && 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)
result.where(id: topic_ids)
elsif can_create_shared && viewing_shared
result.includes(:shared_draft).references(:shared_draft)
else
result.where('topics.category_id != ?', drafts_category_id)
end

result
end

def apply_ordering(result, options)
Expand Down
11 changes: 11 additions & 0 deletions spec/components/topic_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,17 @@ def clear_cache!
list = TopicQuery.new(moderator).list_latest
expect(list.topics).not_to include(topic)
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