Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
2d833b1d by Sergi Almacellas Abellana at 2022-12-19T14:38:29+01:00
Do not check read access when copying records
Closes #11949
- - - - -


2 changed files:

- trytond/trytond/model/modelstorage.py
- trytond/trytond/tests/test_copy.py


Changes:

=====================================
trytond/trytond/model/modelstorage.py
=====================================
@@ -440,7 +440,9 @@
                 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 = []


=====================================
trytond/trytond/tests/test_copy.py
=====================================
@@ -272,6 +272,30 @@
             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"



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/2d833b1d7b9e3f2753b63645489482419fb0377b

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/2d833b1d7b9e3f2753b63645489482419fb0377b
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to