Skip to content
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

Conversation

chienandalu
Copy link
Contributor

@chienandalu chienandalu commented 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:

Object.assign(session.user_context, {"new_key": "new_value"});

With this patch, a slight variation would be possible:

session.user_context = Object.assign(
  {}, session.user_context, {"new_key": "new_value"}
);

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

@robodoo
Copy link
Contributor

robodoo commented Jan 12, 2023

@C3POdoo C3POdoo requested review from a team, Polymorphe57 and fdardenne and removed request for a team January 12, 2023 17:38
@pedrobaeza pedrobaeza changed the title [15.0][FIX] web: lecacy user_context setter [15.0][FIX] web: legacy user_context setter 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 chienandalu force-pushed the 15.0-fix-js-legacy-context-setter branch from c90861b to 120fd89 Compare January 12, 2023 17:43
@brboi brboi removed the request for review from a team January 18, 2023 09:48
@Polymorphe57 Polymorphe57 requested review from brboi and removed request for fdardenne November 3, 2023 14:55
@Polymorphe57
Copy link
Contributor

robodoo r+

@Polymorphe57
Copy link
Contributor

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>
@robodoo
Copy link
Contributor

robodoo commented Feb 20, 2024

@chienandalu @Polymorphe57 staging failed: ci/runbot on 9484023d7100c3e0fc1447151c643067be1b3969 (view more at https://runbot.odoo.com/runbot/build/58518273)

@pedrobaeza
Copy link
Collaborator

Merged in #159849

@pedrobaeza pedrobaeza closed this Mar 31, 2024
@pedrobaeza pedrobaeza deleted the 15.0-fix-js-legacy-context-setter branch March 31, 2024 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants