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