Skip to content

Commit

Permalink
[16.0][FIX] fastapi: always add authenticate_partner_id in context wh…
Browse files Browse the repository at this point in the history
…en evaluating ir rules

This fix is needed since a modificiation of ir.rule that checks the domain when creating/modifying ir rules
The solution is to set authenticate_partner_id to False when it is not present in context
  • Loading branch information
AnizR committed Jan 17, 2024
1 parent 8fe85e2 commit 7c125b4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion fastapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Odoo FastAPI
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2b79ba7bbc412d35210ba755b9fca17352faad894aa88c9339fb7063d02a50bf
!! source digest: sha256:8a90dec844eac96b44cefb64548fb05283ade12b16246bb89062abc7644e2087
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
4 changes: 0 additions & 4 deletions fastapi/fastapi_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ def _get_environ(self):
@contextmanager
def _manage_odoo_env(self, uid=None):
env = request.env
# add authenticated_partner_id=False in the context
# to ensure that the ir.rule defined for user's endpoint can be
# evaluated even if not authenticated partner is set
env = env(context=dict(env.context, authenticated_partner_id=False))
accept_language = request.httprequest.headers.get("Accept-language")
context = env.context
if accept_language:
Expand Down
7 changes: 3 additions & 4 deletions fastapi/models/ir_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ class IrRule(models.Model):
@api.model
def _eval_context(self):
ctx = super()._eval_context()
if "authenticated_partner_id" in self.env.context:
ctx["authenticated_partner_id"] = self.env.context[
"authenticated_partner_id"
]
ctx["authenticated_partner_id"] = self.env.context.get(
"authenticated_partner_id", False
)
return ctx

def _compute_domain_keys(self):
Expand Down
5 changes: 5 additions & 0 deletions fastapi/readme/newsfragments/410.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Odoo has done an update and now, it checks domains of ir.rule on creation and modification.

The ir.rule 'Fastapi: Running user rule' uses a field (authenticate_partner_id) that comes from the context.
This field wasn't always set and this caused an error when Odoo checked the domain.
So now it is set to *False* by default.
3 changes: 2 additions & 1 deletion fastapi/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Odoo FastAPI</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2b79ba7bbc412d35210ba755b9fca17352faad894aa88c9339fb7063d02a50bf
!! source digest: sha256:8a90dec844eac96b44cefb64548fb05283ade12b16246bb89062abc7644e2087
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/16.0/fastapi"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon provides the basis to smoothly integrate the <a class="reference external" href="https://fastapi.tiangolo.com/">FastAPI</a>
Expand Down

0 comments on commit 7c125b4

Please sign in to comment.