From 84752834a4b8a2fb3e07ed2edebf6baec6e758cb Mon Sep 17 00:00:00 2001 From: DallonF Date: Thu, 14 Jun 2012 12:05:02 -0700 Subject: [PATCH] Added internal exception to cancel(), hide(), and protect() --- lib/internal-client.js | 1 + lib/resources/collection.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/internal-client.js b/lib/internal-client.js index ddd02f8..6d0fd69 100644 --- a/lib/internal-client.js +++ b/lib/internal-client.js @@ -68,6 +68,7 @@ exports.build = function(server, session) { , query: options.query , body: options.body , session: session + , internal: true }; res = { diff --git a/lib/resources/collection.js b/lib/resources/collection.js index 12f7053..ba8769b 100644 --- a/lib/resources/collection.js +++ b/lib/resources/collection.js @@ -132,6 +132,10 @@ Collection.prototype.handle = function (ctx) { // set id one wasnt provided in the query ctx.query.id = ctx.query.id || this.parseId(ctx); + if (ctx.req.internal) { + ctx.session.internal = true; + } + switch(ctx.req.method) { case 'GET': this.find(ctx.session, ctx.query, ctx.dpd, ctx.done); @@ -188,6 +192,7 @@ Collection.prototype.execListener = function(method, session, query, item, clien , options = { this: item, context: { + internal: session.internal, console: console, emit: function(collection, query, event, data) { if(arguments.length === 4) { @@ -203,19 +208,19 @@ Collection.prototype.execListener = function(method, session, query, item, clien errors[key] = val || true; }, cancel: function(msg, status) { - if (!session.isRoot) { + if (!session.isRoot && !session.internal) { var err = new Error(msg); err.statusCode = status; throw err; } }, hide: function(property) { - if (!session.isRoot) { + if (!session.isRoot && !session.internal) { delete data[property]; } }, protect: function(property) { - if (!session.isRoot) { + if (!session.isRoot && !session.internal) { delete data[property]; } }