FEATURE: Can bulk delete topics now using the modal.

This commit is contained in:
Robin Ward 2014-08-11 15:13:44 -04:00
parent 0ee07ae2bb
commit 15c7e01b90
5 changed files with 27 additions and 1 deletions

View File

@ -28,6 +28,7 @@ export default Ember.ArrayController.extend(Discourse.ModalFunctionality, {
}
return result;
}).catch(function() {
bootbox.alert(I18n.t('generic_error'));
self.set('loading', false);
});
},
@ -60,6 +61,10 @@ export default Ember.ArrayController.extend(Discourse.ModalFunctionality, {
this.send('changeBulkTemplate', 'modal/bulk_notification_level');
},
deleteTopics: function() {
this.performAndRefresh({type: 'delete'});
},
closeTopics: function() {
this.forEachPerformed({type: 'close'}, function(t) {
t.set('closed', true);

View File

@ -1,4 +1,5 @@
<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>

View File

@ -726,6 +726,7 @@ en:
topics:
bulk:
reset_read: "Reset Read"
delete: "Delete Topics"
dismiss_posts: "Dismiss Posts"
dismiss_posts_tooltip: "Clear unread counts on these topics but continue to show them on my unread list when new posts are made"
dismiss_topics: "Dismiss Topics"

View File

@ -8,7 +8,7 @@ class TopicsBulkAction
end
def self.operations
%w(change_category close change_notification_level reset_read dismiss_posts)
%w(change_category close change_notification_level reset_read dismiss_posts delete)
end
def perform!
@ -61,6 +61,12 @@ class TopicsBulkAction
end
end
def delete
topics.each do |t|
t.trash! if guardian.can_delete?(t)
end
end
def guardian
@guardian ||= Guardian.new(@user)
end
@ -69,5 +75,6 @@ class TopicsBulkAction
@topics ||= Topic.where(id: @topic_ids)
end
end

View File

@ -61,6 +61,18 @@ describe TopicsBulkAction do
end
end
describe "delete" do
let(:topic) { Fabricate(:topic) }
let(:moderator) { Fabricate(:moderator) }
it "deletes the topic" do
tba = TopicsBulkAction.new(moderator, [topic.id], type: 'delete')
tba.perform!
topic.reload
topic.should be_trashed
end
end
describe "change_notification_level" do
let(:topic) { Fabricate(:topic) }