From 63153e1c7fbf6e3d2a34016fc3d6be3a0c22e975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 14 Jun 2016 18:19:27 +0200 Subject: [PATCH] Ensure _check_access is removed when instantiate translation Since changeset 3a17f8e704a7, there is no more context leak so the context when saving is exactly the one at the instantiation. So _check_access must be removed when the translations are instantiated. review26401002 --- trytond/ir/translation.py | 63 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index 3fbfff70e5..eda4cd01fd 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -519,18 +519,18 @@ class Translation(ModelSQL, ModelView): translations[translation.name] = translation to_save = [] - for record, value in izip(records, values): - translation = translations.get(get_name(record)) - if not translation: - translation = cls() - translation.name = name - translation.lang = lang - translation.type = ttype - translation.src = getattr(record, field_name) - translation.value = value - translation.fuzzy = False - to_save.append(translation) with Transaction().set_context(_check_access=False): + for record, value in izip(records, values): + translation = translations.get(get_name(record)) + if not translation: + translation = cls() + translation.name = name + translation.lang = lang + translation.type = ttype + translation.src = getattr(record, field_name) + translation.value = value + translation.fuzzy = False + to_save.append(translation) cls.save(to_save) return @@ -560,16 +560,16 @@ class Translation(ModelSQL, ModelView): ).append(translation) to_save = [] - for record, value in izip(records, values): - translation = translations.get(record.id) - if not translation: - translation = cls() - translation.name = name - translation.lang = lang - translation.type = ttype - translation.res_id = record.id - else: - with Transaction().set_context(_check_access=False): + with Transaction().set_context(_check_access=False): + for record, value in izip(records, values): + translation = translations.get(record.id) + if not translation: + translation = cls() + translation.name = name + translation.lang = lang + translation.type = ttype + translation.res_id = record.id + else: cls.write([translation], { 'value': value, 'src': getattr(record, field_name), @@ -581,24 +581,23 @@ class Translation(ModelSQL, ModelView): other_lang.src = getattr(record, field_name) other_lang.fuzzy = True to_save.append(other_lang) - translation.value = value - translation.src = getattr(record, field_name) - translation.fuzzy = False - to_save.append(translation) - with Transaction().set_context(_check_access=False): + translation.value = value + translation.src = getattr(record, field_name) + translation.fuzzy = False + to_save.append(translation) cls.save(to_save) @classmethod def delete_ids(cls, model, ttype, ids): "Delete translation for each id" translations = [] - for sub_ids in grouped_slice(ids): - translations += cls.search([ - ('type', '=', ttype), - ('name', 'like', model + ',%'), - ('res_id', 'in', list(sub_ids)), - ]) with Transaction().set_context(_check_access=False): + for sub_ids in grouped_slice(ids): + translations += cls.search([ + ('type', '=', ttype), + ('name', 'like', model + ',%'), + ('res_id', 'in', list(sub_ids)), + ]) cls.delete(translations) @classmethod