From 62561b27de103aa16786e8731269e62880b18fdf Mon Sep 17 00:00:00 2001 From: chirac Date: Thu, 31 Dec 2020 19:50:41 +0100 Subject: [PATCH] Correct customs acl list for extensions --- machines/models.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/machines/models.py b/machines/models.py index c6275bb8..4f359477 100644 --- a/machines/models.py +++ b/machines/models.py @@ -981,6 +981,32 @@ class Extension(RevMixin, AclMixin, models.Model): ("machines.use_all_extension",), ) + @classmethod + def can_list(cls, user_request, *_args, **_kwargs): + """All users can list unprivileged extensions + Only members of privileged groups can list all. + + :param user_request: The user who wants to view the list. + :return: True if the user can view the list and an explanation + message. + + """ + can, _message, _group = cls.can_use_all(user_request) + if can: + return ( + True, + None, + None, + cls.objects.all() + ) + else: + return ( + False, + _("You don't have the right to list all extensions."), + ("machines.use_all_extension",), + cls.objects.filter(need_infra=False), + ) + def __str__(self): return self.name