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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[15.0][FIX] web: legacy user_context setter #109822
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C3POdoo
requested review from
a team,
Polymorphe57 and
fdardenne
and removed request for
a team
January 12, 2023 17:38
pedrobaeza
changed the title
[15.0][FIX] web: lecacy user_context setter
[15.0][FIX] web: legacy user_context setter
Jan 12, 2023
pedrobaeza
approved these changes
Jan 12, 2023
sergio-teruel
approved these changes
Jan 12, 2023
When writing extension modules it's possible to override the session context so we can achieve effects on the overriden functions orm calls. This is very handy to avoid ugly patches that doesn't respect proper inheritance. This can be done using the `user` service and its `updateContext()` function. Since v15, this is not possible for legacy widgets, as the `user_context` key in the session is behind a getter. Before, this was possible: ```javascript Object.assign(session.user_context, {"new_key": "new_value"}); ``` With this patch, a slight variation would be possible: ```javascript session.user_context = Object.assign( {}, session.user_context, {"new_key": "new_value"} ); ```
chienandalu
force-pushed
the
15.0-fix-js-legacy-context-setter
branch
from
January 12, 2023 17:43
c90861b
to
120fd89
Compare
carlosdauden
approved these changes
Jan 12, 2023
robodoo r+ |
Thank you |
robodoo
pushed a commit
that referenced
this pull request
Feb 20, 2024
When writing extension modules it's possible to override the session context so we can achieve effects on the overriden functions orm calls. This is very handy to avoid ugly patches that doesn't respect proper inheritance. This can be done using the `user` service and its `updateContext()` function. Since v15, this is not possible for legacy widgets, as the `user_context` key in the session is behind a getter. Before, this was possible: ```javascript Object.assign(session.user_context, {"new_key": "new_value"}); ``` With this patch, a slight variation would be possible: ```javascript session.user_context = Object.assign( {}, session.user_context, {"new_key": "new_value"} ); ``` closes #109822 Signed-off-by: Mathieu Duckerts-Antoine (dam) <dam@odoo.com>
@chienandalu @Polymorphe57 staging failed: ci/runbot on 9484023d7100c3e0fc1447151c643067be1b3969 (view more at https://runbot.odoo.com/runbot/build/58518273) |
This was referenced Mar 29, 2024
Merged in #159849 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When writing extension modules it's possible to override the session context so we can achieve effects on the overriden functions orm calls. This is very handy to avoid ugly patches that doesn't respect proper inheritance. This can be done using the
user
service and itsupdateContext()
function.Since v15, this is not possible for legacy widgets, as the
user_context
key in the session is behind a getter. Before, this was possible:With this patch, a slight variation would be possible:
Some extra context on the user_context thing (no pun intended 馃檪 ): this would be a real world use case for the attendance action where we need to add some extra values to the attendances when the user clicks on the check in/out button:
https://github.com/OCA/hr-attendance/blob/3a9237e035a01dbe28378c8201669d995fe163d0/hr_attendance_geolocation/static/src/js/attendance_geolocation.js#L42-L53
The previous code was this and it avoided another modules adding more extra info as the original function was being completely shadowed.
https://github.com/OCA/hr-attendance/blob/17c3b2797e9e1fb8554e5af57dca7aedc66b0f4a/hr_attendance_geolocation/static/src/js/attendance_geolocation.js#L83-L133
Another option was to use a base module that could allow to hook into the function to add the extra context but that would imply shadowing the core function as well with all the issues that could come along with that design.
cc @Tecnativa
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr