details:   https://code.tryton.org/tryton/commit/96740e20c7d6
branch:    8.2
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 |  18 ++++++++++++++++++
 4 files changed, 30 insertions(+), 0 deletions(-)

diffs (67 lines):

diff -r 8825a01110a8 -r 96740e20c7d6 trytond/CHANGELOG
--- a/trytond/CHANGELOG Mon Nov 23 11:25:25 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 8825a01110a8 -r 96740e20c7d6 trytond/trytond/ir/model.py
--- a/trytond/trytond/ir/model.py       Mon Nov 23 11:25:25 2026 +0100
+++ b/trytond/trytond/ir/model.py       Tue Nov 24 10:16:01 2026 +0100
@@ -902,6 +902,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:
                     groups = Group.browse(User.get_groups())
diff -r 8825a01110a8 -r 96740e20c7d6 trytond/trytond/tests/access.py
--- a/trytond/trytond/tests/access.py   Mon Nov 23 11:25:25 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 8825a01110a8 -r 96740e20c7d6 trytond/trytond/tests/test_access.py
--- a/trytond/trytond/tests/test_access.py      Mon Nov 23 11:25:25 2026 +0100
+++ b/trytond/trytond/tests/test_access.py      Tue Nov 24 10:16:01 2026 +0100
@@ -1335,6 +1335,24 @@
             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()
+        FieldAccess = pool.get('ir.model.field.access')
+        TestAccess = pool.get('test.access')
+        record, = TestAccess.create([{}])
+        FieldAccess.create([{
+                    'model': 'test.access',
+                    'field': 'selection',
+                    'group': None,
+                    'perm_read': False,
+                    }])
+
+        with Transaction().set_user(self.user_id):
+            with self.assertRaises(AccessError):
+                TestAccess.read([record.id], ['selection:string'])
+
 
 class ModelFieldAccessWriteTestCase(_ModelFieldAccessTestCase):
     _perm = 'perm_write'

Reply via email to