Merge pull request #2814 from cpradio/add-bulk-archive-option
FEATURE: Add Archive Topics to Bulk actions
This commit is contained in:
commit
223f3eebfc
|
@ -73,6 +73,12 @@ export default Ember.ArrayController.extend(ModalFunctionality, {
|
|||
});
|
||||
},
|
||||
|
||||
archiveTopics: function() {
|
||||
this.forEachPerformed({type: 'archive'}, function(t) {
|
||||
t.set('archived', true);
|
||||
});
|
||||
},
|
||||
|
||||
changeCategory: function() {
|
||||
var categoryId = parseInt(this.get('newCategoryId'), 10) || 0,
|
||||
category = Discourse.Category.findById(categoryId),
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<button class='btn' {{action showChangeCategory}}>{{i18n topics.bulk.change_category}}</button>
|
||||
<button class='btn' {{action deleteTopics}}>{{i18n topics.bulk.delete}}</button>
|
||||
<button class='btn' {{action closeTopics}}>{{i18n topics.bulk.close_topics}}</button>
|
||||
<button class='btn' {{action showNotificationLevel}}>{{i18n topics.bulk.notification_level}}</button>
|
||||
<button class='btn' {{action resetRead}}>{{i18n topics.bulk.reset_read}}</button>
|
||||
<p>
|
||||
<button class='btn' {{action showChangeCategory}}>{{i18n topics.bulk.change_category}}</button>
|
||||
<button class='btn' {{action deleteTopics}}>{{i18n topics.bulk.delete}}</button>
|
||||
<button class='btn' {{action closeTopics}}>{{i18n topics.bulk.close_topics}}</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>
|
|
@ -771,6 +771,7 @@ en:
|
|||
actions: "Bulk Actions"
|
||||
change_category: "Change Category"
|
||||
close_topics: "Close Topics"
|
||||
archive_topics: "Archive Topics"
|
||||
notification_level: "Change Notification Level"
|
||||
selected:
|
||||
one: "You have selected <b>1</b> topic."
|
||||
|
|
|
@ -8,7 +8,7 @@ class TopicsBulkAction
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def perform!
|
||||
|
@ -61,6 +61,15 @@ class TopicsBulkAction
|
|||
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
|
||||
topics.each do |t|
|
||||
t.trash! if guardian.can_delete?(t)
|
||||
|
|
|
@ -122,4 +122,31 @@ describe TopicsBulkAction do
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue