From 9e1d53a30cf444c084c283aa7e097307e9370dda Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 19 Jun 2023 21:06:38 +1200 Subject: [PATCH 01/44] Basic ErrorPage functionality --- client/homebrew/homebrew.jsx | 3 +- client/homebrew/pages/errorPage/errorPage.jsx | 8 ++--- server/app.js | 33 +++++++++++++++++-- server/homebrew.api.js | 17 ++++++---- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx index f6dccbdb7..a08a39ea0 100644 --- a/client/homebrew/homebrew.jsx +++ b/client/homebrew/homebrew.jsx @@ -9,7 +9,7 @@ const EditPage = require('./pages/editPage/editPage.jsx'); const UserPage = require('./pages/userPage/userPage.jsx'); const SharePage = require('./pages/sharePage/sharePage.jsx'); const NewPage = require('./pages/newPage/newPage.jsx'); -//const ErrorPage = require('./pages/errorPage/errorPage.jsx'); +const ErrorPage = require('./pages/errorPage/errorPage.jsx'); const PrintPage = require('./pages/printPage/printPage.jsx'); const AccountPage = require('./pages/accountPage/accountPage.jsx'); @@ -78,6 +78,7 @@ const Homebrew = createClass({ } /> } /> } /> + } /> } /> } /> diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index 560ab5625..8e6a25ff7 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -16,12 +16,12 @@ const ErrorPage = createClass({ getDefaultProps : function() { return { ver : '0.0.0', - errorId : '' + errorId : '', + text : '# Oops \n We could not find a brew with that id. **Sorry!**', + error : {} }; }, - text : '# Oops \n We could not find a brew with that id. **Sorry!**', - render : function(){ return
@@ -39,7 +39,7 @@ const ErrorPage = createClass({
- +
; } diff --git a/server/app.js b/server/app.js index 22c9d9dac..e292831ca 100644 --- a/server/app.js +++ b/server/app.js @@ -397,6 +397,18 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ return next(); })); +app.get('/error', (req, res, next)=>{ + console.log('ERROR PAGE'); + const errorCookie = JSON.parse(req.cookies['HOMEBREWERY_Error']) || {}; + if(errorCookie){ res.cookie('HOMEBREWERY_Error', '', { maxAge: 0 }); } + + console.log(errorCookie); + + req.ogMeta = errorCookie.ogMeta; + req.brew = errorCookie.error; + + return next(); +}); const nodeEnv = config.get('node_env'); const isLocalEnvironment = config.get('local_environments').includes(nodeEnv); @@ -462,9 +474,24 @@ const getPureError = (error)=>{ }; app.use((err, req, res, next)=>{ - const status = err.status || 500; - console.error(err); - res.status(status).send(getPureError(err)); + console.log(err); + const status = err.status || err.code || 500; + + const errorData = { + error : { + title : 'Error - Something went wrong!', + text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!', + status : status + }, + ogMeta : { ...defaultMetaTags, + title : 'Error Page', + description : 'Something went wrong!' + } + }; + res.cookie('HOMEBREWERY_Error', JSON.stringify(errorData), { maxAge: 300 * 1000 }); + + // res.status(status).send(getPureError(err)); + res.redirect('/error'); }); app.use((req, res)=>{ diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 39fa021e5..2271466b8 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -57,7 +57,10 @@ const api = { googleError = err; }); // Throw any error caught while attempting to retrieve Google brew. - if(googleError) throw googleError; + if(googleError) { + // console.log(googleError); + throw { ...new Error, ...googleError }; + } // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew; } @@ -65,14 +68,14 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { - throw `The current logged in user does not have editor access to this brew. + throw { ...new Error, message : `The current logged in user does not have editor access to this brew. -If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.`; +If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.` }; } // If after all of that we still don't have a brew, throw an exception if(!stub && !stubOnly) { - throw 'Brew not found in Homebrewery database or Google Drive'; + throw { ...new Error, message: 'Brew not found in Homebrewery database or Google Drive' }; } // Clean up brew: fill in missing fields with defaults / fix old invalid values @@ -181,7 +184,7 @@ If you believe you should have access to this brew, ask the file owner to invite saved = await newHomebrew.save() .catch((err)=>{ console.error(err, err.toString(), err.stack); - throw `Error while creating new brew, ${err.toString()}`; + throw { ...new Error, message: `Error while creating new brew, ${err.toString()}` }; }); if(!saved) return; saved = saved.toObject(); @@ -308,7 +311,7 @@ If you believe you should have access to this brew, ask the file owner to invite await HomebrewModel.deleteOne({ _id: brew._id }) .catch((err)=>{ console.error(err); - throw { status: 500, message: 'Error while removing' }; + throw { ...new Error, status: 500, message: 'Error while removing' }; }); } else { if(shouldDeleteGoogleBrew) { @@ -320,7 +323,7 @@ If you believe you should have access to this brew, ask the file owner to invite brew.markModified('authors'); //Mongo will not properly update arrays without markModified() await brew.save() .catch((err)=>{ - throw { status: 500, message: err }; + throw { ...new Error, status: 500, message: err }; }); } } From ce538ebbfdf9070d4b1692ddfc3c01c2de2a2d10 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 20 Jun 2023 13:44:41 +1200 Subject: [PATCH 02/44] Add errorIndex.json --- client/homebrew/pages/errorPage/errors/errorIndex.json | 3 +++ server/app.js | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 client/homebrew/pages/errorPage/errors/errorIndex.json diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.json b/client/homebrew/pages/errorPage/errors/errorIndex.json new file mode 100644 index 000000000..1d8fb35d5 --- /dev/null +++ b/client/homebrew/pages/errorPage/errors/errorIndex.json @@ -0,0 +1,3 @@ +{ + "404" : "## Your brew is not here.\n\nThis error tells us your file was saved on your Google Drive, but the link you tried to open doesn't work anymore. Since the Homebrewery cannot delete your your personal files from Google Drive without you clicking the delete button, there are three most likely possibilities:\n\n- You have accidentally deleted the Google Drive files. Look on your Google Drive and make sure the Homebrewery folder is still there, and that it holds your brews as text files.\n\n- You have accidentally changed the sharing settings for your files. If the files are still on Google Drive, change all of them to be shared **with everyone who has the link** so the Homebrewery can access them.\n\n- Rarely, it might mean that your Google Account is full or has been closed by Google (for inactivity, violating some policy of theirs). Make sure you can still access your Google Drive normally and upload/download files to it.\n\nIf you can't find it, Google Drive usually puts your file in your Trash folder for 30 days. Assuming you didn't empty the trash right after, it might be worth checking. You can also look on the right side of the page while logged into Google Drive and look at the Activity tab. This can help you pin down the exact date the brew was deleted and by whom.\n\nIf you still can't find it, some people have had success asking Google to recover accidentally deleted files. You can visit this link https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946.\n\nAt the bottom of the page there is a button that says **Send yourself an Email** and you will receive instructions on how to request the files be restored.\n\nAlso note, at no point are you 'forced' to save your files on Google Drive. You can always set any brew to be stored on your own Google Drive, or on the Homebrewery servers, by clicking the Google drive icon by the brew title and choosing **transfer my brew to/from Google Drive**." +} \ No newline at end of file diff --git a/server/app.js b/server/app.js index e292831ca..face33efe 100644 --- a/server/app.js +++ b/server/app.js @@ -398,12 +398,9 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ })); app.get('/error', (req, res, next)=>{ - console.log('ERROR PAGE'); - const errorCookie = JSON.parse(req.cookies['HOMEBREWERY_Error']) || {}; + const errorCookie = JSON.parse(req.cookies['HOMEBREWERY_Error']); if(errorCookie){ res.cookie('HOMEBREWERY_Error', '', { maxAge: 0 }); } - console.log(errorCookie); - req.ogMeta = errorCookie.ogMeta; req.brew = errorCookie.error; From 4d6ac2b142d196f01fe9901697bc2aceeafaa1f0 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 20 Jun 2023 13:45:01 +1200 Subject: [PATCH 03/44] Update ErrorPage to use basePage/UIPage --- client/homebrew/pages/errorPage/errorPage.jsx | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index 8e6a25ff7..797d2e8e3 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -4,15 +4,15 @@ const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); -const Nav = require('naturalcrit/nav/nav.jsx'); -const Navbar = require('../../navbar/navbar.jsx'); -const PatreonNavItem = require('../../navbar/patreon.navitem.jsx'); -const RecentNavItem = require('../../navbar/recent.navitem.jsx').both; -const HelpNavItem = require('../../navbar/help.navitem.jsx'); +const UIPage = require('../basePages/uiPage/uiPage.jsx'); -const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx'); +const Markdown = require('../../../../shared/naturalcrit/markdown.js'); + +const ErrorIndex = require('./errors/errorIndex.json'); const ErrorPage = createClass({ + displayName : 'ErrorPage', + getDefaultProps : function() { return { ver : '0.0.0', @@ -23,25 +23,14 @@ const ErrorPage = createClass({ }, render : function(){ - return
- - - - Crit Fail! - - + const errorText = ErrorIndex[this.props.brew.status.toString()] || ''; - - - - - - - -
- -
-
; + return +

{`Error ${this.props.brew.status || '000'}`}

+

{this.props.brew.text || 'No error text'}

+
+
+ ; } }); From 71c384ee0be45768d533383caadfd828a05d0ac6 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 20 Jun 2023 16:45:36 +1200 Subject: [PATCH 04/44] Fix tests --- server/homebrew.api.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index c6443be7b..19dc1135c 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -162,7 +162,7 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual(notFoundError); + expect(err).toEqual({ 'message': notFoundError }); expect(req.brew).toEqual({}); expect(next).not.toHaveBeenCalled(); expect(api.getId).toHaveBeenCalledWith(req); @@ -197,9 +197,9 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual(`The current logged in user does not have editor access to this brew. + expect(err).toEqual({ 'message' : `The current logged in user does not have editor access to this brew. -If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.`); +If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.` }); }); it('does not throw if no authors', async ()=>{ From 2fa1b2bb8b44c72325e4370199fe4f01471f5502 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 23 Jun 2023 16:29:17 -0400 Subject: [PATCH 05/44] Break out page rendering into function --- server/app.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/app.js b/server/app.js index face33efe..c1a8595e7 100644 --- a/server/app.js +++ b/server/app.js @@ -423,8 +423,7 @@ if(isLocalEnvironment){ //Render the page const templateFn = require('./../client/template.js'); -app.use(asyncHandler(async (req, res, next)=>{ - +const renderPage = async (req, res) => { // Create configuration object const configuration = { local : isLocalEnvironment, @@ -449,6 +448,11 @@ app.use(asyncHandler(async (req, res, next)=>{ console.log(err); return res.sendStatus(500); }); + return page; +}; + +app.use(asyncHandler(async (req, res, next)=>{ + const page = await renderPage(req, res); if(!page) return; res.send(page); })); From 37c88b83f1341e1f986ac4663c17773be1214dac Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 23 Jun 2023 17:24:31 -0400 Subject: [PATCH 06/44] Don't redirect/use cookies. Just render page. --- server/app.js | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/server/app.js b/server/app.js index c1a8595e7..10f99ffaa 100644 --- a/server/app.js +++ b/server/app.js @@ -397,16 +397,6 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ return next(); })); -app.get('/error', (req, res, next)=>{ - const errorCookie = JSON.parse(req.cookies['HOMEBREWERY_Error']); - if(errorCookie){ res.cookie('HOMEBREWERY_Error', '', { maxAge: 0 }); } - - req.ogMeta = errorCookie.ogMeta; - req.brew = errorCookie.error; - - return next(); -}); - const nodeEnv = config.get('node_env'); const isLocalEnvironment = config.get('local_environments').includes(nodeEnv); // Local only @@ -432,7 +422,7 @@ const renderPage = async (req, res) => { }; const props = { version : require('./../package.json').version, - url : req.originalUrl, + url : req.customUrl || req.originalUrl, brew : req.brew, brews : req.brews, googleBrews : req.googleBrews, @@ -446,11 +436,11 @@ const renderPage = async (req, res) => { const page = await templateFn('homebrew', title, props) .catch((err)=>{ console.log(err); - return res.sendStatus(500); }); return page; }; +//Send rendered page app.use(asyncHandler(async (req, res, next)=>{ const page = await renderPage(req, res); if(!page) return; @@ -458,8 +448,8 @@ app.use(asyncHandler(async (req, res, next)=>{ })); //v=====----- Error-Handling Middleware -----=====v// -//Format Errors so all fields will be sent -const replaceErrors = (key, value)=>{ +//Format Errors as plain objects so all fields will appear in the string sent +const formatErrors = (key, value)=>{ if(value instanceof Error) { const error = {}; Object.getOwnPropertyNames(value).forEach(function (key) { @@ -471,28 +461,27 @@ const replaceErrors = (key, value)=>{ }; const getPureError = (error)=>{ - return JSON.parse(JSON.stringify(error, replaceErrors)); + return JSON.parse(JSON.stringify(error, formatErrors)); }; -app.use((err, req, res, next)=>{ - console.log(err); +app.use(async (err, req, res, next)=>{ const status = err.status || err.code || 500; + console.error(err); - const errorData = { - error : { - title : 'Error - Something went wrong!', - text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!', - status : status - }, - ogMeta : { ...defaultMetaTags, - title : 'Error Page', - description : 'Something went wrong!' - } + req.ogMeta = {...defaultMetaTags, + title : 'Error Page', + description : 'Something went wrong!' }; - res.cookie('HOMEBREWERY_Error', JSON.stringify(errorData), { maxAge: 300 * 1000 }); + req.brew = { + title : 'Error - Something went wrong!', + text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!', + status : status + }; + req.customUrl= '/error'; - // res.status(status).send(getPureError(err)); - res.redirect('/error'); + const page = await renderPage(req, res); + if(!page) return; + res.send(page); }); app.use((req, res)=>{ From 32229c6e6e25aa71bc7f5d2975f6f9285143f884 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 24 Jun 2023 00:40:10 -0400 Subject: [PATCH 07/44] Change json file to js so we can use multiline strings --- client/homebrew/pages/errorPage/errorPage.jsx | 4 +- .../pages/errorPage/errors/errorIndex.js | 40 +++++++++++++++++++ .../pages/errorPage/errors/errorIndex.json | 3 -- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 client/homebrew/pages/errorPage/errors/errorIndex.js delete mode 100644 client/homebrew/pages/errorPage/errors/errorIndex.json diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index 797d2e8e3..e1344b126 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -8,7 +8,7 @@ const UIPage = require('../basePages/uiPage/uiPage.jsx'); const Markdown = require('../../../../shared/naturalcrit/markdown.js'); -const ErrorIndex = require('./errors/errorIndex.json'); +const ErrorIndex = require('./errors/errorIndex.js'); const ErrorPage = createClass({ displayName : 'ErrorPage', @@ -23,7 +23,7 @@ const ErrorPage = createClass({ }, render : function(){ - const errorText = ErrorIndex[this.props.brew.status.toString()] || ''; + const errorText = ErrorIndex()[this.props.brew.status.toString()] || ''; return

{`Error ${this.props.brew.status || '000'}`}

diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js new file mode 100644 index 000000000..14421ad39 --- /dev/null +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -0,0 +1,40 @@ +const dedent = require('dedent-tabs').default; + +const errorIndex = () => { + return { + "404" : dedent` + ## We can't find this brew in your Google Drive! + + This error tells us your file was saved on your Google Drive, but the link + you tried to open doesn't work anymore. The Homebrewery cannot delete files + from your Google Drive on its own, so there are three most likely possibilities: + : + - **You may have accidentally deleted the Google Drive files.** Look on your Google Drive + and make sure the Homebrewery folder is still there, and that it holds your brews + as text files. + - **You may have changed the sharing settings for your files.** If the files + are still on Google Drive, change all of them to be shared **with everyone who has + the link** so the Homebrewery can access them. + - Rarely, it might mean that your Google Account is full or has been closed by + Google (for inactivity, violating some policy of theirs). Make sure you can still + access your Google Drive normally and upload/download files to it. + : + If you can't find it, Google Drive usually puts your file in your Trash folder for + 30 days. Assuming you didn't empty the trash right after, it might be worth checking. + You can also look on the right side of the page while logged into Google Drive and + look at the Activity tab. This can help you pin down the exact date the brew was + deleted and by whom. + : + If you *still* can't find it, some people have had success asking Google to recover + accidentally deleted files. You can visit this link + https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946. + At the bottom of the page there is a button that says **Send yourself an Email** + and you will receive instructions on how to request the files be restored. + : + Also note, if you prefer not to use your Google Drive for storage, you can always + change the storage location of a brew by clicking the Google drive icon by the + brew title and choosing **transfer my brew to/from Google Drive**.` + }; +}; + +module.exports = errorIndex; \ No newline at end of file diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.json b/client/homebrew/pages/errorPage/errors/errorIndex.json deleted file mode 100644 index 1d8fb35d5..000000000 --- a/client/homebrew/pages/errorPage/errors/errorIndex.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "404" : "## Your brew is not here.\n\nThis error tells us your file was saved on your Google Drive, but the link you tried to open doesn't work anymore. Since the Homebrewery cannot delete your your personal files from Google Drive without you clicking the delete button, there are three most likely possibilities:\n\n- You have accidentally deleted the Google Drive files. Look on your Google Drive and make sure the Homebrewery folder is still there, and that it holds your brews as text files.\n\n- You have accidentally changed the sharing settings for your files. If the files are still on Google Drive, change all of them to be shared **with everyone who has the link** so the Homebrewery can access them.\n\n- Rarely, it might mean that your Google Account is full or has been closed by Google (for inactivity, violating some policy of theirs). Make sure you can still access your Google Drive normally and upload/download files to it.\n\nIf you can't find it, Google Drive usually puts your file in your Trash folder for 30 days. Assuming you didn't empty the trash right after, it might be worth checking. You can also look on the right side of the page while logged into Google Drive and look at the Activity tab. This can help you pin down the exact date the brew was deleted and by whom.\n\nIf you still can't find it, some people have had success asking Google to recover accidentally deleted files. You can visit this link https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946.\n\nAt the bottom of the page there is a button that says **Send yourself an Email** and you will receive instructions on how to request the files be restored.\n\nAlso note, at no point are you 'forced' to save your files on Google Drive. You can always set any brew to be stored on your own Google Drive, or on the Homebrewery servers, by clicking the Google drive icon by the brew title and choosing **transfer my brew to/from Google Drive**." -} \ No newline at end of file From 2775614eab7a1354102e07ed86d0e37b993bbd7b Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 24 Jun 2023 01:46:44 -0400 Subject: [PATCH 08/44] Add styling to errorPage --- .../homebrew/pages/basePages/uiPage/uiPage.less | 17 ++++++++++++++++- client/homebrew/pages/errorPage/errorPage.jsx | 12 ++++++++---- client/homebrew/pages/errorPage/errorPage.less | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/client/homebrew/pages/basePages/uiPage/uiPage.less b/client/homebrew/pages/basePages/uiPage/uiPage.less index 9780b84ff..7760bbd74 100644 --- a/client/homebrew/pages/basePages/uiPage/uiPage.less +++ b/client/homebrew/pages/basePages/uiPage/uiPage.less @@ -1,6 +1,6 @@ .uiPage{ .content{ - overflow-y : hidden; + overflow-y : scroll; width : 90vw; background-color: #f0f0f0; font-family: 'Open Sans'; @@ -21,6 +21,7 @@ text-transform: uppercase; margin: 0.5em 30% 0.25em 0; border-bottom: 2px solid slategrey; + width: 100%; } h1 { font-size: 2em; @@ -43,5 +44,19 @@ strong { font-weight: bold; } + em { + font-style:italic; + } + ul { + padding-left: 1.25em; + list-style: square; + } + .blank { + height : 1em; + margin-top : 0; + & + * { + margin-top : 0; + } + } } } diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index e1344b126..4640a3ab4 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -26,10 +26,14 @@ const ErrorPage = createClass({ const errorText = ErrorIndex()[this.props.brew.status.toString()] || ''; return -

{`Error ${this.props.brew.status || '000'}`}

-

{this.props.brew.text || 'No error text'}

-
-
+
+
+

{`Error ${this.props.brew.status || '000'}`}

+

{this.props.brew.text || 'No error text'}

+
+
+
+
; } }); diff --git a/client/homebrew/pages/errorPage/errorPage.less b/client/homebrew/pages/errorPage/errorPage.less index 48ba0f93e..f9e5917d9 100644 --- a/client/homebrew/pages/errorPage/errorPage.less +++ b/client/homebrew/pages/errorPage/errorPage.less @@ -1,5 +1,15 @@ -.errorPage{ +.uiPage{ .errorTitle{ - background-color: @orange; + //background-color: @orange; + color: #d02727; + text-align: center; + } + .content { + h1, h2, h3, h4 { + border-bottom: none; + } + hr { + border-bottom: 2px solid slategrey; + } } } \ No newline at end of file From 66b9a792e74456a0c62a77f7b9c58a71b442f3d5 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 24 Jun 2023 01:47:07 -0400 Subject: [PATCH 09/44] Change Missing Google error text --- client/homebrew/pages/errorPage/errors/errorIndex.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 14421ad39..a97c3109a 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -13,9 +13,9 @@ const errorIndex = () => { and make sure the Homebrewery folder is still there, and that it holds your brews as text files. - **You may have changed the sharing settings for your files.** If the files - are still on Google Drive, change all of them to be shared **with everyone who has - the link** so the Homebrewery can access them. - - Rarely, it might mean that your Google Account is full or has been closed by + are still on Google Drive, change all of them to be shared *with everyone who has + the link* so the Homebrewery can access them. + - **Your Google Account may be full**, or may be have been closed by Google (for inactivity, violating some policy of theirs). Make sure you can still access your Google Drive normally and upload/download files to it. : @@ -26,14 +26,14 @@ const errorIndex = () => { deleted and by whom. : If you *still* can't find it, some people have had success asking Google to recover - accidentally deleted files. You can visit this link + accidentally deleted files at this link: https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946. - At the bottom of the page there is a button that says **Send yourself an Email** + At the bottom of the page there is a button that says *Send yourself an Email* and you will receive instructions on how to request the files be restored. : Also note, if you prefer not to use your Google Drive for storage, you can always change the storage location of a brew by clicking the Google drive icon by the - brew title and choosing **transfer my brew to/from Google Drive**.` + brew title and choosing *transfer my brew to/from Google Drive*.` }; }; From 6353341738165c7db960924a559b5a5f7c00e5fc Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 24 Jun 2023 01:50:57 -0400 Subject: [PATCH 10/44] styleLint --- .../pages/basePages/uiPage/uiPage.less | 84 ++++++++----------- .../homebrew/pages/errorPage/errorPage.less | 16 ++-- 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/client/homebrew/pages/basePages/uiPage/uiPage.less b/client/homebrew/pages/basePages/uiPage/uiPage.less index 7760bbd74..ee7738e87 100644 --- a/client/homebrew/pages/basePages/uiPage/uiPage.less +++ b/client/homebrew/pages/basePages/uiPage/uiPage.less @@ -1,62 +1,50 @@ -.uiPage{ - .content{ - overflow-y : scroll; - width : 90vw; - background-color: #f0f0f0; - font-family: 'Open Sans'; - margin-left: auto; - margin-right: auto; - margin-top: 25px; - padding: 2% 4%; - font-size: 0.8em; - line-height: 1.8em; - .dataGroup{ - padding: 6px 20px 15px; - border: 2px solid black; - border-radius: 5px; - margin: 5px 0px; +.uiPage { + .content { + width : 90vw; + padding : 2% 4%; + margin-top : 25px; + margin-right : auto; + margin-left : auto; + overflow-y : scroll; + font-family : 'Open Sans'; + font-size : 0.8em; + line-height : 1.8em; + background-color : #F0F0F0; + .dataGroup { + padding : 6px 20px 15px; + margin : 5px 0px; + border : 2px solid black; + border-radius : 5px; } - h1, h2, h3, h4{ - font-weight: 900; - text-transform: uppercase; - margin: 0.5em 30% 0.25em 0; - border-bottom: 2px solid slategrey; - width: 100%; + h1, h2, h3, h4 { + width : 100%; + margin : 0.5em 30% 0.25em 0; + font-weight : 900; + text-transform : uppercase; + border-bottom : 2px solid slategrey; } h1 { - font-size: 2em; - border-bottom: 2px solid darkslategrey; - margin-bottom: 0.5em; - margin-right: 0; - } - h2 { - font-size: 1.75em; + margin-right : 0; + margin-bottom : 0.5em; + font-size : 2em; + border-bottom : 2px solid darkslategrey; } + h2 { font-size : 1.75em; } h3 { - font-size: 1.5em; - svg { - width: 19px; - } - } - h4 { - font-size: 1.25em; - } - strong { - font-weight: bold; - } - em { - font-style:italic; + font-size : 1.5em; + svg { width : 19px; } } + h4 { font-size : 1.25em; } + strong { font-weight : bold; } + em { font-style : italic; } ul { - padding-left: 1.25em; - list-style: square; + padding-left : 1.25em; + list-style : square; } .blank { height : 1em; margin-top : 0; - & + * { - margin-top : 0; - } + & + * { margin-top : 0; } } } } diff --git a/client/homebrew/pages/errorPage/errorPage.less b/client/homebrew/pages/errorPage/errorPage.less index f9e5917d9..f6fd88a65 100644 --- a/client/homebrew/pages/errorPage/errorPage.less +++ b/client/homebrew/pages/errorPage/errorPage.less @@ -1,15 +1,11 @@ -.uiPage{ - .errorTitle{ +.uiPage { + .errorTitle { //background-color: @orange; - color: #d02727; - text-align: center; + color : #D02727; + text-align : center; } .content { - h1, h2, h3, h4 { - border-bottom: none; - } - hr { - border-bottom: 2px solid slategrey; - } + h1, h2, h3, h4 { border-bottom : none; } + hr { border-bottom : 2px solid slategrey; } } } \ No newline at end of file From f6c5354ce0e5ad34deb8deb5e30ee2b6dbd97f8f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 24 Jun 2023 02:57:03 -0400 Subject: [PATCH 11/44] Add support for custom HBErrorCodes --- client/homebrew/pages/errorPage/errorPage.jsx | 2 +- .../pages/errorPage/errors/errorIndex.js | 77 +++++++++++-------- server/app.js | 12 +-- server/homebrew.api.js | 4 +- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index 4640a3ab4..bc01887d1 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -23,7 +23,7 @@ const ErrorPage = createClass({ }, render : function(){ - const errorText = ErrorIndex()[this.props.brew.status.toString()] || ''; + const errorText = ErrorIndex()[this.props.brew.HBErrorCode.toString()] || ''; return
diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index a97c3109a..c9be104fe 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -1,39 +1,50 @@ const dedent = require('dedent-tabs').default; -const errorIndex = () => { +const errorIndex = ()=>{ return { - "404" : dedent` - ## We can't find this brew in your Google Drive! - - This error tells us your file was saved on your Google Drive, but the link - you tried to open doesn't work anymore. The Homebrewery cannot delete files - from your Google Drive on its own, so there are three most likely possibilities: - : - - **You may have accidentally deleted the Google Drive files.** Look on your Google Drive - and make sure the Homebrewery folder is still there, and that it holds your brews - as text files. - - **You may have changed the sharing settings for your files.** If the files - are still on Google Drive, change all of them to be shared *with everyone who has - the link* so the Homebrewery can access them. - - **Your Google Account may be full**, or may be have been closed by - Google (for inactivity, violating some policy of theirs). Make sure you can still - access your Google Drive normally and upload/download files to it. - : - If you can't find it, Google Drive usually puts your file in your Trash folder for - 30 days. Assuming you didn't empty the trash right after, it might be worth checking. - You can also look on the right side of the page while logged into Google Drive and - look at the Activity tab. This can help you pin down the exact date the brew was - deleted and by whom. - : - If you *still* can't find it, some people have had success asking Google to recover - accidentally deleted files at this link: - https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946. - At the bottom of the page there is a button that says *Send yourself an Email* - and you will receive instructions on how to request the files be restored. - : - Also note, if you prefer not to use your Google Drive for storage, you can always - change the storage location of a brew by clicking the Google drive icon by the - brew title and choosing *transfer my brew to/from Google Drive*.` + '00' : dedent` + ## An unknown error occurred! + + We aren't sure what happened, but our server wasn't able to find what you + were looking for.`, + + '01' : dedent` + ## An error occurred while retrieving this brew from Google Drive! + + Google reported an error while attempting to retrieve a brew from this link.`, + + '02' : dedent` + ## We can't find this brew in your Google Drive! + + This error tells us your file was saved on your Google Drive, but the link + you tried to open doesn't work anymore. The Homebrewery cannot delete files + from your Google Drive on its own, so there are three most likely possibilities: + : + - **You may have accidentally deleted the Google Drive files.** Look on your Google Drive + and make sure the Homebrewery folder is still there, and that it holds your brews + as text files. + - **You may have changed the sharing settings for your files.** If the files + are still on Google Drive, change all of them to be shared *with everyone who has + the link* so the Homebrewery can access them. + - **Your Google Account may be full**, or may be have been closed by + Google (for inactivity, violating some policy of theirs). Make sure you can still + access your Google Drive normally and upload/download files to it. + : + If you can't find it, Google Drive usually puts your file in your Trash folder for + 30 days. Assuming you didn't empty the trash right after, it might be worth checking. + You can also look on the right side of the page while logged into Google Drive and + look at the Activity tab. This can help you pin down the exact date the brew was + deleted and by whom. + : + If you *still* can't find it, some people have had success asking Google to recover + accidentally deleted files at this link: + https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946. + At the bottom of the page there is a button that says *Send yourself an Email* + and you will receive instructions on how to request the files be restored. + : + Also note, if you prefer not to use your Google Drive for storage, you can always + change the storage location of a brew by clicking the Google drive icon by the + brew title and choosing *transfer my brew to/from Google Drive*.` }; }; diff --git a/server/app.js b/server/app.js index 10f99ffaa..a30e3fdaf 100644 --- a/server/app.js +++ b/server/app.js @@ -413,7 +413,7 @@ if(isLocalEnvironment){ //Render the page const templateFn = require('./../client/template.js'); -const renderPage = async (req, res) => { +const renderPage = async (req, res)=>{ // Create configuration object const configuration = { local : isLocalEnvironment, @@ -468,14 +468,16 @@ app.use(async (err, req, res, next)=>{ const status = err.status || err.code || 500; console.error(err); - req.ogMeta = {...defaultMetaTags, + req.ogMeta = { ...defaultMetaTags, title : 'Error Page', description : 'Something went wrong!' }; req.brew = { - title : 'Error - Something went wrong!', - text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!', - status : status + title : 'Error - Something went wrong!', + text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!', + status : status, + HBErrorCode : err.HBErrorCode ?? '00', + pureError : getPureError(err) }; req.customUrl= '/error'; diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 2271466b8..516c1bc03 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -58,8 +58,8 @@ const api = { }); // Throw any error caught while attempting to retrieve Google brew. if(googleError) { - // console.log(googleError); - throw { ...new Error, ...googleError }; + const reason = googleError.errors[0].reason; + throw { ...Error, ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01' }; } // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew; From 853515e09ec27ec0f91f8b7d7e810b0ccafa14f5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 12:56:22 +1200 Subject: [PATCH 12/44] Switch Error gen from spread operator to func --- server/homebrew.api.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 516c1bc03..dd13d2274 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -68,14 +68,14 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { - throw { ...new Error, message : `The current logged in user does not have editor access to this brew. + throw Error(`The current logged in user does not have editor access to this brew. -If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.` }; +If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.`); } // If after all of that we still don't have a brew, throw an exception if(!stub && !stubOnly) { - throw { ...new Error, message: 'Brew not found in Homebrewery database or Google Drive' }; + throw Error('Brew not found in Homebrewery database or Google Drive'); } // Clean up brew: fill in missing fields with defaults / fix old invalid values @@ -184,7 +184,7 @@ If you believe you should have access to this brew, ask the file owner to invite saved = await newHomebrew.save() .catch((err)=>{ console.error(err, err.toString(), err.stack); - throw { ...new Error, message: `Error while creating new brew, ${err.toString()}` }; + throw Error(`Error while creating new brew, ${err.toString()}`); }); if(!saved) return; saved = saved.toObject(); @@ -311,7 +311,7 @@ If you believe you should have access to this brew, ask the file owner to invite await HomebrewModel.deleteOne({ _id: brew._id }) .catch((err)=>{ console.error(err); - throw { ...new Error, status: 500, message: 'Error while removing' }; + throw Error('Error while removing', { status: 500 }); }); } else { if(shouldDeleteGoogleBrew) { @@ -323,7 +323,7 @@ If you believe you should have access to this brew, ask the file owner to invite brew.markModified('authors'); //Mongo will not properly update arrays without markModified() await brew.save() .catch((err)=>{ - throw { ...new Error, status: 500, message: err }; + throw Error(err, { status: 500 }); }); } } From 7efe8964f11a69e70ba0b1249adb4747a81fb156 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 14:21:35 +1200 Subject: [PATCH 13/44] Change throw method, update HBErrors --- .../pages/errorPage/errors/errorIndex.js | 27 ++++++++++++++++++- server/homebrew.api.js | 14 +++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index c9be104fe..6700c8de0 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -44,7 +44,32 @@ const errorIndex = ()=>{ : Also note, if you prefer not to use your Google Drive for storage, you can always change the storage location of a brew by clicking the Google drive icon by the - brew title and choosing *transfer my brew to/from Google Drive*.` + brew title and choosing *transfer my brew to/from Google Drive*.`, + + '03' : dedent` + ## The current logged in user does not have editor access to this brew. + + If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.`, + + '04' : dedent` + ## No Homebrewery document could be found. + + The server could not locate the Homebrewery document.`, + + '05' : dedent` + ## Unable to save Homebrewery document. + + An error occurred wil attempting to save the Homebrewery document.`, + + '06' : dedent` + ## Unable to delete Homebrewery document. + + An error occurred while attempting to remove the Homebrewery document.`, + + '07' : dedent` + ## Unable to remove user from Homebrewery document. + + An error occurred while attempting to remove the current user from the Homebrewery document author list!` }; }; diff --git a/server/homebrew.api.js b/server/homebrew.api.js index dd13d2274..036a21c62 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -59,7 +59,7 @@ const api = { // Throw any error caught while attempting to retrieve Google brew. if(googleError) { const reason = googleError.errors[0].reason; - throw { ...Error, ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01' }; + throw { ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01' }; } // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew; @@ -68,14 +68,12 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { - throw Error(`The current logged in user does not have editor access to this brew. - -If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.`); + throw { name: 'Access Error', message: 'User is not an Author', status: 403, HBErrorCode: '03' }; } // If after all of that we still don't have a brew, throw an exception if(!stub && !stubOnly) { - throw Error('Brew not found in Homebrewery database or Google Drive'); + throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '04' }; } // Clean up brew: fill in missing fields with defaults / fix old invalid values @@ -184,7 +182,7 @@ If you believe you should have access to this brew, ask the file owner to invite saved = await newHomebrew.save() .catch((err)=>{ console.error(err, err.toString(), err.stack); - throw Error(`Error while creating new brew, ${err.toString()}`); + throw { name: 'BrewSave Error', message: `Error while creating new brew, ${err.toString()}`, status: 500, HBErrorCode: '05' }; }); if(!saved) return; saved = saved.toObject(); @@ -311,7 +309,7 @@ If you believe you should have access to this brew, ask the file owner to invite await HomebrewModel.deleteOne({ _id: brew._id }) .catch((err)=>{ console.error(err); - throw Error('Error while removing', { status: 500 }); + throw { name: 'BrewDelete Error', message: 'Error while removing', status: 500, HBErrorCode: '06' }; }); } else { if(shouldDeleteGoogleBrew) { @@ -323,7 +321,7 @@ If you believe you should have access to this brew, ask the file owner to invite brew.markModified('authors'); //Mongo will not properly update arrays without markModified() await brew.save() .catch((err)=>{ - throw Error(err, { status: 500 }); + throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '07' }; }); } } From 782aa8e6589d70badbb23ac2787efd44c88709a2 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 14:23:14 +1200 Subject: [PATCH 14/44] Increase ESLint max lines in app.js --- server/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/app.js b/server/app.js index a30e3fdaf..9861f2c5a 100644 --- a/server/app.js +++ b/server/app.js @@ -1,4 +1,4 @@ -/*eslint max-lines: ["warn", {"max": 400, "skipBlankLines": true, "skipComments": true}]*/ +/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/ // Set working directory to project root process.chdir(`${__dirname}/..`); From ffa240f78d4e44698b1b0d151e0324a926a4455b Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 14:39:42 +1200 Subject: [PATCH 15/44] Fix test --- server/homebrew.api.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 19dc1135c..13ea3ea22 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -125,7 +125,7 @@ describe('Tests for api', ()=>{ describe('getBrew', ()=>{ const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew })); - const notFoundError = 'Brew not found in Homebrewery database or Google Drive'; + const notFoundError = { HBErrorCode: '04', message: 'Brew not found', name: 'BrewLoad Error', status: 404 }; it('returns middleware', ()=>{ const getFn = api.getBrew('share'); @@ -162,7 +162,7 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual({ 'message': notFoundError }); + expect(err).toEqual(notFoundError); expect(req.brew).toEqual({}); expect(next).not.toHaveBeenCalled(); expect(api.getId).toHaveBeenCalledWith(req); From 438cb7f26ddff8a61fda7536c3de586673535d7f Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 14:41:15 +1200 Subject: [PATCH 16/44] Fix test --- server/homebrew.api.spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 13ea3ea22..158b4460f 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -197,9 +197,7 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual({ 'message' : `The current logged in user does not have editor access to this brew. - -If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.` }); + expect(err).toEqual({ HBErrorCode: '03', message: 'User is not an Author', name: 'Access Error', status: 403 }); }); it('does not throw if no authors', async ()=>{ From 0001cf16d911fa995fc49c51f3276f9f6a69efba Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 15:00:10 +1200 Subject: [PATCH 17/44] Change UIPage width calculation --- client/homebrew/pages/basePages/uiPage/uiPage.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/basePages/uiPage/uiPage.less b/client/homebrew/pages/basePages/uiPage/uiPage.less index ee7738e87..dc5957c48 100644 --- a/client/homebrew/pages/basePages/uiPage/uiPage.less +++ b/client/homebrew/pages/basePages/uiPage/uiPage.less @@ -1,6 +1,6 @@ .uiPage { .content { - width : 90vw; + width : min(90vw, 1000px); padding : 2% 4%; margin-top : 25px; margin-right : auto; From 4fdc6b79ea49b18c75b9e032d20b7930cf9a834b Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 15:11:12 +1200 Subject: [PATCH 18/44] Use Less var to not break server build process --- client/homebrew/pages/basePages/uiPage/uiPage.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/basePages/uiPage/uiPage.less b/client/homebrew/pages/basePages/uiPage/uiPage.less index dc5957c48..a4c6a75c9 100644 --- a/client/homebrew/pages/basePages/uiPage/uiPage.less +++ b/client/homebrew/pages/basePages/uiPage/uiPage.less @@ -1,6 +1,6 @@ .uiPage { .content { - width : min(90vw, 1000px); + width : ~"min(90vw, 1000px)"; padding : 2% 4%; margin-top : 25px; margin-right : auto; From 9ddae7bbea3e7fd8835da25226af6c4ce4263958 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 15:23:58 +1200 Subject: [PATCH 19/44] Update UIPage.less to increase specificity --- .../pages/basePages/uiPage/uiPage.less | 98 ++++++++++--------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/client/homebrew/pages/basePages/uiPage/uiPage.less b/client/homebrew/pages/basePages/uiPage/uiPage.less index a4c6a75c9..fc5ed583d 100644 --- a/client/homebrew/pages/basePages/uiPage/uiPage.less +++ b/client/homebrew/pages/basePages/uiPage/uiPage.less @@ -1,50 +1,52 @@ -.uiPage { - .content { - width : ~"min(90vw, 1000px)"; - padding : 2% 4%; - margin-top : 25px; - margin-right : auto; - margin-left : auto; - overflow-y : scroll; - font-family : 'Open Sans'; - font-size : 0.8em; - line-height : 1.8em; - background-color : #F0F0F0; - .dataGroup { - padding : 6px 20px 15px; - margin : 5px 0px; - border : 2px solid black; - border-radius : 5px; - } - h1, h2, h3, h4 { - width : 100%; - margin : 0.5em 30% 0.25em 0; - font-weight : 900; - text-transform : uppercase; - border-bottom : 2px solid slategrey; - } - h1 { - margin-right : 0; - margin-bottom : 0.5em; - font-size : 2em; - border-bottom : 2px solid darkslategrey; - } - h2 { font-size : 1.75em; } - h3 { - font-size : 1.5em; - svg { width : 19px; } - } - h4 { font-size : 1.25em; } - strong { font-weight : bold; } - em { font-style : italic; } - ul { - padding-left : 1.25em; - list-style : square; - } - .blank { - height : 1em; - margin-top : 0; - & + * { margin-top : 0; } +.homebrew { + .uiPage.sitePage { + .content { + width : ~"min(90vw, 1000px)"; + padding : 2% 4%; + margin-top : 25px; + margin-right : auto; + margin-left : auto; + overflow-y : scroll; + font-family : 'Open Sans'; + font-size : 0.8em; + line-height : 1.8em; + background-color : #F0F0F0; + .dataGroup { + padding : 6px 20px 15px; + margin : 5px 0px; + border : 2px solid black; + border-radius : 5px; + } + h1, h2, h3, h4 { + width : 100%; + margin : 0.5em 30% 0.25em 0; + font-weight : 900; + text-transform : uppercase; + border-bottom : 2px solid slategrey; + } + h1 { + margin-right : 0; + margin-bottom : 0.5em; + font-size : 2em; + border-bottom : 2px solid darkslategrey; + } + h2 { font-size : 1.75em; } + h3 { + font-size : 1.5em; + svg { width : 19px; } + } + h4 { font-size : 1.25em; } + strong { font-weight : bold; } + em { font-style : italic; } + ul { + padding-left : 1.25em; + list-style : square; + } + .blank { + height : 1em; + margin-top : 0; + & + * { margin-top : 0; } + } } } -} +} \ No newline at end of file From 9de4a829779cabba602e90854d4dc979077675f4 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 15:24:10 +1200 Subject: [PATCH 20/44] Remove unneeded HR --- client/homebrew/pages/errorPage/errorPage.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index bc01887d1..e1414f666 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -31,7 +31,6 @@ const ErrorPage = createClass({

{`Error ${this.props.brew.status || '000'}`}

{this.props.brew.text || 'No error text'}

-
; From d1412abe03731a554de9b67a74304659048496f1 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 16:48:50 +1200 Subject: [PATCH 21/44] Increase specificity of ErrorPage.less --- client/homebrew/pages/errorPage/errorPage.jsx | 1 + .../homebrew/pages/errorPage/errorPage.less | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index e1414f666..bc01887d1 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -31,6 +31,7 @@ const ErrorPage = createClass({

{`Error ${this.props.brew.status || '000'}`}

{this.props.brew.text || 'No error text'}

+
; diff --git a/client/homebrew/pages/errorPage/errorPage.less b/client/homebrew/pages/errorPage/errorPage.less index f6fd88a65..2d10301e0 100644 --- a/client/homebrew/pages/errorPage/errorPage.less +++ b/client/homebrew/pages/errorPage/errorPage.less @@ -1,11 +1,13 @@ -.uiPage { - .errorTitle { - //background-color: @orange; - color : #D02727; - text-align : center; - } - .content { - h1, h2, h3, h4 { border-bottom : none; } - hr { border-bottom : 2px solid slategrey; } +.homebrew { + .uiPage.sitePage { + .errorTitle { + //background-color: @orange; + color : #D02727; + text-align : center; + } + .content { + h1, h2, h3, h4 { border-bottom : none; } + hr { border-bottom : 2px solid slategrey; } + } } } \ No newline at end of file From da8e7ec61013811c7f7dcfd89d63cf033318fa15 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 16:51:17 +1200 Subject: [PATCH 22/44] Change Not an Author to 401 --- server/homebrew.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 036a21c62..978fc1350 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -68,7 +68,7 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { - throw { name: 'Access Error', message: 'User is not an Author', status: 403, HBErrorCode: '03' }; + throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03' }; } // If after all of that we still don't have a brew, throw an exception From e5ef0aedd37f6b10cea9de7edf3c31b1eeb5f0ec Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 17:10:25 +1200 Subject: [PATCH 23/44] Pass all error properties to message generator --- client/homebrew/pages/errorPage/errorPage.jsx | 2 +- client/homebrew/pages/errorPage/errors/errorIndex.js | 11 +++++++++-- server/app.js | 1 + server/homebrew.api.js | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/homebrew/pages/errorPage/errorPage.jsx b/client/homebrew/pages/errorPage/errorPage.jsx index bc01887d1..33da05017 100644 --- a/client/homebrew/pages/errorPage/errorPage.jsx +++ b/client/homebrew/pages/errorPage/errorPage.jsx @@ -23,7 +23,7 @@ const ErrorPage = createClass({ }, render : function(){ - const errorText = ErrorIndex()[this.props.brew.HBErrorCode.toString()] || ''; + const errorText = ErrorIndex(this.props)[this.props.brew.HBErrorCode.toString()] || ''; return
diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 6700c8de0..324b2f6d0 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -1,6 +1,6 @@ const dedent = require('dedent-tabs').default; -const errorIndex = ()=>{ +const errorIndex = (props)=>{ return { '00' : dedent` ## An unknown error occurred! @@ -49,7 +49,14 @@ const errorIndex = ()=>{ '03' : dedent` ## The current logged in user does not have editor access to this brew. - If you believe you should have access to this brew, ask the file owner to invite you as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again.`, + If you believe you should have access to this brew, ask the file owner to invite you + as an author by opening the brew, viewing the Properties tab, and adding your username + to the "invited authors" list. You can then try to access this document again. + + Current Authors: + + ${props.brew.authors?.map((author)=>{return `- ${author}`;}).join('\n') || 'Unable to list authors'} + `, '04' : dedent` ## No Homebrewery document could be found. diff --git a/server/app.js b/server/app.js index 9861f2c5a..901349d97 100644 --- a/server/app.js +++ b/server/app.js @@ -473,6 +473,7 @@ app.use(async (err, req, res, next)=>{ description : 'Something went wrong!' }; req.brew = { + ...err, title : 'Error - Something went wrong!', text : err.errors?.map((error)=>{return error.message;}).join('\n\n') || err.message || 'Unknown error!', status : status, diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 978fc1350..7107cfbe3 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -68,7 +68,7 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { - throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03' }; + throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03', authors: stub.authors }; } // If after all of that we still don't have a brew, throw an exception From 4c6de90d829d038ef6b3a1611b1918566b920a85 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 17:13:37 +1200 Subject: [PATCH 24/44] Fix test --- server/homebrew.api.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 158b4460f..27ae64949 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -197,7 +197,7 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual({ HBErrorCode: '03', message: 'User is not an Author', name: 'Access Error', status: 403 }); + expect(err).toEqual({ HBErrorCode: '03', authors: ['a'], message: 'User is not an Author', name: 'Access Error', status: 401 }); }); it('does not throw if no authors', async ()=>{ From e28b6e7a1926e88041ab8b4175b2128878f9a43e Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 18:10:31 +1200 Subject: [PATCH 25/44] Differentiate Not an Author from Not logged in --- .../homebrew/pages/errorPage/errors/errorIndex.js | 15 +++++++++++---- server/homebrew.api.js | 13 ++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 324b2f6d0..1293858d2 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -1,5 +1,7 @@ const dedent = require('dedent-tabs').default; +const loginUrl = 'https://www.naturalcrit.com/login'; + const errorIndex = (props)=>{ return { '00' : dedent` @@ -59,24 +61,29 @@ const errorIndex = (props)=>{ `, '04' : dedent` + ## Not logged in + + User is not logged in. Please log in [here](${loginUrl}).`, + + '05' : dedent` ## No Homebrewery document could be found. The server could not locate the Homebrewery document.`, - '05' : dedent` + '06' : dedent` ## Unable to save Homebrewery document. An error occurred wil attempting to save the Homebrewery document.`, - '06' : dedent` + '07' : dedent` ## Unable to delete Homebrewery document. An error occurred while attempting to remove the Homebrewery document.`, - '07' : dedent` + '08' : dedent` ## Unable to remove user from Homebrewery document. - An error occurred while attempting to remove the current user from the Homebrewery document author list!` + An error occurred while attempting to remove the current user from the Homebrewery document author list!`, }; }; diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 7107cfbe3..3fbe696e9 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -68,12 +68,15 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { - throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03', authors: stub.authors }; + if(req.account){ + throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03', authors: stub.authors }; + } + throw { name: 'Access Error', message: 'User is not logged in', status: 401, HBErrorCode: '04' }; } // If after all of that we still don't have a brew, throw an exception if(!stub && !stubOnly) { - throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '04' }; + throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '05' }; } // Clean up brew: fill in missing fields with defaults / fix old invalid values @@ -182,7 +185,7 @@ const api = { saved = await newHomebrew.save() .catch((err)=>{ console.error(err, err.toString(), err.stack); - throw { name: 'BrewSave Error', message: `Error while creating new brew, ${err.toString()}`, status: 500, HBErrorCode: '05' }; + throw { name: 'BrewSave Error', message: `Error while creating new brew, ${err.toString()}`, status: 500, HBErrorCode: '06' }; }); if(!saved) return; saved = saved.toObject(); @@ -309,7 +312,7 @@ const api = { await HomebrewModel.deleteOne({ _id: brew._id }) .catch((err)=>{ console.error(err); - throw { name: 'BrewDelete Error', message: 'Error while removing', status: 500, HBErrorCode: '06' }; + throw { name: 'BrewDelete Error', message: 'Error while removing', status: 500, HBErrorCode: '07' }; }); } else { if(shouldDeleteGoogleBrew) { @@ -321,7 +324,7 @@ const api = { brew.markModified('authors'); //Mongo will not properly update arrays without markModified() await brew.save() .catch((err)=>{ - throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '07' }; + throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '08' }; }); } } From 800bff611a9c470a16c2f043727903aafaa542bd Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 18:14:12 +1200 Subject: [PATCH 26/44] Fix test --- server/homebrew.api.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 27ae64949..ce22854d4 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -197,7 +197,7 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual({ HBErrorCode: '03', authors: ['a'], message: 'User is not an Author', name: 'Access Error', status: 401 }); + expect(err).toEqual({ HBErrorCode: '04', message: 'User is not logged in', name: 'Access Error', status: 401 }); }); it('does not throw if no authors', async ()=>{ From 9f4de3c66ee2c0f62d8635af25eff8ab1058b46f Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 18:16:57 +1200 Subject: [PATCH 27/44] Fix test --- server/homebrew.api.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index ce22854d4..3ae275d38 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -125,7 +125,7 @@ describe('Tests for api', ()=>{ describe('getBrew', ()=>{ const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew })); - const notFoundError = { HBErrorCode: '04', message: 'Brew not found', name: 'BrewLoad Error', status: 404 }; + const notFoundError = { HBErrorCode: '05', message: 'Brew not found', name: 'BrewLoad Error', status: 404 }; it('returns middleware', ()=>{ const getFn = api.getBrew('share'); From f175323221ae9d9d291250a3f2343437b1a53fc5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 18:22:22 +1200 Subject: [PATCH 28/44] Use common error object to reduce DRY --- server/homebrew.api.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 3fbe696e9..4c4f10705 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -68,10 +68,11 @@ const api = { const isAuthor = stub?.authors?.includes(req.account?.username); const isInvited = stub?.invitedAuthors?.includes(req.account?.username); if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { + const accessError = { name: 'Access Error', status: 401 }; if(req.account){ - throw { name: 'Access Error', message: 'User is not an Author', status: 401, HBErrorCode: '03', authors: stub.authors }; + throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03', authors: stub.authors }; } - throw { name: 'Access Error', message: 'User is not logged in', status: 401, HBErrorCode: '04' }; + throw { ...accessError, message: 'User is not logged in', HBErrorCode: '04' }; } // If after all of that we still don't have a brew, throw an exception From 04eb7d05567b1d5b3b90ea6fa38d90ff5b06cb15 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 20:13:13 +1200 Subject: [PATCH 29/44] Add brew title to Not an Author page --- client/homebrew/pages/errorPage/errors/errorIndex.js | 4 +++- server/homebrew.api.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 1293858d2..71326190d 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -55,7 +55,9 @@ const errorIndex = (props)=>{ as an author by opening the brew, viewing the Properties tab, and adding your username to the "invited authors" list. You can then try to access this document again. - Current Authors: + **Brew Title:** ${props.brew.brewTitle || 'Unable to show title'} + + **Current Authors:** ${props.brew.authors?.map((author)=>{return `- ${author}`;}).join('\n') || 'Unable to list authors'} `, diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 4c4f10705..462a089b5 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -70,7 +70,7 @@ const api = { if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) { const accessError = { name: 'Access Error', status: 401 }; if(req.account){ - throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03', authors: stub.authors }; + throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03', authors: stub.authors, brewTitle: stub.title }; } throw { ...accessError, message: 'User is not logged in', HBErrorCode: '04' }; } From fa38d5c892aa4c0da765c56b1ddb250269ea45e5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 20:39:36 +1200 Subject: [PATCH 30/44] Additional info in errors --- .../pages/errorPage/errors/errorIndex.js | 26 ++++++++++++++++--- server/homebrew.api.js | 6 ++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 71326190d..7a9dd4d2b 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -4,17 +4,20 @@ const loginUrl = 'https://www.naturalcrit.com/login'; const errorIndex = (props)=>{ return { + // Default catch all '00' : dedent` ## An unknown error occurred! We aren't sure what happened, but our server wasn't able to find what you were looking for.`, + // General Google load error '01' : dedent` ## An error occurred while retrieving this brew from Google Drive! Google reported an error while attempting to retrieve a brew from this link.`, + // Google Drive - 404 : brew deleted or access denied '02' : dedent` ## We can't find this brew in your Google Drive! @@ -48,6 +51,7 @@ const errorIndex = (props)=>{ change the storage location of a brew by clicking the Google drive icon by the brew title and choosing *transfer my brew to/from Google Drive*.`, + // User is not Authors list '03' : dedent` ## The current logged in user does not have editor access to this brew. @@ -62,30 +66,46 @@ const errorIndex = (props)=>{ ${props.brew.authors?.map((author)=>{return `- ${author}`;}).join('\n') || 'Unable to list authors'} `, + // User is not logged in '04' : dedent` ## Not logged in User is not logged in. Please log in [here](${loginUrl}).`, + // Brew load error '05' : dedent` ## No Homebrewery document could be found. - The server could not locate the Homebrewery document.`, + The server could not locate the Homebrewery document. + + **Requested access:** ${props.brew.accessType} + **Brew ID:** ${props.brew.brewId} + `, + + // Brew save error '06' : dedent` ## Unable to save Homebrewery document. An error occurred wil attempting to save the Homebrewery document.`, + // Brew delete error '07' : dedent` ## Unable to delete Homebrewery document. - An error occurred while attempting to remove the Homebrewery document.`, + An error occurred while attempting to remove the Homebrewery document. + + **Brew ID:** ${props.brew.brewId} + `, + // Author delete error '08' : dedent` ## Unable to remove user from Homebrewery document. - An error occurred while attempting to remove the current user from the Homebrewery document author list!`, + An error occurred while attempting to remove the user from the Homebrewery document author list! + + **Brew ID:** ${props.brew.brewId} + `, }; }; diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 462a089b5..63057d200 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -77,7 +77,7 @@ const api = { // If after all of that we still don't have a brew, throw an exception if(!stub && !stubOnly) { - throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '05' }; + throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '05', accessType: accessType, brewId: id }; } // Clean up brew: fill in missing fields with defaults / fix old invalid values @@ -313,7 +313,7 @@ const api = { await HomebrewModel.deleteOne({ _id: brew._id }) .catch((err)=>{ console.error(err); - throw { name: 'BrewDelete Error', message: 'Error while removing', status: 500, HBErrorCode: '07' }; + throw { name: 'BrewDelete Error', message: 'Error while removing', status: 500, HBErrorCode: '07', brewId: brew._id }; }); } else { if(shouldDeleteGoogleBrew) { @@ -325,7 +325,7 @@ const api = { brew.markModified('authors'); //Mongo will not properly update arrays without markModified() await brew.save() .catch((err)=>{ - throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '08' }; + throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '08', brewId: brew._id }; }); } } From 4799e8b443d80f62c98433edf794397f10b73fce Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 21:10:28 +1200 Subject: [PATCH 31/44] Fix test --- server/homebrew.api.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 3ae275d38..0c46b1488 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -125,7 +125,7 @@ describe('Tests for api', ()=>{ describe('getBrew', ()=>{ const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew })); - const notFoundError = { HBErrorCode: '05', message: 'Brew not found', name: 'BrewLoad Error', status: 404 }; + const notFoundError = { HBErrorCode: '05', message: 'Brew not found', name: 'BrewLoad Error', status: 404, accessType: 'share', brewId: '1' }; it('returns middleware', ()=>{ const getFn = api.getBrew('share'); From cff4f8eae567e736208106f7415e7623d424fd8a Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 25 Jun 2023 21:26:02 +1200 Subject: [PATCH 32/44] Catch duplicate delete requests --- server/homebrew.api.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 63057d200..d8e3318fa 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -288,10 +288,13 @@ const api = { try { await api.getBrew('edit')(req, res, ()=>{}); } catch (err) { - const { id, googleId } = api.getId(req); - console.warn(`No google brew found for id ${googleId}, the stub with id ${id} will be deleted.`); - await HomebrewModel.deleteOne({ editId: id }); - return next(); + // Only if the error code is HBErrorCode '02', that is, Google returned "404 - Not Found" + if(err.HBErrorCode == '02') { + const { id, googleId } = api.getId(req); + console.warn(`No google brew found for id ${googleId}, the stub with id ${id} will be deleted.`); + await HomebrewModel.deleteOne({ editId: id }); + return next(); + } } let brew = req.brew; From f3c36ffb0a1ba15fa99adcc2bed5cfad83ea1804 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Jun 2023 03:56:53 +0000 Subject: [PATCH 33/44] Bump stylelint from 15.8.0 to 15.9.0 Bumps [stylelint](https://github.com/stylelint/stylelint) from 15.8.0 to 15.9.0. - [Release notes](https://github.com/stylelint/stylelint/releases) - [Changelog](https://github.com/stylelint/stylelint/blob/main/CHANGELOG.md) - [Commits](https://github.com/stylelint/stylelint/compare/15.8.0...15.9.0) --- updated-dependencies: - dependency-name: stylelint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index fe818bf2b..37fd9ea4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "jest": "^29.5.0", "jest-expect-message": "^1.1.3", "postcss-less": "^6.0.0", - "stylelint": "^15.8.0", + "stylelint": "^15.9.0", "stylelint-config-recess-order": "^4.2.0", "stylelint-config-recommended": "^12.0.0", "stylelint-stylistic": "^0.4.2", @@ -15736,9 +15736,9 @@ "dev": true }, "node_modules/stylelint": { - "version": "15.8.0", - "resolved": "https://registry.npmjs.org/stylelint/-/stylelint-15.8.0.tgz", - "integrity": "sha512-x9qBk84F3MEjMEUNCE7MtWmfj9G9y5XzJ0cpQeJdy2l/IoqjC8Ih0N0ytmOTnXE4Yv0J7I1cmVRQUVNSPCxTsA==", + "version": "15.9.0", + "resolved": "https://registry.npmjs.org/stylelint/-/stylelint-15.9.0.tgz", + "integrity": "sha512-sXtAZi64CllWr6A+8ymDWnlIaYwuAa7XRmGnJxLQXFNnLjd3Izm4HAD+loKVaZ7cpK6SLxhAUX1lwPJKGCn0mg==", "dev": true, "dependencies": { "@csstools/css-parser-algorithms": "^2.2.0", diff --git a/package.json b/package.json index 8814b457d..e2e8da2f8 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "jest": "^29.5.0", "jest-expect-message": "^1.1.3", "postcss-less": "^6.0.0", - "stylelint": "^15.8.0", + "stylelint": "^15.9.0", "stylelint-config-recess-order": "^4.2.0", "stylelint-config-recommended": "^12.0.0", "stylelint-stylistic": "^0.4.2", From 10e14bfcfd7be7ac366672b5d490f20573db9d71 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Jun 2023 03:57:17 +0000 Subject: [PATCH 34/44] Bump react-router-dom from 6.13.0 to 6.14.0 Bumps [react-router-dom](https://github.com/remix-run/react-router/tree/HEAD/packages/react-router-dom) from 6.13.0 to 6.14.0. - [Release notes](https://github.com/remix-run/react-router/releases) - [Changelog](https://github.com/remix-run/react-router/blob/react-router-dom@6.14.0/packages/react-router-dom/CHANGELOG.md) - [Commits](https://github.com/remix-run/react-router/commits/react-router-dom@6.14.0/packages/react-router-dom) --- updated-dependencies: - dependency-name: react-router-dom dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 26 +++++++++++++------------- package.json | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index fe818bf2b..9c1f0362d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "react": "^17.0.2", "react-dom": "^17.0.2", "react-frame-component": "^4.1.3", - "react-router-dom": "6.13.0", + "react-router-dom": "6.14.0", "sanitize-filename": "1.6.3", "superagent": "^6.1.0", "vitreum": "git+https://git@github.com/calculuschild/vitreum.git" @@ -2810,9 +2810,9 @@ } }, "node_modules/@remix-run/router": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.6.3.tgz", - "integrity": "sha512-EXJysQ7J3veRECd0kZFQwYYd5sJMcq2O/m60zu1W2l3oVQ9xtub8jTOtYRE0+M2iomyG/W3Ps7+vp2kna0C27Q==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.7.0.tgz", + "integrity": "sha512-Eu1V3kz3mV0wUpVTiFHuaT8UD1gj/0VnoFHQYX35xlslQUpe8CuYoKFn9d4WZFHm3yDywz6ALZuGdnUPKrNeAw==", "engines": { "node": ">=14" } @@ -14284,11 +14284,11 @@ "dev": true }, "node_modules/react-router": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.13.0.tgz", - "integrity": "sha512-Si6KnfEnJw7gUQkNa70dlpI1bul46FuSxX5t5WwlUBxE25DAz2BjVkwaK8Y2s242bQrZPXCpmwLPtIO5pv4tXg==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.14.0.tgz", + "integrity": "sha512-OD+vkrcGbvlwkspUFDgMzsu1RXwdjNh83YgG/28lBnDzgslhCgxIqoExLlxsfTpIygp7fc+Hd3esloNwzkm2xA==", "dependencies": { - "@remix-run/router": "1.6.3" + "@remix-run/router": "1.7.0" }, "engines": { "node": ">=14" @@ -14298,12 +14298,12 @@ } }, "node_modules/react-router-dom": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.13.0.tgz", - "integrity": "sha512-6Nqoqd7fgwxxVGdbiMHTpDHCYPq62d7Wk1Of7B82vH7ZPwwsRaIa22zRZKPPg413R5REVNiyuQPKDG1bubcOFA==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.14.0.tgz", + "integrity": "sha512-YEwlApKwzMMMbGbhh+Q7MsloTldcwMgHxUY/1g0uA62+B1hZo2jsybCWIDCL8zvIDB1FA0pBKY9chHbZHt+2dQ==", "dependencies": { - "@remix-run/router": "1.6.3", - "react-router": "6.13.0" + "@remix-run/router": "1.7.0", + "react-router": "6.14.0" }, "engines": { "node": ">=14" diff --git a/package.json b/package.json index 8814b457d..986d65ed1 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "react": "^17.0.2", "react-dom": "^17.0.2", "react-frame-component": "^4.1.3", - "react-router-dom": "6.13.0", + "react-router-dom": "6.14.0", "sanitize-filename": "1.6.3", "superagent": "^6.1.0", "vitreum": "git+https://git@github.com/calculuschild/vitreum.git" From c5f4793c23805fe2ba32dc98daa15c422ba280ee Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 26 Jun 2023 17:43:19 +1200 Subject: [PATCH 35/44] Add owner info to missing Google file message --- client/homebrew/pages/errorPage/errors/errorIndex.js | 3 ++- server/homebrew.api.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 7a9dd4d2b..1fdce66b9 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -25,7 +25,8 @@ const errorIndex = (props)=>{ you tried to open doesn't work anymore. The Homebrewery cannot delete files from your Google Drive on its own, so there are three most likely possibilities: : - - **You may have accidentally deleted the Google Drive files.** Look on your Google Drive + - **You may have accidentally deleted the Google Drive files.** Look on + ${props.brew.authors?.length > 0 ? `the Google Drive account associated with the **${props.brew.authors[0]}** Homebrewery account` : 'your Google Drive account'} and make sure the Homebrewery folder is still there, and that it holds your brews as text files. - **You may have changed the sharing settings for your files.** If the files diff --git a/server/homebrew.api.js b/server/homebrew.api.js index d8e3318fa..4c6961b5a 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -59,7 +59,7 @@ const api = { // Throw any error caught while attempting to retrieve Google brew. if(googleError) { const reason = googleError.errors[0].reason; - throw { ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01' }; + throw { ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01', authors: stub?.authors }; } // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew; From 3d47b5a0bcade6a8dafbd5e55bd27fcb6076c214 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 26 Jun 2023 18:06:37 +1200 Subject: [PATCH 36/44] Fix test --- server/homebrew.api.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 0c46b1488..464661441 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -544,7 +544,7 @@ brew`); describe('deleteBrew', ()=>{ it('should handle case where fetching the brew returns an error', async ()=>{ api.getBrew = jest.fn(()=>async ()=>{ throw 'err'; }); - api.getId = jest.fn(()=>({ id: '1', googleId: '2' })); + api.getId = jest.fn(()=>({ id: '1', googleId: '2', HBErrorCode: '02' })); model.deleteOne = jest.fn(async ()=>{}); const next = jest.fn(()=>{}); From a3b2c6987f47b26ceabce42638847b7e26748bd1 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 26 Jun 2023 18:08:52 +1200 Subject: [PATCH 37/44] Fix test --- server/homebrew.api.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 464661441..cc940f52b 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -543,8 +543,8 @@ brew`); describe('deleteBrew', ()=>{ it('should handle case where fetching the brew returns an error', async ()=>{ - api.getBrew = jest.fn(()=>async ()=>{ throw 'err'; }); - api.getId = jest.fn(()=>({ id: '1', googleId: '2', HBErrorCode: '02' })); + api.getBrew = jest.fn(()=>async ()=>{ throw {message: 'err', HBErrorCode: '02' }; }); + api.getId = jest.fn(()=>({ id: '1', googleId: '2' })); model.deleteOne = jest.fn(async ()=>{}); const next = jest.fn(()=>{}); From e88e7f852c7fefd917946887ce51950538475cb4 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 26 Jun 2023 20:40:11 +1200 Subject: [PATCH 38/44] Add account check to Google File not found error --- .../pages/errorPage/errors/errorIndex.js | 21 +++++++++++++------ server/homebrew.api.js | 2 +- server/homebrew.api.spec.js | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 1fdce66b9..ded15c99a 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -19,14 +19,23 @@ const errorIndex = (props)=>{ // Google Drive - 404 : brew deleted or access denied '02' : dedent` - ## We can't find this brew in your Google Drive! + ## We can't find this brew in Google Drive! - This error tells us your file was saved on your Google Drive, but the link - you tried to open doesn't work anymore. The Homebrewery cannot delete files - from your Google Drive on its own, so there are three most likely possibilities: + This error tells us the file was saved on Google Drive, but the link + you have tried to open doesn't work anymore. The Homebrewery cannot delete files + from Google Drive on its own, so there are three most likely possibilities: : - - **You may have accidentally deleted the Google Drive files.** Look on - ${props.brew.authors?.length > 0 ? `the Google Drive account associated with the **${props.brew.authors[0]}** Homebrewery account` : 'your Google Drive account'} + - **The Google Drive files may have been accidentally deleted.** Look in + ${props.brew.authors?.length > 0 + && + (props.brew.authors[0] == props.brew.account + ? 'your Google Drive account' + : dedent`the Google Drive account associated with the + **${props.brew.authors[0]}** Homebrewery account - you + are currently logged in with the **${props.brew.account}** + account -`) + || + 'your Google Drive account'} and make sure the Homebrewery folder is still there, and that it holds your brews as text files. - **You may have changed the sharing settings for your files.** If the files diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 4c6961b5a..f82a9b642 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -59,7 +59,7 @@ const api = { // Throw any error caught while attempting to retrieve Google brew. if(googleError) { const reason = googleError.errors[0].reason; - throw { ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01', authors: stub?.authors }; + throw { ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01', authors: stub?.authors, account: req.account.username }; } // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew; diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index cc940f52b..214faccf9 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -543,7 +543,7 @@ brew`); describe('deleteBrew', ()=>{ it('should handle case where fetching the brew returns an error', async ()=>{ - api.getBrew = jest.fn(()=>async ()=>{ throw {message: 'err', HBErrorCode: '02' }; }); + api.getBrew = jest.fn(()=>async ()=>{ throw { message: 'err', HBErrorCode: '02' }; }); api.getId = jest.fn(()=>({ id: '1', googleId: '2' })); model.deleteOne = jest.fn(async ()=>{}); const next = jest.fn(()=>{}); From c0164dce6a077a4230ba618d4c6488bbe31200ee Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 26 Jun 2023 17:02:28 -0400 Subject: [PATCH 39/44] Fix for username undefined (not logged in) --- server/homebrew.api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index f82a9b642..9e00b46b2 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -59,7 +59,12 @@ const api = { // Throw any error caught while attempting to retrieve Google brew. if(googleError) { const reason = googleError.errors[0].reason; - throw { ...googleError, HBErrorCode: reason == 'notFound' ? '02' : '01', authors: stub?.authors, account: req.account.username }; + if(reason == 'notFound') { + throw { ...googleError, HBErrorCode: '02', authors: stub?.authors, account: req.account?.username }; + } + else { + throw { ...googleError, HBErrorCode: '01'}; + } } // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew stub = stub ? _.assign({ ...api.excludeStubProps(stub), stubbed: true }, api.excludeGoogleProps(googleBrew)) : googleBrew; From d0de7ca28cacfe7c0eabfb04028a99ce10dd2933 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 26 Jun 2023 22:48:58 -0400 Subject: [PATCH 40/44] Rephrasing of error texts --- .../pages/errorPage/errors/errorIndex.js | 86 ++++++++++--------- server/homebrew.api.js | 4 +- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index ded15c99a..5bde0b0b3 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -21,37 +21,40 @@ const errorIndex = (props)=>{ '02' : dedent` ## We can't find this brew in Google Drive! - This error tells us the file was saved on Google Drive, but the link - you have tried to open doesn't work anymore. The Homebrewery cannot delete files - from Google Drive on its own, so there are three most likely possibilities: + This file was saved on Google Drive, but this link doesn't work anymore. + ${ props.brew.authors?.length > 0 + ? `Note that this brew belongs to the Homebrewery account **${ props.brew.authors[0] }**, + ${ props.brew.account + ? `which is + ${props.brew.authors[0] == props.brew.account + ? `your account.` + : `not your account (you are currently signed in as **${props.brew.account}**).` + }` + : 'and you are not currently signed in to any account.' + }` + : '' + } + The Homebrewery cannot delete files from Google Drive on its own, so there + are three most likely possibilities: : - - **The Google Drive files may have been accidentally deleted.** Look in - ${props.brew.authors?.length > 0 - && - (props.brew.authors[0] == props.brew.account - ? 'your Google Drive account' - : dedent`the Google Drive account associated with the - **${props.brew.authors[0]}** Homebrewery account - you - are currently logged in with the **${props.brew.account}** - account -`) - || - 'your Google Drive account'} + - **The Google Drive files may have been accidentally deleted.** Look in + the Google Drive account that owns this brew (or ask the owner to do so), and make sure the Homebrewery folder is still there, and that it holds your brews as text files. - **You may have changed the sharing settings for your files.** If the files are still on Google Drive, change all of them to be shared *with everyone who has the link* so the Homebrewery can access them. - - **Your Google Account may be full**, or may be have been closed by - Google (for inactivity, violating some policy of theirs). Make sure you can still - access your Google Drive normally and upload/download files to it. + - **The Google Drive may be full**, or may be have been closed by + Google (for inactivity, violating some policy of theirs). Make sure the owner can + still access Google Drive normally and upload/download files to it. : - If you can't find it, Google Drive usually puts your file in your Trash folder for - 30 days. Assuming you didn't empty the trash right after, it might be worth checking. - You can also look on the right side of the page while logged into Google Drive and - look at the Activity tab. This can help you pin down the exact date the brew was - deleted and by whom. + If the file isn't found, Google Drive usually puts your file in your Trash folder for + 30 days. Assuming the trash hasn't been emptied yet, it might be worth checking. + You can also find the Activity tab on the right side of the Google Drive page, which + shows the recent activity on Google Drive. This can help you pin down the exact date + the brew was deleted or moved, and by whom. : - If you *still* can't find it, some people have had success asking Google to recover + If the brew still isn't found, some people have had success asking Google to recover accidentally deleted files at this link: https://support.google.com/drive/answer/1716222?hl=en&ref_topic=7000946. At the bottom of the page there is a button that says *Send yourself an Email* @@ -63,35 +66,38 @@ const errorIndex = (props)=>{ // User is not Authors list '03' : dedent` - ## The current logged in user does not have editor access to this brew. + ## Current signed-in user does not have editor access to this brew. - If you believe you should have access to this brew, ask the file owner to invite you - as an author by opening the brew, viewing the Properties tab, and adding your username - to the "invited authors" list. You can then try to access this document again. + If you believe you should have access to this brew, ask one of its authors to invite you + as an author by opening the Edit page for the brew, viewing the {{fa,fa-info-circle}} + **Properties** tab, and adding your username to the "invited authors" list. You can + then try to access this document again. **Brew Title:** ${props.brew.brewTitle || 'Unable to show title'} - **Current Authors:** + **Current Authors:** ${props.brew.authors?.map((author)=>{return `${author}`;}).join(', ') || 'Unable to list authors'}`, - ${props.brew.authors?.map((author)=>{return `- ${author}`;}).join('\n') || 'Unable to list authors'} - `, - - // User is not logged in + // User is not signed in; must be a user on the Authors List '04' : dedent` - ## Not logged in + ## Sign-in required to edit this brew. - User is not logged in. Please log in [here](${loginUrl}).`, + You must be logged in to one of the accounts listed as an author of this brew. + User is not logged in. Please log in [here](${loginUrl}). + + **Brew Title:** ${props.brew.brewTitle || 'Unable to show title'} + + **Current Authors:** ${props.brew.authors?.map((author)=>{return `${author}`;}).join(', ') || 'Unable to list authors'}`, // Brew load error '05' : dedent` ## No Homebrewery document could be found. - The server could not locate the Homebrewery document. + The server could not locate the Homebrewery document. It was likely deleted by + its owner. **Requested access:** ${props.brew.accessType} - **Brew ID:** ${props.brew.brewId} - `, + **Brew ID:** ${props.brew.brewId}`, // Brew save error '06' : dedent` @@ -105,8 +111,7 @@ const errorIndex = (props)=>{ An error occurred while attempting to remove the Homebrewery document. - **Brew ID:** ${props.brew.brewId} - `, + **Brew ID:** ${props.brew.brewId}`, // Author delete error '08' : dedent` @@ -114,8 +119,7 @@ const errorIndex = (props)=>{ An error occurred while attempting to remove the user from the Homebrewery document author list! - **Brew ID:** ${props.brew.brewId} - `, + **Brew ID:** ${props.brew.brewId}`, }; }; diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 9e00b46b2..a986c0019 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -58,7 +58,7 @@ const api = { }); // Throw any error caught while attempting to retrieve Google brew. if(googleError) { - const reason = googleError.errors[0].reason; + const reason = googleError.errors?.[0].reason; if(reason == 'notFound') { throw { ...googleError, HBErrorCode: '02', authors: stub?.authors, account: req.account?.username }; } @@ -77,7 +77,7 @@ const api = { if(req.account){ throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03', authors: stub.authors, brewTitle: stub.title }; } - throw { ...accessError, message: 'User is not logged in', HBErrorCode: '04' }; + throw { ...accessError, message: 'User is not logged in', HBErrorCode: '04', authors: stub.authors, brewTitle: stub.title }; } // If after all of that we still don't have a brew, throw an exception From ba43055f32eccac730091950dcc24d5e7c0f0c12 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 26 Jun 2023 23:14:08 -0400 Subject: [PATCH 41/44] another text tweak --- client/homebrew/pages/errorPage/errors/errorIndex.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 5bde0b0b3..a7e61d08d 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -44,8 +44,8 @@ const errorIndex = (props)=>{ - **You may have changed the sharing settings for your files.** If the files are still on Google Drive, change all of them to be shared *with everyone who has the link* so the Homebrewery can access them. - - **The Google Drive may be full**, or may be have been closed by - Google (for inactivity, violating some policy of theirs). Make sure the owner can + - **The Google Account may be closed.** Google may have removed the account + due to inactivity or violating a Google policy. Make sure the owner can still access Google Drive normally and upload/download files to it. : If the file isn't found, Google Drive usually puts your file in your Trash folder for From a7040e554ac2d3a7b144f0983b31c604697d2f16 Mon Sep 17 00:00:00 2001 From: Sean Robertson Date: Tue, 27 Jun 2023 15:19:33 +1200 Subject: [PATCH 42/44] Fix test --- server/homebrew.api.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 214faccf9..6afe1b53c 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -197,7 +197,7 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual({ HBErrorCode: '04', message: 'User is not logged in', name: 'Access Error', status: 401 }); + expect(err).toEqual({ HBErrorCode: '04', message: 'User is not logged in', name: 'Access Error', status: 401, authors: [ 'a' ], brewTitle: 'test brew' }); }); it('does not throw if no authors', async ()=>{ From 8baf0fc8490c788b678a4ae9e8b7908d0f336864 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 26 Jun 2023 23:26:59 -0400 Subject: [PATCH 43/44] Add additional test for when logged in, but not in author list --- server/homebrew.api.js | 5 ++--- server/homebrew.api.spec.js | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index a986c0019..60c86b6d4 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -61,9 +61,8 @@ const api = { const reason = googleError.errors?.[0].reason; if(reason == 'notFound') { throw { ...googleError, HBErrorCode: '02', authors: stub?.authors, account: req.account?.username }; - } - else { - throw { ...googleError, HBErrorCode: '01'}; + } else { + throw { ...googleError, HBErrorCode: '01' }; } } // Combine the Homebrewery stub with the google brew, or if the stub doesn't exist just use the google brew diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 6afe1b53c..0adbcda4f 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -183,7 +183,7 @@ describe('Tests for api', ()=>{ expect(next).toHaveBeenCalled(); }); - it('throws if invalid author', async ()=>{ + it('throws if not logged in as author', async ()=>{ api.getId = jest.fn(()=>({ id: '1', googleId: undefined })); model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', authors: ['a'] })); @@ -197,7 +197,24 @@ describe('Tests for api', ()=>{ err = e; } - expect(err).toEqual({ HBErrorCode: '04', message: 'User is not logged in', name: 'Access Error', status: 401, authors: [ 'a' ], brewTitle: 'test brew' }); + expect(err).toEqual({ HBErrorCode: '04', message: 'User is not logged in', name: 'Access Error', status: 401, brewTitle: 'test brew', authors: ['a'] }); + }); + + it('throws if logged in as invalid author', async ()=>{ + api.getId = jest.fn(()=>({ id: '1', googleId: undefined })); + model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', authors: ['a'] })); + + const fn = api.getBrew('edit', true); + const req = { brew: {}, account: { username: 'b' } }; + + let err; + try { + await fn(req, null, null); + } catch (e) { + err = e; + } + + expect(err).toEqual({ HBErrorCode: '03', message: 'User is not an Author', name: 'Access Error', status: 401, brewTitle: 'test brew', authors: ['a'] }); }); it('does not throw if no authors', async ()=>{ From cea5f2e43a16ba8f037fffeb7012c893bc0d7c33 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 28 Jun 2023 16:13:01 -0400 Subject: [PATCH 44/44] Up version to v3.9.1 --- changelog.md | 10 ++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index bfdb278e4..1a761c9cd 100644 --- a/changelog.md +++ b/changelog.md @@ -80,6 +80,16 @@ pre { ## changelog For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). +### Friday 28/06/2023 - v3.9.1 +{{taskList + +##### G-Ambatte + +* [x] Better error pages with more useful information + +Fixes issue [#1924](https://github.com/naturalcrit/homebrewery/issues/1924) +}} + ### Friday 02/06/2023 - v3.9.0 {{taskList diff --git a/package-lock.json b/package-lock.json index 8b6ea8d34..b3f8c8e58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebrewery", - "version": "3.9.0", + "version": "3.9.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebrewery", - "version": "3.9.0", + "version": "3.9.1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 94474cfe3..44f69f457 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebrewery", "description": "Create authentic looking D&D homebrews using only markdown", - "version": "3.9.0", + "version": "3.9.1", "engines": { "node": ">=18.16.x" },