details:   https://code.tryton.org/tryton/commit/781521a7e74a
branch:    7.0
user:      Cédric Krier <[email protected]>
date:      Tue Nov 24 10:16:01 2026 +0100
description:
        Enforce access rights on the selection field strings

        Closes #15271
        (grafted from 9237d25735840fbf99c71cd9d56a15a8ba8de8f1)
diffstat:

 trytond/CHANGELOG                    |   1 +
 trytond/trytond/ir/model.py          |   6 ++++++
 trytond/trytond/tests/access.py      |   5 +++++
 trytond/trytond/tests/test_access.py |  21 +++++++++++++++++++++
 4 files changed, 33 insertions(+), 0 deletions(-)

diffs (70 lines):

diff -r a45a59ae4933 -r 781521a7e74a trytond/CHANGELOG
--- a/trytond/CHANGELOG Thu Nov 26 10:59:50 2026 +0100
+++ b/trytond/CHANGELOG Tue Nov 24 10:16:01 2026 +0100
@@ -1,3 +1,4 @@
+* Enforce access rights on the selection field strings (issue15271)
 * Prevent searching on password hash and reset password (issue15266)
 * Enforce access rights when exporting resource data (issue15264)
 * Forbid to read the user's reset password (issue15258)
diff -r a45a59ae4933 -r 781521a7e74a trytond/trytond/ir/model.py
--- a/trytond/trytond/ir/model.py       Thu Nov 26 10:59:50 2026 +0100
+++ b/trytond/trytond/ir/model.py       Tue Nov 24 10:16:01 2026 +0100
@@ -819,6 +819,12 @@
         accesses = dict((f, a[mode])
             for f, a in cls.get_access([model_name])[model_name].items())
         for field in fields:
+            if field.startswith('_'):
+                continue
+            if '.' in field:
+                continue
+            if field.endswith(':string'):
+                field = field[:-len(':string')]
             if not accesses.get(field, True):
                 if raise_exception:
                     raise AccessError(
diff -r a45a59ae4933 -r 781521a7e74a trytond/trytond/tests/access.py
--- a/trytond/trytond/tests/access.py   Thu Nov 26 10:59:50 2026 +0100
+++ b/trytond/trytond/tests/access.py   Tue Nov 24 10:16:01 2026 +0100
@@ -9,6 +9,11 @@
     __name__ = 'test.access'
     field1 = fields.Char('Field 1')
     field2 = fields.Char('Field 2')
+    selection = fields.Selection([
+            (None, ""),
+            ('foo', "Foo"),
+            ('bar', "Bar"),
+            ], "Selection")
     relate = fields.Many2One('test.access.relate', "Relate")
     reference = fields.Reference("Reference", [
             (None, ""),
diff -r a45a59ae4933 -r 781521a7e74a trytond/trytond/tests/test_access.py
--- a/trytond/trytond/tests/test_access.py      Thu Nov 26 10:59:50 2026 +0100
+++ b/trytond/trytond/tests/test_access.py      Tue Nov 24 10:16:01 2026 +0100
@@ -1182,6 +1182,27 @@
         with self.assertRaises(AccessError):
             ModelAccessProxy(proxy.field1)
 
+    @with_transaction(context=_context)
+    def test_no_access_selection_string(self):
+        "Test no access on selection string"
+        pool = Pool()
+        Field = pool.get('ir.model.field')
+        FieldAccess = pool.get('ir.model.field.access')
+        TestAccess = pool.get('test.access')
+        record, = TestAccess.create([{}])
+        field, = Field.search([
+                ('model.model', '=', 'test.access'),
+                ('name', '=', 'selection'),
+                ])
+        FieldAccess.create([{
+                    'field': field.id,
+                    'group': None,
+                    'perm_read': False,
+                    }])
+
+        with self.assertRaises(AccessError):
+            TestAccess.read([record.id], ['selection:string'])
+
 
 class ModelFieldAccessWriteTestCase(_ModelFieldAccessTestCase):
     _perm = 'perm_write'

Reply via email to