Security profiles: Ensure default profile is always listed first

This commit is contained in:
Raphael Michel
2026-06-09 19:56:13 +02:00
parent 07d27e66d1
commit 8916fbe3c6

View File

@@ -20,7 +20,6 @@
# <https://www.gnu.org/licenses/>. # <https://www.gnu.org/licenses/>.
# #
import logging import logging
from collections import OrderedDict
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@@ -52,10 +51,18 @@ class BaseSecurityProfile:
""" """
raise NotImplementedError() raise NotImplementedError()
@property
def priority(self) -> int:
"""
Priority for ordering, higher will come first.
"""
return 100
class FullAccessSecurityProfile(BaseSecurityProfile): class FullAccessSecurityProfile(BaseSecurityProfile):
identifier = 'full' identifier = 'full'
verbose_name = _('Full device access (reading and changing orders and gift cards, reading of products and settings)') verbose_name = _('Full device access (reading and changing orders and gift cards, reading of products and settings)')
priority = 1000
def is_allowed(self, request): def is_allowed(self, request):
return True return True
@@ -190,13 +197,15 @@ def get_all_security_profiles():
if _ALL_PROFILES: if _ALL_PROFILES:
return _ALL_PROFILES return _ALL_PROFILES
types = OrderedDict() types = []
for recv, ret in register_device_security_profile.send(None): for recv, ret in register_device_security_profile.send(None):
if isinstance(ret, (list, tuple)): if isinstance(ret, (list, tuple)):
for r in ret: for r in ret:
types[r.identifier] = r types.append(r)
else: else:
types[ret.identifier] = ret types.append(ret)
types.sort(key=lambda el: el.priority, reverse=True)
types = {r.identifier: r for r in types}
_ALL_PROFILES = types _ALL_PROFILES = types
return types return types