From 06beb3f18841f10a115f96378e3a3197dbdc64d7 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Mon, 19 Dec 2022 14:38:29 +0100 Subject: [PATCH] Do not check read access when copying records Closes #11949 --- trytond/trytond/model/modelstorage.py | 4 +++- trytond/trytond/tests/test_copy.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/trytond/trytond/model/modelstorage.py b/trytond/trytond/model/modelstorage.py index a98aa9c607..4e1c1d42a0 100644 --- a/trytond/trytond/model/modelstorage.py +++ b/trytond/trytond/model/modelstorage.py @@ -440,7 +440,9 @@ class ModelStorage(Model): or isinstance(f, fields.MultiValue)) and n not in mptt] ids = list(map(int, records)) - values = {d['id']: d for d in cls.read(ids, fields_names=fields_names)} + with Transaction().set_context(_check_access=False): + values = { + d['id']: d for d in cls.read(ids, fields_names=fields_names)} field_defs = cls.fields_get(fields_names=fields_names) default_values = cls.default_get(fields_names, with_rec_name=False) to_create = [] diff --git a/trytond/trytond/tests/test_copy.py b/trytond/trytond/tests/test_copy.py index 4c702406af..54e56a50be 100644 --- a/trytond/trytond/tests/test_copy.py +++ b/trytond/trytond/tests/test_copy.py @@ -272,6 +272,30 @@ class CopyTestCase(unittest.TestCase): new_record, = TestAccess.copy( [record], default={'name': 'nondefault'}) + @with_transaction(context={'_check_access': True}) + def test_copy_with_no_read_access(self): + "Test copying field with no read access" + pool = Pool() + Field = pool.get('ir.model.field') + FieldAccess = pool.get('ir.model.field.access') + TestAccess = pool.get('test.copy.access') + + record, = TestAccess.create([{}]) + + field, = Field.search([ + ('model.model', '=', 'test.copy.access'), + ('name', '=', 'name'), + ]) + FieldAccess.create([{ + 'field': field.id, + 'group': None, + 'perm_read': False, + 'perm_write': False, + }]) + + new_record, = TestAccess.copy([record]) + self.assertNotEqual(new_record.id, record.id) + class CopyTranslationTestCase(TranslationTestCase): "Test copy translation"