diff --git a/app/assets/javascripts/discourse/controllers/topic_bulk_actions_controller.js b/app/assets/javascripts/discourse/controllers/topic_bulk_actions_controller.js
index d0176b28c..1b90f5831 100644
--- a/app/assets/javascripts/discourse/controllers/topic_bulk_actions_controller.js
+++ b/app/assets/javascripts/discourse/controllers/topic_bulk_actions_controller.js
@@ -9,7 +9,7 @@
**/
Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, {
onShow: function() {
- this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal');
+ this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal small');
},
perform: function(operation) {
@@ -30,9 +30,26 @@ Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.Mo
});
},
+ forEachPerformed: function(operation, cb) {
+ var self = this;
+ this.perform(operation).then(function (topics) {
+ if (topics) {
+ topics.forEach(cb);
+ self.send('closeModal');
+ }
+ });
+ },
+
actions: {
showChangeCategory: function() {
this.send('changeBulkTemplate', 'modal/bulk_change_category');
+ this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal full');
+ },
+
+ closeTopics: function() {
+ this.forEachPerformed({type: 'close'}, function(t) {
+ t.set('closed', true);
+ });
},
changeCategory: function() {
diff --git a/app/assets/javascripts/discourse/templates/modal/bulk_actions_buttons.js.handlebars b/app/assets/javascripts/discourse/templates/modal/bulk_actions_buttons.js.handlebars
index 88c8763eb..e17be58e3 100644
--- a/app/assets/javascripts/discourse/templates/modal/bulk_actions_buttons.js.handlebars
+++ b/app/assets/javascripts/discourse/templates/modal/bulk_actions_buttons.js.handlebars
@@ -1 +1,2 @@
+
diff --git a/app/assets/stylesheets/desktop/modal.scss b/app/assets/stylesheets/desktop/modal.scss
index 8445d42a4..857404e57 100644
--- a/app/assets/stylesheets/desktop/modal.scss
+++ b/app/assets/stylesheets/desktop/modal.scss
@@ -251,9 +251,9 @@
p {
margin-top: 0;
}
- .modal-body {
- height: 420px;
- max-height: 420px;
+ &.full .modal-body {
+ height: 400px;
+ max-height: 400px;
}
}
.tabbed-modal {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 0d16de9cd..0cecfb68a 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -604,6 +604,7 @@ en:
toggle: "toggle bulk selection of topics"
actions: "Bulk Actions"
change_category: "Change Category"
+ close_topics: "Close Topics"
selected:
one: "You have selected 1 topic."
other: "You have selected {{count}} topics."
diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb
index e4dcc6535..85d9a7396 100644
--- a/lib/topics_bulk_action.rb
+++ b/lib/topics_bulk_action.rb
@@ -4,27 +4,36 @@ class TopicsBulkAction
@user = user
@topic_ids = topic_ids
@operation = operation
+ @changed_ids = []
end
def self.operations
- %w(change_category)
+ %w(change_category close)
end
def perform!
raise Discourse::InvalidParameters.new(:operation) unless TopicsBulkAction.operations.include?(@operation[:type])
send(@operation[:type])
+ @changed_ids
end
private
def change_category
- changed_ids = []
topics.each do |t|
if guardian.can_edit?(t)
- changed_ids << t.id if t.change_category(@operation[:category_name])
+ @changed_ids << t.id if t.change_category(@operation[:category_name])
+ end
+ end
+ end
+
+ def close
+ topics.each do |t|
+ if guardian.can_moderate?(t)
+ t.update_status('closed', true, @user)
+ @changed_ids << t.id
end
end
- changed_ids
end
def guardian
diff --git a/spec/components/topics_bulk_action_spec.rb b/spec/components/topics_bulk_action_spec.rb
index 3e0d3b7f0..84233d57a 100644
--- a/spec/components/topics_bulk_action_spec.rb
+++ b/spec/components/topics_bulk_action_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
-require 'topics_bulk_action'
+require_dependency 'topics_bulk_action'
describe TopicsBulkAction do
describe "invalid operation" do
- let(:user) { Fabricate.build(:user) }
+ let(:user) { Fabricate.build(:user) }
it "raises an error with an invalid operation" do
tba = TopicsBulkAction.new(user, [1], type: 'rm_root')
@@ -14,7 +14,7 @@ describe TopicsBulkAction do
describe "change_category" do
let(:topic) { Fabricate(:topic) }
- let(:category) { Fabricate(:category) }
+ let(:category) { Fabricate(:category) }
context "when the user can edit the topic" do
it "changes the category and returns the topic_id" do
@@ -27,7 +27,7 @@ describe TopicsBulkAction do
end
context "when the user can't edit the topic" do
- it "doesn't change the category and returns the topic_id" do
+ it "doesn't change the category" do
Guardian.any_instance.expects(:can_edit?).returns(false)
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_category', category_name: category.name)
topic_ids = tba.perform!
@@ -36,7 +36,32 @@ describe TopicsBulkAction do
topic.category.should_not == category
end
end
+ end
+ describe "close" do
+ let(:topic) { Fabricate(:topic) }
+
+ context "when the user can moderate the topic" do
+ it "closes 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: 'close')
+ topic_ids = tba.perform!
+ topic_ids.should == [topic.id]
+ topic.reload
+ topic.should be_closed
+ end
+ end
+
+ context "when the user can't edit the topic" do
+ it "doesn't close the topic" do
+ Guardian.any_instance.expects(:can_moderate?).returns(false)
+ tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'close')
+ topic_ids = tba.perform!
+ topic_ids.should be_blank
+ topic.reload
+ topic.should_not be_closed
+ end
+ end
end
end
-