-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make trigger context accessible in save #6459
Comments
+1. This is a solution to #6512. |
@jonas-db Good to see that there is demand for such a feature. That gave me some motivation to pick it up again 🙂 |
Added PR for JS SDK parse-community/Parse-SDK-JS#1150 |
Added PR for Parse Server #6626 |
Added PR in docs parse-community/docs#730 |
The intended use case is passing a parameter from The proposed change in parse-community/Parse-SDK-JS#1150 exposes the context also to clients outside of Cloud Code. Exposure is unidirectional, i.e. a parameter can only be passed to the trigger context, but any change of Proposed solutions:
Any thoughts? |
@mtrezza can you think of any security concerns? |
Context is used for internal purposes and the PR is changing exposure of the existing context.
By guessing (or by an obvious error message) someone could manipulate the internal context from client side. Or am I being too creative here? |
I agree this is some form of implicit taint flow. My original idea was to only expose it in the cloud code, and not on the client since any client can inject anything it. (but again, maybe this is the same as parameters in cloud functions, not sure if there is any security built around that?) |
No contrary voices, so I assume we'll expose @acinader It would be great if the next release of parse server could be coordinated with the next JS SDK release to coherently introduce this feature. The JS SDK PR has already been merged. The test cases in #6626 should pass with the next JS SDK release. |
Just a follow-up since you linked the tracking use case. Maybe, it can be extended to other operations such as find, delete, etc. since these also have triggers and might need a context. |
@jonas-db Sounds good! Would you be willing to open a PR for this? I assume it is relatively easy as it's just extending existing routes. This PR gives a good blueprint with the |
@mtrezza Sorry, I won't have time right now and the context for "save" is sufficient. However, I will review my project in a few months and will be happy to submit a PR for this :) |
I have created the PR for extending the context to following webhooks.
|
If I’m understanding the discussion here correctly, If so, I think this is extremely useful. For example, if there are multiple versions of an PFObject stored on a parse-server, there are typically two types of query/finds needed:
Would Also, I’m assuming As far as security, my initial thought is there aren’t many if any pass whatever security flaws are currently part of the current parse server/client. If a malicious person can manipulate |
Great job! Can you please open a new issue for these PRs as this issue will be closed with the next release of parse server. And can you please add a PR for the docs if necessary, that would put a smile on @TomWFox's face.
Correct.
I don't understand what "multiple versions" means in this context so I can't follow your use case. |
@mtrezza How would you pass
The use case I mentioned is a custom one. Typically parse keeps the current state of PFObjects in Postgres/Mongo. When a PFObject is updated, the state of that object is updated (and loses previous state) and therefore queried, modified, or deleted. I presented a use-case of maintaining versioned data in parse, by having a uuid field and doing 1-to-many mapping between uuid and related (other versions) of PFObjects. It's not necessary to edit parse-server itself for a case like this, but if context can be passed from the client, it solves my example. There may be an overhead because you query and filter as I mentioned in the example instead of modifying the query for mongo or postgres, but this is okay for me. From the discussion and other links here, context seems to handle the use-case I presented, assuming |
They are related like two cousins rather than parent and child :) The
Glad to hear that. |
I’m thinking of sending |
Sounds good! A PR for the Parse iOS or Android SDK would be very welcome. |
Not sure if it's a bug, or maybe by design, but using obj.save(null, context: { a: 'a' }) from within a trigger will throw an error if obj is being updated. It will work fine if obj is a new object being created though. So let's consider something like:
This will work fine, if I add or update an object of class Bar, an object of Foo will be created and its a property will be set to 5. But if you attempt the very same save call on a retrieved Foo, it will fail:
(an object of Foo exists of course, at this point) The error is one of the two, I'm not sure what determines which one gets called:
or, alternatively:
Not sure if I should be opening a new issue if this one's not being closed, so I'm posting here. |
I'm trying to use this with the latest JS SDK and the master version of server and I'm getting the following error:
Using this to update a user:
|
From what I can tell, the context is only handled for new objects because it is handled inside of the |
Yes, moving it out of the |
Additionally, it appears it does not get passed in correctly if you have related objects being saved. user.get('profile').set('displayName', 'foobar')
user.save(null, {context: {skipSync: true}}) |
Thanks, well spotted, I'm looking into it.
@davbeck Do I understand this correctly that the field |
It is a pointer to a Profile object. Surprisingly, I don't get the context object on either of the hooks. Remove the pointer update and the user hook starts getting context again. |
Since these issues only occur in specific use cases and do not impede the basic functionality of this feature, I have opened a new issue #6736 to track them. |
[Open discussion](#6459) for feature with other issues
@mtrezza Sorry for the late reply just getting caught up on the conversations. Will review shortly. |
With the docs PR merged (see above), feature is complete. |
Guys, one question, why in the afterFind the context is not available? because sometimes I have to change the result in afterFind, but I can't send anything to afterFind to diff the results. There's another way to pass data between beforeFind and afterFind, or include context is the better way? |
From what I can tell, the context has not been made accessible in the You can look at #6666 which extended this PR to make context available in |
For sure, I never changed anything on parse server code, but I would love to try. From what I understand of parse server, to make context accessible in afterFind, needs to change in this file? Something like: and in function declaration, add the context var Something like that? Thank's for your reply |
Great! Welcome to the contributor's league 😉 I suggest you take a look at the contribution guide where you can also find useful infos, for example about how to set up a local development environment for Parse Server.
I suggest you take a look at the changes in #6666. In |
ok! Thank you again, I'll do that. |
Is your feature request related to a problem? Please describe.
Sometimes an object should be saved with custom execution in its triggers (e.g. afterSave).
Describe the solution you'd like
It should be possible to pass arguments from the
save
call to the triggers. There is already acontext
object that is passed frombeforeSave
toafterSave
. It would be practical to make thecontext
accessible in thesave
call as an option, e.g.:TODOs:
The text was updated successfully, but these errors were encountered: