[FW][FIX] knowledge: do not crash when public reads is_user_favorite
Reading is_user_favorite requires access on intermediate favorite model. It is however not accessible to public users. Reading the field therefore raises an error which is not necessary. We can simply set the field to False as public users can not set articles as favorite and skip the whole computation. Task-2859616 X-original-commit: odoo/odoo@fe854b3636 Part-of: odoo/odoo#95471
This commit is contained in:
@@ -412,6 +412,9 @@ class Article(models.Model):
|
||||
@api.depends_context('uid')
|
||||
@api.depends('favorite_ids.user_id')
|
||||
def _compute_is_user_favorite(self):
|
||||
if self.env.user._is_public():
|
||||
self.is_user_favorite = False
|
||||
return
|
||||
for article in self:
|
||||
favorite = article.favorite_ids.filtered(lambda f: f.user_id == self.env.user)
|
||||
article.is_user_favorite = bool(favorite)
|
||||
|
||||
@@ -21,10 +21,11 @@ class TestWKnowledgeSecurity(KnowledgeCommonWData):
|
||||
|
||||
article_shared.sudo().website_published = True
|
||||
article_shared.body # access body should not trigger acls
|
||||
self.assertFalse(article_shared.is_user_favorite)
|
||||
|
||||
# FAVOURITE
|
||||
with self.assertRaises(exceptions.AccessError, msg='ACLs: No favorite access to public'):
|
||||
article_shared.is_user_favorite
|
||||
self.env['knowledge.article.favorite'].search([])
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.addons.base.models.ir_rule')
|
||||
@users('portal_test')
|
||||
|
||||
Reference in New Issue
Block a user