diff --git a/app/assets/javascripts/discourse/controllers/bulk_notification_level_controller.js b/app/assets/javascripts/discourse/controllers/bulk_notification_level_controller.js index 60fb2a87092..444165baf99 100644 --- a/app/assets/javascripts/discourse/controllers/bulk_notification_level_controller.js +++ b/app/assets/javascripts/discourse/controllers/bulk_notification_level_controller.js @@ -7,7 +7,7 @@ @module Discourse **/ Discourse.BulkNotificationLevelController = Em.Controller.extend({ - needs: ['topicBulkActions', 'discoveryTopics'], + needs: ['topicBulkActions'], notificationLevelId: null, @@ -27,17 +27,9 @@ Discourse.BulkNotificationLevelController = Em.Controller.extend({ actions: { changeNotificationLevel: function() { - var self = this; - - this.get('controllers.topicBulkActions').perform({ + this.get('controllers.topicBulkActions').performAndRefresh({ type: 'change_notification_level', notification_level_id: this.get('notificationLevelId') - }).then(function(topics) { - if (topics) { - // Tell current route to reload - self.get('controllers.discoveryTopics').send('refresh'); - self.send('closeModal'); - } }); } } 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 8447491dd2b..3c5acaae747 100644 --- a/app/assets/javascripts/discourse/controllers/topic_bulk_actions_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_bulk_actions_controller.js @@ -8,6 +8,8 @@ @module Discourse **/ Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, { + needs: ['discoveryTopics'], + onShow: function() { this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal small'); }, @@ -40,6 +42,14 @@ Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.Mo }); }, + performAndRefresh: function(operation) { + var self = this; + return this.perform(operation).then(function() { + self.get('controllers.discoveryTopics').send('refresh'); + self.send('closeModal'); + }); + }, + actions: { showChangeCategory: function() { this.send('changeBulkTemplate', 'modal/bulk_change_category'); @@ -66,6 +76,10 @@ Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.Mo }); self.send('closeModal'); }); + }, + + resetRead: function() { + this.performAndRefresh({ type: 'reset_read' }); } } }); 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 0ae6fc38d1e..814f44f4693 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,3 +1,4 @@ + diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index ce7f462e33c..3d76a50e741 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -88,7 +88,7 @@ class TopicsController < ApplicationController end def destroy_timings - PostTiming.destroy_for(current_user.id, params[:topic_id].to_i) + PostTiming.destroy_for(current_user.id, [params[:topic_id].to_i]) render nothing: true end diff --git a/app/models/post_timing.rb b/app/models/post_timing.rb index 85a51a08d80..b8e86c8f3c6 100644 --- a/app/models/post_timing.rb +++ b/app/models/post_timing.rb @@ -52,10 +52,10 @@ class PostTiming < ActiveRecord::Base end - def self.destroy_for(user_id, topic_id) + def self.destroy_for(user_id, topic_ids) PostTiming.transaction do - PostTiming.delete_all(['user_id = ? and topic_id = ?', user_id, topic_id]) - TopicUser.delete_all(['user_id = ? and topic_id = ?', user_id, topic_id]) + PostTiming.delete_all(['user_id = ? and topic_id in (?)', user_id, topic_ids]) + TopicUser.delete_all(['user_id = ? and topic_id in (?)', user_id, topic_ids]) end end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0ce3bbc3490..b08f6f5fff6 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -628,6 +628,7 @@ en: topics: bulk: + reset_read: "Reset Read" dismiss_read: "Dismiss Read" toggle: "toggle bulk selection of topics" actions: "Bulk Actions" diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb index 5e31dc6ca6c..a0ee6f4adef 100644 --- a/lib/topics_bulk_action.rb +++ b/lib/topics_bulk_action.rb @@ -8,7 +8,7 @@ class TopicsBulkAction end def self.operations - %w(change_category close change_notification_level) + %w(change_category close change_notification_level reset_read) end def perform! @@ -19,6 +19,10 @@ class TopicsBulkAction private + def reset_read + PostTiming.destroy_for(@user.id, @topic_ids) + end + def change_category topics.each do |t| if guardian.can_edit?(t) diff --git a/spec/components/topics_bulk_action_spec.rb b/spec/components/topics_bulk_action_spec.rb index 23637e40d58..1473677e9f9 100644 --- a/spec/components/topics_bulk_action_spec.rb +++ b/spec/components/topics_bulk_action_spec.rb @@ -27,7 +27,7 @@ describe TopicsBulkAction do end context "when the user can't edit the topic" do - it "doesn't change the category" 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! @@ -38,10 +38,20 @@ describe TopicsBulkAction do end end + describe "reset_read" do + let(:topic) { Fabricate(:topic) } + + it "delegates to PostTiming.destroy_for" do + tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'reset_read') + PostTiming.expects(:destroy_for).with(topic.user_id, [topic.id]) + topic_ids = tba.perform! + end + end + describe "change_notification_level" do let(:topic) { Fabricate(:topic) } - context "when the user can edit the topic" do + context "when the user can see the topic" do it "updates the notification level" do tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2) topic_ids = tba.perform! @@ -50,7 +60,7 @@ describe TopicsBulkAction do end end - context "when the user can't edit the topic" do + context "when the user can't see the topic" do it "doesn't change the level" do Guardian.any_instance.expects(:can_see?).returns(false) tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2) diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index a6eaedd8a16..51006b53339 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -345,7 +345,7 @@ describe TopicsController do end it 'deletes the forum topic user record' do - PostTiming.expects(:destroy_for).with(@user.id, @topic.id) + PostTiming.expects(:destroy_for).with(@user.id, [@topic.id]) xhr :delete, :destroy_timings, topic_id: @topic.id end