-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
PUT model/{id} (updateAttributes) implicitly invokes findById & access hook #2255
Comments
Can you provide a sample repo for me to reproduce the issue on my end? |
@shaharz What do you mean might fail? If you are not accessing the result, it should be passed through as though you didn't add the hook. It sounds like you're saying the problem is sending a PUT request triggers the access hook when it shouldn't. @Amir-61 @bajtos I remember one of you guys working on refactoring the PUT feature. What is the expected behaviour with regard to what hooks get triggered for a PUT request? The docs specify /cc @raymondfeng |
That's right!
Yes you are right for the code please see here... The following hooks are triggered by this order:'before save', 'persist', 'loaded' and 'after save'...
AFAICT updateAttributes does not call findById... |
I later noticed the following under 'access':
So in fact it is documented, but my point regarding the lack of context in the hook still stands. |
@shaharz So is this a feature request to get access to context in the op hook then? |
When I say context I don't mean the Loopback context, but the broad sense of the word. Suppose I I have a remote hook Since that's not the case, the choice is basically to either give up the access hook altogether or use middleware (that is guaranteed to fire before the hook). If this is still unclear I can put together a minimal case to illustrate the problem. |
This would definitely help. See https://github.com/strongloop/loopback/wiki/Reporting-issues#bug-report |
@shaharz In your example, I can't reproduce it properly. beforeRemote gets called first and access is never called (opposite of what you describe in the readme). |
Actually I could use your example after modifying a few things. However, the result I get is remote hook first, then access, which seems correct. What are you expecting to happen? |
@superkhau I pushed |
Hello, as for the "access" hook: the way how this hook is designed, it should be called whenever any model instance(s) are accessed. This way it's possible to implement custom access control by registering "access" hook observer. We are discussing with @Amir-61 that we should eventually implement a static version of
If I understand your comments posted later, then you are looking for a remoting hook that would be called before |
Yes, I was expecting the remote hook to be called before |
Escalating to feature. Thanks for the input everyone. |
I believe this is a similar issue to #2064. According to the docs, updateAttributes doesn't trigger the 'access' hook. However, when you PUT model/{id} there is an implicit
findById
call in model.js that does trigger it. As a result, PUT model/{id} might fail even though they're not looking to access the result, only in update attributes.In addition, none of the remote hooks have been called at this point so there's no context to the operation hook to help make an intelligent decision as to whether to let the request go through or not.
Relevant stack trace:
The text was updated successfully, but these errors were encountered: