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 12, 2024
1 parent 1f77c87 commit 166f5c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
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

0 comments on commit 166f5c8

Please sign in to comment.