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

View File

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

View File

@ -13,6 +13,7 @@ class TopicsBulkAction
@operations ||= %w[ @operations ||= %w[
change_category change_category
close close
silent_close
archive archive
change_notification_level change_notification_level
destroy_post_timing destroy_post_timing
@ -170,6 +171,15 @@ class TopicsBulkAction
end end
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 def unlist
topics.each do |t| topics.each do |t|
if guardian.can_moderate?(t) if guardian.can_moderate?(t)

View File

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

View File

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

View File

@ -210,6 +210,19 @@ module PageObjects
@private_message_map_component.is_visible? @private_message_map_component.is_visible?
end 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 private
def topic_footer_button_id(button) 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) } fab!(:topics) { Fabricate.times(10, :post).map(&:topic) }
let(:topic_list_header) { PageObjects::Components::TopicListHeader.new } let(:topic_list_header) { PageObjects::Components::TopicListHeader.new }
let(:topic_list) { PageObjects::Components::TopicList.new } let(:topic_list) { PageObjects::Components::TopicList.new }
let(:topic_page) { PageObjects::Pages::Topic.new }
context "when in topic" do context "when in topic" do
fab!(:admin) fab!(:admin)
fab!(:user)
before { sign_in(admin) }
it "closes multiple topics" do it "closes multiple topics" do
sign_in(admin)
visit("/latest") visit("/latest")
expect(page).to have_css(".topic-list button.bulk-select") expect(page).to have_css(".topic-list button.bulk-select")
expect(topic_list_header).to have_bulk_select_button 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 topic_list_header.click_bulk_topics_confirm
expect(topic_list).to have_closed_status(topics.first) expect(topic_list).to have_closed_status(topics.first)
end 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
end end