UX: Hide buttons depending on tags. (#1)

UX: Hide buttons depending on tags. (#1)
From ebecab38373c23466cf97adf6af007014a0d476f Mon Sep 17 00:00:00 2001
From: Bianca Nenciu <nbianca@users.noreply.github.com>
Date: Sun, 9 Dec 2018 23:49:47 +0200
Subject: [PATCH] UX: Hide buttons depending on tags. (#1)


diff --git a/assets/javascripts/discourse/initializers/init-code-review.js.es6 b/assets/javascripts/discourse/initializers/init-code-review.js.es6
index 61dbb05..246fc31 100644
--- a/assets/javascripts/discourse/initializers/init-code-review.js.es6
+++ b/assets/javascripts/discourse/initializers/init-code-review.js.es6
@@ -35,10 +35,23 @@ function initialize(api) {
       return false;
     }
 
-    const allowSelfApprove = api.container.lookup("site-settings:main")
-      .code_review_allow_self_approval;
+    const siteSettings = api.container.lookup("site-settings:main");
+    const allowSelfApprove = siteSettings.code_review_allow_self_approval;
+    const approvedTag = siteSettings.code_review_approved_tag;
+    const tags = topic.get("tags") || [];
 
-    return allowSelfApprove || currentUser.get("id") !== topic.get("user_id");
+    return (
+      (allowSelfApprove || currentUser.get("id") !== topic.get("user_id")) &&
+      !tags.includes(approvedTag)
+    );
+  }
+
+  function allowFollowup(topic) {
+    const followupTag = api.container.lookup("site-settings:main")
+      .code_review_followup_tag;
+    const tags = topic.get("tags") || [];
+
+    return !tags.includes(followupTag);
   }
 
   api
@@ -54,11 +67,12 @@ function initialize(api) {
             name: I18n.t("code_review.approve.label")
           });
 
-        existingContent.push({
-          id: "followup",
-          icon: "clock-o",
-          name: I18n.t("code_review.followup.label")
-        });
+        if (allowFollowup(topic))
+          existingContent.push({
+            id: "followup",
+            icon: "clock-o",
+            name: I18n.t("code_review.followup.label")
+          });
       }
       return existingContent;
     })
@@ -77,6 +91,7 @@ function initialize(api) {
       setupComponent(args) {
         this.set("topic", args.topic);
         this.set("showApprove", allowApprove(args.topic));
+        this.set("showFollowup", allowFollowup(args.topic));
       },
       shouldRender: function(args, component) {
         if (component.get("site.mobileView")) {
diff --git a/assets/javascripts/discourse/templates/connectors/topic-footer-main-buttons-before-create/approve.hbs b/assets/javascripts/discourse/templates/connectors/topic-footer-main-buttons-before-create/approve.hbs
index 89b8d4f..b751bff 100644
--- a/assets/javascripts/discourse/templates/connectors/topic-footer-main-buttons-before-create/approve.hbs
+++ b/assets/javascripts/discourse/templates/connectors/topic-footer-main-buttons-before-create/approve.hbs
@@ -7,9 +7,11 @@
   action="approveCommit"}}
 {{/if}}
 
+{{#if showFollowup}}
 {{d-button
   class="btn follow-up-commit-button"
   title="code_review.followup.title"
   label="code_review.followup.label"
   icon="clock-o"
   action="followupCommit"}}
+{{/if}}
diff --git a/config/settings.yml b/config/settings.yml
index 9696116..ebe0669 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -3,8 +3,12 @@ plugins:
   code_review_catch_up_commits: 10
   code_review_api_username: ""
   code_review_pending_tag: "pending"
-  code_review_approved_tag: "approved"
-  code_review_followup_tag: "follow-up"
+  code_review_approved_tag:
+    client: true
+    default: "approved"
+  code_review_followup_tag:
+    client: true
+    default: "follow-up"
   code_review_github_webhook_secret: ""
   code_review_allow_self_approval:
     client: true

GitHub