Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var query = {}, cols = {};
var keys = (user && Array.isArray(user.keys))?user.keys:[];
var grant = false;
if(schema.keysCheck(keys,'get')){
grant = true;
} else if(user && schema.keysCheck(keys.concat(['owner']),'get')){
grant = true;
query.$or = [{_author:user._id},{_guests:user._id}];
}
if(grant){
var path = params.path || ''; // Warning, clean first and end '/'.
var _id = path.split('/').slice(2,3).join();
if(/^[a-f0-9]{24}$/i.test(_id)){
_id = new ObjectID.createFromHexString(_id);
} else {
_id = false;
}
if(_id){
var field = path.split('/').pop();
query._id = _id;
cols[field]=1;
var db = DB.collection(schema.collection);
db.findOne(query,cols,function(error, result) {
if(error){
cb({
error : 500,
details : error
});
} else if(!result) {
function saveSession(){
var sid = gw.cookie.sid || false;
var sessions = server.database.collection('sessions');
if(sid){
sid = new ObjectID.createFromHexString(sid);
sessions.update({_id:sid},gw.session,function(error, result) {
if(!error && result>0){
// Ok
} else {
console.log("Error on session save.");
}
});
}
}
it('should correctly diff ObjectIDs', function() {
var o1 = new ObjectID();
var o2 = ObjectID.createFromHexString(o1.toHexString());
var a1 = { _id: o1 };
var a2 = { _id: o2 };
var expected = {
};
diff(a1, a2).should.eql(expected);
o2 = new ObjectID();
var a1 = { _id: o1 };
var a2 = { _id: o2 };
var expected = {
$set: { _id: o2 }
};
function getSession(callback){
var sid = gw.cookie.sid || false;
var sessions = server.database.collection('sessions');
if(!sid){
newSession(callback);
} else {
sid = new ObjectID.createFromHexString(sid);
sessions.findOne({_id:sid},function(error, result) {
if(!error && result){
gw.session = result;
} else {
console.log("Error on get session.");
}
callback();
});
}
}
module.exports = new Plugin({id:'Accounts'},function(gw,next){
var account = gw.routing.check('account',false);
if(account){
if(gw.user){
next();
} else if(gw.session.user){
var _id = gw.session.user;
var users = DB.collection('users');
if(/^[a-f0-9]{24}$/i.test(_id)){_id = new ObjectID.createFromHexString(_id);}
users.findOne({_id:_id},function(error, result) {
if(!error && result){
var user = new User(result);
gw.user = user;
gw.emit('user',user);
next();
} else {
delete gw.session.user;
gw.error(403);
}
});
} else {
gw.error(403);
}
} else {
next();
async function getPaste(pasteId) {
const pastesCollection = await getCollection(collectionName);
const objectId = new ObjectID.createFromHexString(pasteId);
const paste = await pastesCollection.findOne({ _id: objectId });
if (!paste) {
throw new Error("Can not find paste");
}
return paste;
}
parseValue(value: string) {
return ObjectID.createFromHexString(value);
},
parseLiteral(node: ValueNode) {
async function getPaste(pasteId) {
const pastesCollection = await getCollection(collectionName);
const objectId = new ObjectID.createFromHexString(pasteId);
const paste = await pastesCollection.findOne({ _id: objectId });
if (!paste) {
throw new Error("Can not find paste");
}
return paste;
}
parseLiteral(node: ValueNode) {
if (node.kind !== Kind.STRING) {
throw new Error('Cannot parse non-string as ObjectID');
}
return ObjectID.createFromHexString(node.value);
},
serialize(value: ObjectID) {
ensureDbClient(function(err, db){
if(err) return callback(err, null);
db.collection(bugsCollection).findOne({ _id: new ObjectID.createFromHexString(bugID) }, function(err, data){
if(err) return callback(err, null);
callback(null, bugs.from(data));
});
});
};