mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-06-06 17:13:02 -04:00
fix: update documentation and fix smaller issues (#1520)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.password_validation import validate_password
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.core.mail import EmailMessage
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponseRedirect
|
||||
@@ -369,9 +371,15 @@ class UserDetail(APIView):
|
||||
|
||||
if action == "change_password":
|
||||
# Permission to edit user is already checked by self.get_user -> self.check_object_permissions
|
||||
if user.is_superuser and not request.user.is_superuser:
|
||||
raise PermissionDenied("You do not have permission to change a superuser's password.")
|
||||
password = request.data.get("password")
|
||||
if not password:
|
||||
return Response({"detail": "Password is required"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
try:
|
||||
validate_password(password, user=user)
|
||||
except DjangoValidationError as exc:
|
||||
return Response({"detail": list(exc.messages)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user