FIX: Ember CLI was always loading the admin payload in dev mode

FIX: Ember CLI was always loading the admin payload in dev mode

The admin payload should only be loaded if the user is staff.

diff --git a/app/assets/javascripts/discourse/app/index.html b/app/assets/javascripts/discourse/app/index.html
index c7c50c7..ba049ba 100644
--- a/app/assets/javascripts/discourse/app/index.html
+++ b/app/assets/javascripts/discourse/app/index.html
@@ -13,7 +13,6 @@
 
     <script src="{{rootURL}}assets/vendor.js"></script>
     <script src="{{rootURL}}assets/discourse.js"></script>
-    <script src="{{rootURL}}assets/admin.js"></script>
 
     <bootstrap-content key="head">
     {{content-for "head"}}
diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
index 802454b..6042435 100644
--- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
+++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
@@ -29,7 +29,7 @@ function htmlTag(buffer, bootstrap) {
   buffer.push(`<html lang="${bootstrap.html_lang}"${classList}>`);
 }
 
-function head(buffer, bootstrap) {
+function head(buffer, bootstrap, headers, baseURL) {
   if (bootstrap.csrf_token) {
     buffer.push(`<meta name="csrf-param" content="authenticity_token">`);
     buffer.push(`<meta name="csrf-token" content="${bootstrap.csrf_token}">`);
@@ -87,6 +87,13 @@ function head(buffer, bootstrap) {
     buffer.push(link);
   });
 
+  if (bootstrap.preloaded.currentUser) {
+    let staff = JSON.parse(bootstrap.preloaded.currentUser).staff;
+    if (staff) {
+      buffer.push(`<script src="${baseURL}assets/admin.js"></script>`);
+    }
+  }
+
   bootstrap.plugin_js.forEach((src) =>
     buffer.push(`<script src="${src}"></script>`)
   );
@@ -156,15 +163,15 @@ const BUILDERS = {
   "locale-script": localeScript,
 };
 
-function replaceIn(bootstrap, template, id, headers) {
+function replaceIn(bootstrap, template, id, headers, baseURL) {
   let buffer = [];
-  BUILDERS[id](buffer, bootstrap, headers);
+  BUILDERS[id](buffer, bootstrap, headers, baseURL);
   let contents = buffer.filter((b) => b && b.length > 0).join("\n");
 
   return template.replace(`<bootstrap-content key="${id}">`, contents);
 }
 
-async function applyBootstrap(bootstrap, template, response) {
+async function applyBootstrap(bootstrap, template, response, baseURL) {
   // If our initial page added some preload data let's not lose that.
   let json = await response.json();
   if (json && json.preloaded) {
@@ -172,7 +179,7 @@ async function applyBootstrap(bootstrap, template, response) {
   }
 
   Object.keys(BUILDERS).forEach((id) => {
-    template = replaceIn(bootstrap, template, id, response);
+    template = replaceIn(bootstrap, template, id, response, baseURL);
   });
   return template;
 }
@@ -192,7 +199,7 @@ function buildFromBootstrap(assetPath, proxy, baseURL, req, response) {
 
         getJSON(url, null, req.headers)
           .then((json) => {
-            return applyBootstrap(json.bootstrap, template, response);
+            return applyBootstrap(json.bootstrap, template, response, baseURL);
           })
           .then(resolve)
           .catch((e) => {

GitHub sha: cd8a608d1746c8e32af18ebf7767a30e527c1a58

This commit appears in #14504 which was approved by davidtaylorhq, tgxworld, and jjaffeux. It was merged by eviltrout.