Added internal exception to cancel(), hide(), and protect()

This commit is contained in:
DallonF
2012-06-14 12:05:02 -07:00
parent f3ea679224
commit 84752834a4
2 changed files with 9 additions and 3 deletions

View File

@@ -68,6 +68,7 @@ exports.build = function(server, session) {
, query: options.query
, body: options.body
, session: session
, internal: true
};
res = {

View File

@@ -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];
}
}