Open Tyler-RCSD opened 3 years ago
@Tyler-RCSD Thanks for posting! We'll take a look as soon as possible.
In the mean time, there are a few ways you can help speed things along:
Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.
For help with questions about Sails, click here.
Digging into the pubsub hook code it seems that that there are some undocumented lifecycle hooks for _beforePublishUpdate
, _beforePublishDestroy
, _beforePublishAdd
, _beforePublishRemove
, and _beforePublishCreate
but either they don't work as I would expect or I'm not understanding how to use them. Here is what the invocation looks like:
sails/lib/hooks/pubsub/index.js
if (_.isFunction(this._beforePublishUpdate)) {
this._beforePublishUpdate(id, changes, req, options);
}
If I add _beforePublishUpdate as an attribute to my model and set it to a function then that function is executed, but then the actual publish doesn't happen afterward. Other lifecycle hooks like beforeUpdate or afterUpdate have a callback function as their last parameter that you call to have the code continue executing. That doesn't seem to be the case here. Am I misunderstanding how to use this?
I'm also not entirely sure this even helps me because I would need to be able to modify the 'changes' and 'options' parameters before the publish continued.
Hi @Tyler-RCSD, toJSON is not documented to work with RPS, we will be updating the documentation to show this. Using undocumented functions like _beforePublishUpdate and _beforePublishDestroy is not recommended as it can lead to more problems in the future.
Node version: 10.6.3 Sails version (sails): 1.2.4 ORM hook version (sails-hook-orm): 2.1.1 Sockets hook version (sails-hook-sockets): 2.0.0 DB adapter & version (e.g. sails-mysql@5.55.5): sails-mysql@1.0.1
When use HTTP GET requests you can configure customToJSON so that you can omit specific attributes you don't want returned, e.g. password. This is described in the docs here. For instance:
My issue is that customToJSON does not seem to be obeyed when using Resourceful PubSub. If I update my 'user' model I get something like this:
The 'previous' attribute contains the entire user object, including things that are excluded with customToJSON. Is there some way to modify what is being published?