mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 04:34:32 +08:00
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:
parent
e01f75cb32
commit
0464ddcd9b
|
@ -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}}
|
||||
|
|
|
@ -181,7 +181,7 @@ export default class Topic extends RestModel {
|
|||
};
|
||||
|
||||
if (options) {
|
||||
if (options.select) {
|
||||
if (options.silent) {
|
||||
data.silent = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user