mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 21:32:41 +00:00
add invitedAuthors key and move invited author to authors on save
This commit is contained in:
@@ -43,7 +43,9 @@ const getBrew = (accessType, stubOnly = false)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
stub = stub?.toObject();
|
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.';
|
throw 'Current logged in user does not have access to this brew.';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,6 +245,7 @@ const updateBrew = async (req, res)=>{
|
|||||||
|
|
||||||
if(req.account) {
|
if(req.account) {
|
||||||
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
|
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
|
// define a function to catch our save errors
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ const HomebrewSchema = mongoose.Schema({
|
|||||||
textBin : { type: Buffer },
|
textBin : { type: Buffer },
|
||||||
pageCount : { type: Number, default: 1 },
|
pageCount : { type: Number, default: 1 },
|
||||||
|
|
||||||
description : { type: String, default: '' },
|
description : { type: String, default: '' },
|
||||||
tags : [String],
|
tags : [String],
|
||||||
systems : [String],
|
systems : [String],
|
||||||
renderer : { type: String, default: '' },
|
renderer : { type: String, default: '' },
|
||||||
authors : [String],
|
authors : [String],
|
||||||
published : { type: Boolean, default: false },
|
invitedAuthors : [String],
|
||||||
thumbnail : { type: String, default: '' },
|
published : { type: Boolean, default: false },
|
||||||
|
thumbnail : { type: String, default: '' },
|
||||||
|
|
||||||
createdAt : { type: Date, default: Date.now },
|
createdAt : { type: Date, default: Date.now },
|
||||||
updatedAt : { type: Date, default: Date.now },
|
updatedAt : { type: Date, default: Date.now },
|
||||||
|
|||||||
Reference in New Issue
Block a user