mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
Change: restrict altering and creation of superusers to superusers only (#8837)
This commit is contained in:
@@ -109,6 +109,25 @@ class UserViewSet(ModelViewSet):
|
||||
filterset_class = UserFilterSet
|
||||
ordering_fields = ("username",)
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
if not request.user.is_superuser and request.data.get("is_superuser") is True:
|
||||
return HttpResponseForbidden(
|
||||
"Superuser status can only be granted by a superuser",
|
||||
)
|
||||
return super().create(request, *args, **kwargs)
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
user_to_update: User = self.get_object()
|
||||
if (
|
||||
not request.user.is_superuser
|
||||
and request.data.get("is_superuser") is not None
|
||||
and request.data.get("is_superuser") != user_to_update.is_superuser
|
||||
):
|
||||
return HttpResponseForbidden(
|
||||
"Superuser status can only be changed by a superuser",
|
||||
)
|
||||
return super().update(request, *args, **kwargs)
|
||||
|
||||
@action(detail=True, methods=["post"])
|
||||
def deactivate_totp(self, request, pk=None):
|
||||
request_user = request.user
|
||||
|
Reference in New Issue
Block a user