0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-05 12:22:44 +00:00

add invitedAuthors key and move invited author to authors on save

This commit is contained in:
Charlie Humphreys
2022-12-13 21:05:00 -06:00
parent 770d0c141d
commit 63e043593a
2 changed files with 12 additions and 8 deletions

View File

@@ -43,7 +43,9 @@ const getBrew = (accessType, stubOnly = false)=>{
}
});
stub = stub?.toObject();
if(accessType === 'edit' && stub?.authors?.length > 0 && !stub?.authors.includes(req.account?.username)) {
const authorsExistAndIsNotAuthor = stub?.authors?.length > 0 && !stub?.authors.includes(req.account?.username);
const isNotInvited = stub?.invitedAuthors?.length > 0 && !stub?.invitedAuthors.includes(req.account?.username);
if(accessType === 'edit' && authorsExistAndIsNotAuthor && isNotInvited) {
throw 'Current logged in user does not have access to this brew.';
}
@@ -243,6 +245,7 @@ const updateBrew = async (req, res)=>{
if(req.account) {
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
brew.invitedAuthors = _.uniq(_.filter(brew.invitedAuthors, (a)=>req.account.username !== a));
}
// define a function to catch our save errors