FIX: Check if plugin disabled globally prior to extending JS

FIX: Check if plugin disabled globally prior to extending JS

From 16afd2c6122f07d1a57f7d17399ebf673fe9ffc9 Mon Sep 17 00:00:00 2001
From: Bianca Nenciu <nbianca@users.noreply.github.com>
Date: Fri, 23 Nov 2018 01:53:07 +0200
Subject: [PATCH] FIX: Check if plugin disabled globally prior to extending JS


diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
index e7de592..524b5e1 100644
--- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
+++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
@@ -141,8 +141,7 @@ function initialize(api) {
   api.addUserMenuGlyph(widget => {
     if (
       widget.currentUser &&
-      widget.currentUser.get("staff") &&
-      widget.siteSettings.assign_enabled
+      widget.currentUser.get("staff")
     ) {
       return {
         label: "discourse_assign.assigned",
@@ -217,6 +216,10 @@ function initialize(api) {
 export default {
   name: "extend-for-assign",
   initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.assign_enabled) {
+      return;
+    }
     withPluginApi("0.8.11", api => initialize(api, container));
     withPluginApi("0.8.13", api => modifySelectKit(api, container));
   }
diff --git a/test/javascripts/acceptance/assign-test.js.es6 b/test/javascripts/acceptance/assign-test.js.es6
new file mode 100644
index 0000000..94bfb63
--- /dev/null
+++ b/test/javascripts/acceptance/assign-test.js.es6
@@ -0,0 +1,31 @@
+import { acceptance } from "helpers/qunit-helpers";
+
+acceptance("Assign (mobile)", {
+  loggedIn: true,
+  mobileView: true,
+  settings: { assign_enabled: true },
+});
+
+QUnit.test("Footer dropdown contains button", async assert => {
+  const menu = selectKit(".topic-footer-mobile-dropdown");
+
+  await visit("/t/internationalization-localization/280");
+  await menu.expand();
+
+  assert.ok(menu.rowByValue("assign").exists());
+});
+
+acceptance("Assign (mobile & disabled)", {
+  loggedIn: true,
+  mobileView: true,
+  settings: { assign_enabled: false },
+});
+
+QUnit.test("Footer dropdown does not contain button", async assert => {
+  const menu = selectKit(".topic-footer-mobile-dropdown");
+
+  await visit("/t/internationalization-localization/280");
+  await menu.expand();
+
+  assert.notOk(menu.rowByValue("assign").exists());
+});

GitHub

1 Like