mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-13 04:00:35 +08:00
Added internal exception to cancel(), hide(), and protect()
This commit is contained in:
@@ -68,6 +68,7 @@ exports.build = function(server, session) {
|
||||
, query: options.query
|
||||
, body: options.body
|
||||
, session: session
|
||||
, internal: true
|
||||
};
|
||||
|
||||
res = {
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user