Projet

Général

Profil

0001-formdef-forbid-use-of-data_class-on-lightweight-form.patch

Benjamin Dauvergne, 22 février 2021 23:53

Télécharger (1,94 ko)

Voir les différences:

Subject: [PATCH 1/3] formdef: forbid use of data_class() on lightweight
 formdef (#51327)

 wcs/api.py     | 2 +-
 wcs/formdef.py | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)
wcs/api.py
622 622
                    )
623 623
                else:
624 624
                    # naive count
625
                    count = formdef.data_class().count()
625
                    count = formdef.data_class(lightweight=True).count()
626 626
                formdict['count'] = count
627 627

  
628 628
            formdict['functions'] = {}
wcs/formdef.py
288 288
    def data_class_name(self):
289 289
        return '_wcs_%s' % self.url_name.title()
290 290

  
291
    def data_class(self, mode=None):
291
    def data_class(self, mode=None, lightweight=False):
292
        if getattr(self, 'fields', None) is Ellipsis and not lightweight:
293
            raise RuntimeError('accessing data from a lightweight object is not allowed')
294

  
292 295
        if not 'formdef' in sys.modules:
293 296
            sys.modules['formdef'] = sys.modules[__name__]
294 297
        if hasattr(sys.modules['formdef'], self.data_class_name):
......
1404 1407
        # if no formdata was given, lookup if there are some existing formdata
1405 1408
        # where the user has access.
1406 1409
        if not formdata:
1407
            data_class = self.data_class()
1410
            data_class = self.data_class(lightweight=True)
1408 1411
            for role_id in user.get_roles():
1409 1412
                if data_class.get_ids_with_indexed_value('workflow_roles', role_id):
1410 1413
                    return True
1411
-