FEATURE: do not visit muted categories after approving topics

FEATURE: do not visit muted categories after approving topics

Previously if you had certain code review categories muted we would still point you at them after followup/approve if you ran out of topics in your current category

diff --git a/app/controllers/discourse_code_review/code_review_controller.rb b/app/controllers/discourse_code_review/code_review_controller.rb
index 9fa4bdd..5e20d6c 100644
--- a/app/controllers/discourse_code_review/code_review_controller.rb
+++ b/app/controllers/discourse_code_review/code_review_controller.rb
@@ -117,11 +117,26 @@ module DiscourseCodeReview
     protected
 
     def render_next_topic(category_id)
+
+      category_filter_sql = <<~SQL
+        category_id NOT IN (
+          SELECT category_id
+          FROM category_users
+          WHERE user_id = :user_id AND
+            notification_level = :notification_level
+        )
+      SQL
+
       next_topic = Topic
         .joins(:tags)
         .joins("LEFT OUTER JOIN topic_users ON (topics.id = topic_users.topic_id AND topic_users.user_id = #{current_user.id})")
         .where('tags.name = ?', SiteSetting.code_review_pending_tag)
         .where('topics.user_id <> ?', current_user.id)
+        .where(
+          category_filter_sql,
+          user_id: current_user.id,
+          notification_level: CategoryUser.notification_levels[:muted]
+        )
         .order('case when last_read_post_number IS NULL then 0 else 1 end asc', "case when category_id = #{category_id.to_i} then 0 else 1 end asc", 'bumped_at asc')
         .first
 
diff --git a/spec/requests/discourse_code_review/code_review_controller_spec.rb b/spec/requests/discourse_code_review/code_review_controller_spec.rb
index f43a633..c8bf0fe 100644
--- a/spec/requests/discourse_code_review/code_review_controller_spec.rb
+++ b/spec/requests/discourse_code_review/code_review_controller_spec.rb
@@ -1,9 +1,12 @@
 require 'rails_helper'
 
 describe DiscourseCodeReview::CodeReviewController do
+
   before do
     SiteSetting.code_review_enabled = true
+    SiteSetting.tagging_enabled = true
   end
+
   context '.approve' do
     it 'allows you to approve your own commit if enabled' do
 
@@ -18,6 +21,40 @@ describe DiscourseCodeReview::CodeReviewController do
       expect(response.status).to eq(403)
     end
 
+    it 'skips commits from muted categories' do
+      admin = Fabricate(:admin)
+      admin2 = Fabricate(:admin)
+
+      muted_category = Fabricate(:category)
+
+      CategoryUser.create!(
+        user_id: admin.id,
+        category_id: muted_category.id,
+        notification_level: CategoryUser.notification_levels[:muted]
+      )
+
+      commit = create_post(
+        raw: "this is a fake commit",
+        tags: [SiteSetting.code_review_pending_tag],
+        user: admin2
+      )
+
+      _muted_commit = create_post(
+        raw: "this is a fake commit 2",
+        tags: [SiteSetting.code_review_pending_tag],
+        category: muted_category.name,
+        user: admin2
+      )
+
+      sign_in admin
+
+      post '/code-review/approve.json', params: { topic_id: commit.topic_id }
+      expect(response.status).to eq(200)
+
+      json = JSON.parse(response.body)
+      expect(json["next_topic_url"]).to eq(nil)
+    end
+
     it 'allows you to approve your own commit if enabled' do
 
       SiteSetting.code_review_allow_self_approval = true

GitHub sha: cd9c73cd

1 Like