mirror of
https://github.com/pretix/pretix.git
synced 2026-06-12 01:35:16 +00:00
Security profiles: Ensure default profile is always listed first
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user