From 76f5a65b2cc8a45b55570470ffc08b1227942576 Mon Sep 17 00:00:00 2001
From: Marti Martz
Date: Tue, 28 Nov 2017 03:02:31 -0700
Subject: [PATCH] statusCodePage enhance further (#1289)
* Use some more *bootstrap* classes
* Show which file erred out on repos that have multiple scripts. *(and singles)*
Post #1284
Auto-merge
---
controllers/user.js | 59 +++++++++++++++++++++++++----
views/pages/statusCodePage.html | 9 ++++-
views/pages/userGitHubRepoPage.html | 4 +-
3 files changed, 63 insertions(+), 9 deletions(-)
diff --git a/controllers/user.js b/controllers/user.js
index 9e5aa91ba..518c6d366 100644
--- a/controllers/user.js
+++ b/controllers/user.js
@@ -1204,6 +1204,9 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;
var githubUserId = null;
var githubRepoName = null;
+ var githubDefaultBranch = null;
+ var githubPathName = null;
+ var githubPathExt = null;
var githubBlobPath = null;
// Session
@@ -1218,6 +1221,9 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
options.isOwnRepo = authedUser.ghUsername && authedUser.ghUsername === options.githubUserId;
options.githubRepoName = githubRepoName = aReq.body.repo || aReq.query.repo;
+ options.githubDefaultBranch = githubDefaultBranch = aReq.body.default_branch || aReq.query.default_branch;
+ options.githubPathName = githubPathName = aReq.body.pathname || aReq.query.pathname;
+ options.githubPathExt = githubPathExt = aReq.body.pathext || aReq.query.pathext;
options.githubBlobPath = githubBlobPath = aReq.body.path || aReq.query.path;
if (!(githubUserId && githubRepoName && githubBlobPath)) {
@@ -1284,7 +1290,17 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
if (aErr) {
statusCodePage(aReq, aRes, aNext, {
statusCode: aErr.status.code,
- statusMessage: aErr.status.message
+ statusMessage: aErr.status.message,
+ isCustomView: true,
+ statusData: {
+ isGHImport: true,
+ utf_pathname: githubPathName,
+ utf_pathext: githubPathExt,
+ user: encodeURIComponent(githubUserId),
+ repo: encodeURIComponent(githubRepoName),
+ default_branch: encodeURIComponent(githubDefaultBranch),
+ path: encodeURIComponent(githubBlobPath)
+ }
});
return;
}
@@ -1329,7 +1345,21 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
}
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
} else {
- aCallback('Specified file does not contain the proper metadata blocks.');
+ statusCodePage(aReq, aRes, aNext, {
+ statusCode: 400,
+ statusMessage: 'Specified file does not contain the proper metadata blocks.',
+ isCustomView: true,
+ statusData: {
+ isGHImport: true,
+ utf_pathname: githubPathName,
+ utf_pathext: githubPathExt,
+ user: encodeURIComponent(githubUserId),
+ repo: encodeURIComponent(githubRepoName),
+ default_branch: encodeURIComponent(githubDefaultBranch),
+ path: encodeURIComponent(githubBlobPath)
+ }
+ });
+ return;
}
} else if (options.javascriptBlob.isJSLibrary) {
@@ -1360,11 +1390,23 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
}
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
} else {
- aCallback('Specified file does not contain the proper metadata blocks.');
+ statusCodePage(aReq, aRes, aNext, {
+ statusCode: 400,
+ statusMessage: 'Specified file does not contain the proper metadata blocks.',
+ isCustomView: true,
+ statusData: {
+ isGHImport: true,
+ utf_pathname: githubPathName,
+ utf_pathext: githubPathExt,
+ user: encodeURIComponent(githubUserId),
+ repo: encodeURIComponent(githubRepoName),
+ default_branch: encodeURIComponent(githubDefaultBranch),
+ path: encodeURIComponent(githubBlobPath)
+ }
+ });
+ return;
}
-
-
} else {
aCallback('Invalid filetype.');
}
@@ -1373,8 +1415,11 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
var script = null;
if (aErr) {
- console.error(aErr);
- console.error(githubUserId, githubRepoName, githubBlobPath);
+ console.error([
+ aErr,
+ authedUser.name + ' ' + githubUserId + ' ' + githubRepoName + ' ' + githubBlobPath
+
+ ].join('\n'));
statusCodePage(aReq, aRes, aNext, {
statusCode: 400,
statusMessage: aErr
diff --git a/views/pages/statusCodePage.html b/views/pages/statusCodePage.html
index ac771623a..0ab7af52a 100644
--- a/views/pages/statusCodePage.html
+++ b/views/pages/statusCodePage.html
@@ -44,13 +44,20 @@ {{statusCode}}
{{#isAdminSessionLengthView}}
Session Length: {{length}}
{{/isAdminSessionLengthView}}
+ {{#isGHImport}}
+ {{{statusMessage}}}
{{utf_pathname}}{{utf_pathext}}
+ {{/isGHImport}}
{{/statusData}}
{{/isCustomView}}
{{^isCustomView}}
{{{statusMessage}}}
{{/isCustomView}}
-
+
diff --git a/views/pages/userGitHubRepoPage.html b/views/pages/userGitHubRepoPage.html
index 8998f914c..cd7108ec8 100644
--- a/views/pages/userGitHubRepoPage.html
+++ b/views/pages/userGitHubRepoPage.html
@@ -33,11 +33,13 @@
{{path.dir}}{{path.name}}{{path.ext}}
{{size}} bytes