FIX: only show approve / followup if already tagged as a commit

FIX: only show approve / followup if already tagged as a commit

only if we have the approve / followup / pending tag will we see extra
buttons

From 3fcb07b8d012b2d202cf75c4119d838fb04e7789 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Mon, 10 Dec 2018 15:27:27 +1100
Subject: [PATCH] FIX: only show approve / followup if already tagged as a
 commit

only if we have the approve / followup / pending tag will we see extra
buttons

diff --git a/assets/javascripts/discourse/initializers/init-code-review.js.es6 b/assets/javascripts/discourse/initializers/init-code-review.js.es6
index 4bdc9ce..673805b 100644
--- a/assets/javascripts/discourse/initializers/init-code-review.js.es6
+++ b/assets/javascripts/discourse/initializers/init-code-review.js.es6
@@ -52,21 +52,33 @@ function initialize(api) {
 
     const siteSettings = api.container.lookup("site-settings:main");
     const allowSelfApprove = siteSettings.code_review_allow_self_approval;
+
     const approvedTag = siteSettings.code_review_approved_tag;
+    const pendingTag = siteSettings.code_review_pending_tag;
+    const followupTag = siteSettings.code_review_followup_tag;
+
     const tags = topic.get("tags") || [];
 
     return (
       (allowSelfApprove || currentUser.get("id") !== topic.get("user_id")) &&
-      !tags.includes(approvedTag)
+      !tags.includes(approvedTag) &&
+      (tags.includes(pendingTag) || tags.includes(followupTag))
     );
   }
 
   function allowFollowup(topic) {
-    const followupTag = api.container.lookup("site-settings:main")
-      .code_review_followup_tag;
+    const siteSettings = api.container.lookup("site-settings:main");
+
+    const approvedTag = siteSettings.code_review_approved_tag;
+    const pendingTag = siteSettings.code_review_pending_tag;
+    const followupTag = siteSettings.code_review_followup_tag;
+
     const tags = topic.get("tags") || [];
 
-    return !tags.includes(followupTag);
+    return (
+      !tags.includes(followupTag) &&
+      (tags.includes(pendingTag) || tags.includes(approvedTag))
+    );
   }
 
   api
diff --git a/config/settings.yml b/config/settings.yml
index c338e1c..795cc89 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -3,7 +3,9 @@ plugins:
   code_review_catch_up_commits: 10
   code_review_api_username: ""
   code_review_allow_private_clone: false
-  code_review_pending_tag: "pending"
+  code_review_pending_tag:
+    client: true
+    default: "pending"
   code_review_approved_tag:
     client: true
     default: "approved"
diff --git a/test/javascripts/acceptance/self-approve-test-desktop.js.es6 b/test/javascripts/acceptance/self-approve-test-desktop.js.es6
index 4fad8fc..dfabce2 100644
--- a/test/javascripts/acceptance/self-approve-test-desktop.js.es6
+++ b/test/javascripts/acceptance/self-approve-test-desktop.js.es6
@@ -1,12 +1,26 @@
 import { replaceCurrentUser, acceptance } from "helpers/qunit-helpers";
+import Fixtures from "fixtures/topic";
 
 acceptance("review desktop", {
   loggedIn: true,
-  mobileView: false
+  mobileView: false,
+  settings: {
+    code_review_approved_tag: "approved",
+    code_review_pending_tag: "pending",
+    code_review_followup_tag: "followup"
+  }
 });
 
 QUnit.test("shows approve button by default", async assert => {
-  await visit("/t/internationalization-localization/280");
+  const json = $.extend(true, {}, Fixtures["/t/280/1.json"]);
+
+  json.tags = ["pending"];
+
+  server.get("/t/281.json", () => {
+    return [200, { "Content-Type": "application/json" }, json];
+  });
+
+  await visit("/t/internationalization-localization/281");
 
   assert.ok(count(".approve-commit-button") > 0);
 });
diff --git a/test/javascripts/acceptance/self-approve-test-mobile.js.es6 b/test/javascripts/acceptance/self-approve-test-mobile.js.es6
index 6a23832..e88c559 100644
--- a/test/javascripts/acceptance/self-approve-test-mobile.js.es6
+++ b/test/javascripts/acceptance/self-approve-test-mobile.js.es6
@@ -1,9 +1,15 @@
 import { replaceCurrentUser, acceptance } from "helpers/qunit-helpers";
 import { clearCallbacks } from "select-kit/mixins/plugin-api";
+import Fixtures from "fixtures/topic";
 
 acceptance("review mobile", {
   loggedIn: true,
   mobileView: true,
+  settings: {
+    code_review_approved_tag: "approved",
+    code_review_pending_tag: "pending",
+    code_review_followup_tag: "followup"
+  },
   afterEach() {
     clearCallbacks();
   },
@@ -15,7 +21,15 @@ acceptance("review mobile", {
 });
 
 QUnit.test("shows approve button by default", async assert => {
-  await visit("/t/internationalization-localization/280");
+  const json = $.extend(true, {}, Fixtures["/t/280/1.json"]);
+
+  json.tags = ["pending"];
+
+  server.get("/t/281.json", () => {
+    return [200, { "Content-Type": "application/json" }, json];
+  });
+
+  await visit("/t/internationalization-localization/281");
 
   const menu = selectKit(".topic-footer-mobile-dropdown");
   await menu.expand();

GitHub

1 Like