Add DDP._CurrentPublicationInvocation

This will make it possible to determine if code that is running has
been called from a publish function.
This commit is contained in:
Simon Fridlund
2017-04-24 17:01:30 +02:00
parent f31870302b
commit c6be32bfa0
2 changed files with 11 additions and 6 deletions

View File

@@ -6,3 +6,4 @@ LivedataTest.SUPPORTED_DDP_VERSIONS = DDPCommon.SUPPORTED_DDP_VERSIONS;
// it to get the current user. Meteor.setTimeout and friends clear
// it. We can probably find a better way to factor this.
DDP._CurrentInvocation = new Meteor.EnvironmentVariable;
DDP._CurrentPublicationInvocation = new Meteor.EnvironmentVariable;

View File

@@ -1041,12 +1041,16 @@ _.extend(Subscription.prototype, {
var self = this;
try {
var res = maybeAuditArgumentChecks(
self._handler, self, EJSON.clone(self._params),
// It's OK that this would look weird for universal subscriptions,
// because they have no arguments so there can never be an
// audit-argument-checks failure.
"publisher '" + self._name + "'");
var res = DDP._CurrentPublicationInvocation.withValue(
self,
() => maybeAuditArgumentChecks(
self._handler, self, EJSON.clone(self._params),
// It's OK that this would look weird for universal subscriptions,
// because they have no arguments so there can never be an
// audit-argument-checks failure.
"publisher '" + self._name + "'"
)
);
} catch (e) {
self.error(e);
return;