diff --git a/server/homebrew.api.js b/server/homebrew.api.js index d5cced977..f28412281 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -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 diff --git a/server/homebrew.model.js b/server/homebrew.model.js index a514e3fd8..da8853de7 100644 --- a/server/homebrew.model.js +++ b/server/homebrew.model.js @@ -12,13 +12,14 @@ const HomebrewSchema = mongoose.Schema({ textBin : { type: Buffer }, pageCount : { type: Number, default: 1 }, - description : { type: String, default: '' }, - tags : [String], - systems : [String], - renderer : { type: String, default: '' }, - authors : [String], - published : { type: Boolean, default: false }, - thumbnail : { type: String, default: '' }, + description : { type: String, default: '' }, + tags : [String], + systems : [String], + renderer : { type: String, default: '' }, + authors : [String], + invitedAuthors : [String], + published : { type: Boolean, default: false }, + thumbnail : { type: String, default: '' }, createdAt : { type: Date, default: Date.now }, updatedAt : { type: Date, default: Date.now },