skip your own commits where possible allow self approval of commits for now, there are some cases where it makes sense

skip your own commits where possible
allow self approval of commits for now, there are some cases
where it makes sense

From e1d4c58f54be56dad2c57568809546586dda6873 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Wed, 21 Nov 2018 16:02:18 +1100
Subject: [PATCH] skip your own commits where possible allow self approval of
 commits for now, there are some cases where it makes sense


diff --git a/app/controllers/discourse_code_review/code_review_controller.rb b/app/controllers/discourse_code_review/code_review_controller.rb
index 708e7b9..e4b1f51 100644
--- a/app/controllers/discourse_code_review/code_review_controller.rb
+++ b/app/controllers/discourse_code_review/code_review_controller.rb
@@ -24,10 +24,6 @@ class ::DiscourseCodeReview::CodeReviewController < ::ApplicationController
   def approve
     topic = Topic.find_by(id: params[:topic_id])
 
-    if topic.user_id == current_user.id
-      raise Discourse::InvalidAccess
-    end
-
     PostRevisor.new(topic.ordered_posts.first, topic)
       .revise!(current_user,
         category_id: SiteSetting.code_review_approved_category_id)
@@ -50,6 +46,7 @@ class ::DiscourseCodeReview::CodeReviewController < ::ApplicationController
     next_topic = Topic
       .where(category_id: SiteSetting.code_review_pending_category_id)
       .where('topics.id not in (select categories.topic_id from categories where categories.id = category_id)')
+      .where('user_id <> ?', current_user.id)
       .order('bumped_at asc')
       .first
 
diff --git a/assets/javascripts/discourse/initializers/init-code-review.js.es6 b/assets/javascripts/discourse/initializers/init-code-review.js.es6
index 89104e9..fb86995 100644
--- a/assets/javascripts/discourse/initializers/init-code-review.js.es6
+++ b/assets/javascripts/discourse/initializers/init-code-review.js.es6
@@ -21,14 +21,12 @@ function initialize(api) {
   api.addPostSmallActionIcon("followup", "clock-o");
   api.addPostSmallActionIcon("approved", "thumbs-up");
 
-  function allowUser(topic) {
+  function allowUser() {
     const currentUser = api.getCurrentUser();
     if (!currentUser) {
       return false;
     }
-    return (
-      currentUser.get("staff") && currentUser.get("id") !== topic.get("user_id")
-    );
+    return currentUser.get("staff");
   }
 
   api
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 34335d9..66687f7 100644
--- a/spec/requests/discourse_code_review/code_review_controller_spec.rb
+++ b/spec/requests/discourse_code_review/code_review_controller_spec.rb
@@ -12,7 +12,7 @@ describe DiscourseCodeReview::CodeReviewController do
       sign_in user
 
       post '/code-review/approve.json', params: { topic_id: commit.topic_id }
-      expect(response.status).to eq(403)
+      expect(response.status).to eq(200)
     end
   end
 end

GitHub

1 Like