FIX: Correctly toggle bulk select checkboxes for regular users (#29984)

Non-admin/moderator users can bulk select items in new/unread, but not in
latest/top/hot. This commit ensures that when the user can no longer
bulk select items in a list, the bulk select checkboxes in the topic list
rows are hidden.
This commit is contained in:
Penar Musaraj 2024-11-28 09:39:17 -05:00 committed by GitHub
parent 88f1b3b195
commit cd4de88e4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View File

@ -72,7 +72,9 @@ export default class TopicList extends Component.extend(LoadMore) {
// for the classNameBindings
@dependentKeyCompat
get bulkSelectEnabled() {
return this.bulkSelectHelper?.bulkSelectEnabled;
return (
this.get("canBulkSelect") && this.bulkSelectHelper?.bulkSelectEnabled
);
}
get toggleInTitle() {

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
describe "Topic list focus", type: :system do
describe "Discovery list", type: :system do
fab!(:topics) { Fabricate.times(10, :post).map(&:topic) }
fab!(:reply) { Fabricate(:post, topic: topics.first) }
@ -38,4 +38,27 @@ describe "Topic list focus", type: :system do
expect(page).to have_css("th[data-sort-order='posts'][aria-sort=ascending]")
expect(nth_topic_id(10)).to eq(reply.topic_id.to_s)
end
describe "bulk topic options" do
fab!(:user)
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post1) { create_post(user: user, topic: topic) }
fab!(:post2) { create_post(topic: topic) }
it "should correctly show/hide the bulk select toggle for regular users" do
sign_in(user)
visit("/unread")
# The bulk select toggle should be visible, the user has an unread post
find("button.bulk-select").click
expect(page).to have_css(".topic-list-body .bulk-select")
find("#navigation-bar .latest > a").click
# No bulk select toggle or checkboxes
# this action is not available for this user in /latest
expect(page).to have_no_css(".topic-list-body .bulk-select")
expect(page).to have_no_css("button.bulk-select")
end
end
end