mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 21:32:41 +00:00
Differentiate Not an Author from Not logged in
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
|
const loginUrl = 'https://www.naturalcrit.com/login';
|
||||||
|
|
||||||
const errorIndex = (props)=>{
|
const errorIndex = (props)=>{
|
||||||
return {
|
return {
|
||||||
'00' : dedent`
|
'00' : dedent`
|
||||||
@@ -59,24 +61,29 @@ const errorIndex = (props)=>{
|
|||||||
`,
|
`,
|
||||||
|
|
||||||
'04' : dedent`
|
'04' : dedent`
|
||||||
|
## Not logged in
|
||||||
|
|
||||||
|
User is not logged in. Please log in [here](${loginUrl}).`,
|
||||||
|
|
||||||
|
'05' : dedent`
|
||||||
## No Homebrewery document could be found.
|
## No Homebrewery document could be found.
|
||||||
|
|
||||||
The server could not locate the Homebrewery document.`,
|
The server could not locate the Homebrewery document.`,
|
||||||
|
|
||||||
'05' : dedent`
|
'06' : dedent`
|
||||||
## Unable to save Homebrewery document.
|
## Unable to save Homebrewery document.
|
||||||
|
|
||||||
An error occurred wil attempting to save the Homebrewery document.`,
|
An error occurred wil attempting to save the Homebrewery document.`,
|
||||||
|
|
||||||
'06' : dedent`
|
'07' : dedent`
|
||||||
## Unable to delete Homebrewery document.
|
## 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.`,
|
||||||
|
|
||||||
'07' : dedent`
|
'08' : dedent`
|
||||||
## Unable to remove user from Homebrewery document.
|
## 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!`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -68,12 +68,15 @@ const api = {
|
|||||||
const isAuthor = stub?.authors?.includes(req.account?.username);
|
const isAuthor = stub?.authors?.includes(req.account?.username);
|
||||||
const isInvited = stub?.invitedAuthors?.includes(req.account?.username);
|
const isInvited = stub?.invitedAuthors?.includes(req.account?.username);
|
||||||
if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) {
|
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 after all of that we still don't have a brew, throw an exception
|
||||||
if(!stub && !stubOnly) {
|
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
|
// Clean up brew: fill in missing fields with defaults / fix old invalid values
|
||||||
@@ -182,7 +185,7 @@ const api = {
|
|||||||
saved = await newHomebrew.save()
|
saved = await newHomebrew.save()
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.error(err, err.toString(), err.stack);
|
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;
|
if(!saved) return;
|
||||||
saved = saved.toObject();
|
saved = saved.toObject();
|
||||||
@@ -309,7 +312,7 @@ const api = {
|
|||||||
await HomebrewModel.deleteOne({ _id: brew._id })
|
await HomebrewModel.deleteOne({ _id: brew._id })
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.error(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 {
|
} else {
|
||||||
if(shouldDeleteGoogleBrew) {
|
if(shouldDeleteGoogleBrew) {
|
||||||
@@ -321,7 +324,7 @@ const api = {
|
|||||||
brew.markModified('authors'); //Mongo will not properly update arrays without markModified()
|
brew.markModified('authors'); //Mongo will not properly update arrays without markModified()
|
||||||
await brew.save()
|
await brew.save()
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '07' };
|
throw { name: 'BrewAuthorDelete Error', message: err, status: 500, HBErrorCode: '08' };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user