1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 04:36:48 +00:00

feat(security): apply Codex review hardening to console tokens and superuser authorization

This commit is contained in:
catborise 2026-09-27 11:30:03 +03:00
parent 1227674d8f
commit 708b986e8e
11 changed files with 168 additions and 26 deletions

View file

@ -1,7 +1,9 @@
from functools import wraps
from django.core.exceptions import PermissionDenied
def superuser_only(function):
@wraps(function)
def _inner(request, *args, **kwargs):
if not request.user.is_superuser:
raise PermissionDenied

15
admin/permissions.py Normal file
View file

@ -0,0 +1,15 @@
from rest_framework.permissions import BasePermission
class IsSuperUser(BasePermission):
"""
Allows access only to active superusers.
"""
def has_permission(self, request, view):
return bool(
request.user
and request.user.is_authenticated
and request.user.is_active
and request.user.is_superuser
)