[FW][FIX][IMP] knowledge: lessen usage of member writable constraint

Purpose of this commit is to have less check on "is writable" constraint from
member model. With a new context key we can now bypass the constraint from
member model when we are sure it is globally verified. As in some cases we
modify members from an article, the constraint will be checked at article
level with all members being updated. In some cases doing specific checks
might lead to issues when the constraint is evaluated in a transient state
e.g. when a member is removed while new write members are not yet added.

Task-2859616

X-original-commit: odoo/odoo@a4aa856902
Part-of: odoo/odoo#95471
Co-authored-by: Aurélien Warnon <awa@odoo.com>
Co-authored-by: Thibault Delavallee <tde@odoo.com>
This commit is contained in:
Thibault Delavallée
2022-07-07 17:31:02 +02:00
co-authored by Aurélien Warnon
parent e6b598cac9
commit 35b9e48396
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -1241,7 +1241,7 @@ class Article(models.Model):
}))
article_values['article_member_ids'] = member_command
return writable_self.write(article_values)
return writable_self.with_context(knowledge_member_skip_writable_check=True).write(article_values)
# ------------------------------------------------------------
# PERMISSIONS BATCH COMPUTATION
@@ -49,6 +49,9 @@ class ArticleMember(models.Model):
in self (the ones that will be deleted) to check if one of the remaining
members has write access.
"""
if self.env.context.get('knowledge_member_skip_writable_check'):
return
articles_to_check = self.article_id.filtered(lambda a: a.inherited_permission != 'write')
if not articles_to_check:
return