Close #470 ability to renew an existing bypass, which is slightly useful if you allow long living bypasses

merge-requests/341/head
Thomas Lynch 2 years ago
parent 9c5dd5efa8
commit fd7fc1adbf
  1. 9
      db/bypass.js
  2. 5
      models/forms/blockbypass.js

@ -29,10 +29,15 @@ module.exports = {
'anonymizer': anonymizer,
'expireAt': new Date(Date.now() + blockBypass.expireAfterTime)
};
if (anonymizer === true && id !== null) {
if (id !== null) {
newBypass._id = Mongo.ObjectId(id);
return db.replaceOne({
_id: newBypass._id
}, newBypass, {
upsert: true,
});
}
return db.insertOne(newBypass);
return db.insertOne(newBypass);
},
deleteAll: () => {

@ -8,8 +8,9 @@ const { Bypass } = require(__dirname+'/../../db/')
module.exports = async (req, res) => {
const { secureCookies, blockBypass } = config.get;
const bypass = await Bypass.getBypass(res.locals.anonymizer, res.locals.pseudoIp, blockBypass.expireAfterUses);
const bypassId = bypass.insertedId;
const existingBypassId = req.signedCookies.bypassid || res.locals.pseudoIp;
const bypass = await Bypass.getBypass(res.locals.anonymizer, existingBypassId, blockBypass.expireAfterUses);
const bypassId = bypass.insertedId || existingBypassId; // if upserted, insertedId will be null, and will be the existingId
res.locals.blockBypass = true;
res.cookie('bypassid', bypassId.toString(), {

Loading…
Cancel
Save