FEATURE: Continue reviewing in same category, even if muted (#30)

FEATURE: Continue reviewing in same category, even if muted (#30)

If you had all code review categories muted, then previously you would be taken to /latest every time you review a commit. Now it will continue in the same category, even if it’s muted.

diff --git a/app/controllers/discourse_code_review/code_review_controller.rb b/app/controllers/discourse_code_review/code_review_controller.rb
index ae81434..9138550 100644
--- a/app/controllers/discourse_code_review/code_review_controller.rb
+++ b/app/controllers/discourse_code_review/code_review_controller.rb
@@ -115,7 +115,8 @@ module DiscourseCodeReview
           SELECT category_id
           FROM category_users
           WHERE user_id = :user_id AND
-            notification_level = :notification_level
+            notification_level = :notification_level AND
+            category_id <> :requested_category_id
         )
       SQL
 
@@ -138,7 +139,8 @@ module DiscourseCodeReview
         .where(
           category_filter_sql,
           user_id: current_user.id,
-          notification_level: CategoryUser.notification_levels[:muted]
+          notification_level: CategoryUser.notification_levels[:muted],
+          requested_category_id: category_id
         )
         .order(
           'case when cr.expires_at IS NULL then 0 else 1 end asc',
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 1872154..7a2d00a 100644
--- a/spec/requests/discourse_code_review/code_review_controller_spec.rb
+++ b/spec/requests/discourse_code_review/code_review_controller_spec.rb
@@ -249,6 +249,20 @@ describe DiscourseCodeReview::CodeReviewController do
       json = JSON.parse(response.body)
       expect(json["next_topic_url"]).to eq(unread_commit.topic.relative_url)
     end
+
+    it 'will continue in the same category, even if muted' do
+      category = Fabricate(:category)
+      commit = create_post(raw: "this is a fake commit", user: other_user, tags: ["hi", SiteSetting.code_review_pending_tag], category: category)
+      unread_commit = create_post(raw: "this is an unread commit", user: other_user, tags: ["hi", SiteSetting.code_review_pending_tag], created_at: Time.zone.now + 2.hours,  category: category)
+
+      CategoryUser.create!(user_id: signed_in_user.id,
+                           category_id: category.id,
+                           notification_level: CategoryUser.notification_levels[:muted])
+
+      post '/code-review/approve.json', params: { topic_id: commit.topic_id }
+      json = JSON.parse(response.body)
+      expect(json["next_topic_url"]).to eq(unread_commit.topic.relative_url)
+    end
   end
 
   it 'assigns and unassigns topic on followup and approve' do

GitHub sha: 06f6e667

2 Likes

This commit appears in #30 which was merged by davidtaylorhq.