2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

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

The admin payload should only be loaded if the user is staff.
This commit is contained in:
Robin Ward 2021-10-04 16:13:01 -04:00
parent 1552d06008
commit cd8a608d17
2 changed files with 13 additions and 7 deletions

View file

@ -13,7 +13,6 @@
<script src="{{rootURL}}assets/vendor.js"></script> <script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/discourse.js"></script> <script src="{{rootURL}}assets/discourse.js"></script>
<script src="{{rootURL}}assets/admin.js"></script>
<bootstrap-content key="head"> <bootstrap-content key="head">
{{content-for "head"}} {{content-for "head"}}

View file

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