FEATURE: Add Archive Topics to Bulk actions

Add the ability to archive topics in bulk
https://meta.discourse.org/t/archive-topics-via-bulk/20302
This commit is contained in:
cpradio 2014-09-22 14:56:48 -04:00
parent d97548114f
commit afdbb2bb96
5 changed files with 54 additions and 6 deletions

View File

@ -73,6 +73,12 @@ export default Ember.ArrayController.extend(ModalFunctionality, {
}); });
}, },
archiveTopics: function() {
this.forEachPerformed({type: 'archive'}, function(t) {
t.set('archived', true);
});
},
changeCategory: function() { changeCategory: function() {
var categoryId = parseInt(this.get('newCategoryId'), 10) || 0, var categoryId = parseInt(this.get('newCategoryId'), 10) || 0,
category = Discourse.Category.findById(categoryId), category = Discourse.Category.findById(categoryId),

View File

@ -1,5 +1,10 @@
<button class='btn' {{action showChangeCategory}}>{{i18n topics.bulk.change_category}}</button> <p>
<button class='btn' {{action deleteTopics}}>{{i18n topics.bulk.delete}}</button> <button class='btn' {{action showChangeCategory}}>{{i18n topics.bulk.change_category}}</button>
<button class='btn' {{action closeTopics}}>{{i18n topics.bulk.close_topics}}</button> <button class='btn' {{action deleteTopics}}>{{i18n topics.bulk.delete}}</button>
<button class='btn' {{action showNotificationLevel}}>{{i18n topics.bulk.notification_level}}</button> <button class='btn' {{action closeTopics}}>{{i18n topics.bulk.close_topics}}</button>
<button class='btn' {{action resetRead}}>{{i18n topics.bulk.reset_read}}</button> <button class='btn' {{action archiveTopics}}>{{i18n topics.bulk.archive_topics}}</button>
</p>
<p>
<button class='btn' {{action showNotificationLevel}}>{{i18n topics.bulk.notification_level}}</button>
<button class='btn' {{action resetRead}}>{{i18n topics.bulk.reset_read}}</button>
</p>

View File

@ -771,6 +771,7 @@ en:
actions: "Bulk Actions" actions: "Bulk Actions"
change_category: "Change Category" change_category: "Change Category"
close_topics: "Close Topics" close_topics: "Close Topics"
archive_topics: "Archive Topics"
notification_level: "Change Notification Level" notification_level: "Change Notification Level"
selected: selected:
one: "You have selected <b>1</b> topic." one: "You have selected <b>1</b> topic."

View File

@ -8,7 +8,7 @@ class TopicsBulkAction
end end
def self.operations def self.operations
%w(change_category close change_notification_level reset_read dismiss_posts delete) %w(change_category close archive change_notification_level reset_read dismiss_posts delete)
end end
def perform! def perform!
@ -61,6 +61,15 @@ class TopicsBulkAction
end end
end end
def archive
topics.each do |t|
if guardian.can_moderate?(t)
t.update_status('archived', true, @user)
@changed_ids << t.id
end
end
end
def delete def delete
topics.each do |t| topics.each do |t|
t.trash! if guardian.can_delete?(t) t.trash! if guardian.can_delete?(t)

View File

@ -122,4 +122,31 @@ describe TopicsBulkAction do
end end
end end
end end
describe "archive" do
let(:topic) { Fabricate(:topic) }
context "when the user can moderate the topic" do
it "archives the topic and returns the topic_id" do
Guardian.any_instance.expects(:can_moderate?).returns(true)
Guardian.any_instance.expects(:can_create?).returns(true)
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'archive')
topic_ids = tba.perform!
topic_ids.should == [topic.id]
topic.reload
topic.should be_archived
end
end
context "when the user can't edit the topic" do
it "doesn't archive the topic" do
Guardian.any_instance.expects(:can_moderate?).returns(false)
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'archive')
topic_ids = tba.perform!
topic_ids.should be_blank
topic.reload
topic.should_not be_archived
end
end
end
end end