FEATURE: Bulk Silent Close Topics (#26043)

Using the new bulk select dropdown you can now choose to bulk close
topics silently.
This commit is contained in:
Blake Erickson 2024-03-06 14:08:49 -07:00 committed by GitHub
parent e01f75cb32
commit 0464ddcd9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 99 additions and 8 deletions

View File

@ -1,5 +1,6 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { Input } from "@ember/component";
import { action, computed } from "@ember/object";
import { service } from "@ember/service";
import { Promise } from "rsvp";
@ -23,6 +24,7 @@ export default class BulkTopicActions extends Component {
@tracked categoryId;
@tracked loading;
@tracked errors;
@tracked isSilent = false;
notificationLevelId = null;
@ -69,8 +71,8 @@ export default class BulkTopicActions extends Component {
const topicIds = [];
const options = {};
if (this.args.model.allowSilent === true) {
options.silent = true;
if (this.isSilent) {
operation = { type: "silent_close" };
}
const tasks = topicChunks.map((topics) => async () => {
@ -300,10 +302,10 @@ export default class BulkTopicActions extends Component {
for="topic-bulk-action-options__silent"
class="checkbox-label"
>
<input
class=""
<Input
id="topic-bulk-action-options__silent"
type="checkbox"
@type="checkbox"
@checked={{this.isSilent}}
/>{{i18n "topics.bulk.silent"}}</label>
</div>
{{/if}}

View File

@ -181,7 +181,7 @@ export default class Topic extends RestModel {
};
if (options) {
if (options.select) {
if (options.silent) {
data.silent = true;
}
}

View File

@ -13,6 +13,7 @@ class TopicsBulkAction
@operations ||= %w[
change_category
close
silent_close
archive
change_notification_level
destroy_post_timing
@ -170,6 +171,15 @@ class TopicsBulkAction
end
end
def silent_close
topics.each do |t|
if guardian.can_moderate?(t)
t.update_status("autoclosed", true, @user)
@changed_ids << t.id
end
end
end
def unlist
topics.each do |t|
if guardian.can_moderate?(t)

View File

@ -38,6 +38,14 @@ module PageObjects
page.has_css?("#{topic_list_item_closed(topic)}")
end
def has_unread_badge?(topic)
page.has_css?("#{topic_list_item_unread_badge(topic)}")
end
def has_no_unread_badge?(topic)
page.has_no_css?("#{topic_list_item_unread_badge(topic)}")
end
def click_topic_checkbox(topic)
find("#{topic_list_item_class(topic)} input#bulk-select-#{topic.id}").click
end
@ -68,6 +76,10 @@ module PageObjects
def topic_list_item_closed(topic)
"#{topic_list_item_class(topic)} .topic-statuses .topic-status svg.locked"
end
def topic_list_item_unread_badge(topic)
"#{topic_list_item_class(topic)} .topic-post-badges .unread-posts"
end
end
end
end

View File

@ -46,6 +46,10 @@ module PageObjects
find("#bulk-topics-confirm").click
end
def click_silent
find("#topic-bulk-action-options__silent").click
end
private
def bulk_select_dropdown_item(name)

View File

@ -210,6 +210,19 @@ module PageObjects
@private_message_map_component.is_visible?
end
def click_notifications_button
find(".topic-notifications-button .select-kit-header").click
end
def watch_topic
click_notifications_button
find('li[data-name="watching"]').click
end
def has_read_post?(post)
post_by_number(post).has_css?(".read-state.read", visible: :all, wait: 3)
end
private
def topic_footer_button_id(button)

View File

@ -5,13 +5,14 @@ describe "Topic bulk select", type: :system do
fab!(:topics) { Fabricate.times(10, :post).map(&:topic) }
let(:topic_list_header) { PageObjects::Components::TopicListHeader.new }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:topic_page) { PageObjects::Pages::Topic.new }
context "when in topic" do
fab!(:admin)
before { sign_in(admin) }
fab!(:user)
it "closes multiple topics" do
sign_in(admin)
visit("/latest")
expect(page).to have_css(".topic-list button.bulk-select")
expect(topic_list_header).to have_bulk_select_button
@ -37,5 +38,54 @@ describe "Topic bulk select", type: :system do
topic_list_header.click_bulk_topics_confirm
expect(topic_list).to have_closed_status(topics.first)
end
it "closes topics normally" do
# Watch the topic as a user
sign_in(user)
visit("/latest")
topic = topics.third
visit("/t/#{topic.slug}/#{topic.id}")
topic_page.watch_topic
expect(topic_page).to have_read_post(1)
# Bulk close the topic as an admin
sign_in(admin)
visit("/latest")
topic_list_header.click_bulk_select_button
topic_list.click_topic_checkbox(topics.third)
topic_list_header.click_bulk_select_topics_dropdown
topic_list_header.click_close_topics_button
topic_list_header.click_bulk_topics_confirm
# Check that the user did receive a new post notification badge
sign_in(user)
visit("/latest")
expect(topic_list).to have_unread_badge(topics.third)
end
it "closes topics silently" do
# Watch the topic as a user
sign_in(user)
visit("/latest")
topic = topics.first
visit("/t/#{topic.slug}/#{topic.id}")
topic_page.watch_topic
expect(topic_page).to have_read_post(1)
# Bulk close the topic as an admin
sign_in(admin)
visit("/latest")
topic_list_header.click_bulk_select_button
topic_list.click_topic_checkbox(topics.first)
topic_list_header.click_bulk_select_topics_dropdown
topic_list_header.click_close_topics_button
topic_list_header.click_silent # Check Silent
topic_list_header.click_bulk_topics_confirm
# Check that the user didn't receive a new post notification badge
sign_in(user)
visit("/latest")
expect(topic_list).to have_no_unread_badge(topics.first)
end
end
end