mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
fix(admin): the Users pages keep an administrator in and say what their fields mean
- An administrator could block, delete or demote (unset Active or Superuser on) their own account, and with it the last one, leaving the panel without anyone to undo it. These are now refused. - The user form showed "No password set." for users who have one: its password field never read the user's password. Its "Set password" link went to ../password/, a page this panel does not have. The form now says whether a password is set and links the page that sets it. - "Staff status" said "can log into this admin site"; here it lets a user change and delete the template VMs given to them, and is now called Template editor. - A quota of 0 counted as no limit, like -1, so a user's quota could not be taken away. Now -1 has no limit and 0 allows none; the help says so, and the labels give the units: memory in MiB, disk in GiB. - A user's page for a user that does not exist answered with a server error instead of not found. - The user list said "None" for a user who never logged in; it says "never", and dates fit their column. - The password form's labels no longer break mid-word.
This commit is contained in:
parent
07a2e09c2f
commit
0e8130f1b0
11 changed files with 161 additions and 43 deletions
|
|
@ -1,10 +1,7 @@
|
|||
from django import forms
|
||||
from django.contrib.auth import password_validation
|
||||
from django.contrib.auth.forms import ReadOnlyPasswordHashField
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from accounts.models import UserAttributes
|
||||
|
|
@ -72,26 +69,8 @@ class UserForm(forms.ModelForm):
|
|||
"is_active",
|
||||
"is_superuser",
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(UserForm, self).__init__(*args, **kwargs)
|
||||
if self.instance.id:
|
||||
password = ReadOnlyPasswordHashField(
|
||||
label=_("Password"),
|
||||
help_text=format_lazy(
|
||||
_(
|
||||
"""Raw passwords are not stored, so there is no way to see this user's password,
|
||||
but you can change the password using <a href='{}'>this form</a>."""
|
||||
),
|
||||
reverse_lazy(
|
||||
"admin:user_update_password",
|
||||
args=[
|
||||
self.instance.id,
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
self.fields["Password"] = password
|
||||
labels = {"is_staff": _("Template editor")}
|
||||
help_texts = {"is_staff": _("May change and delete the template VMs given to them")}
|
||||
|
||||
|
||||
class UserCreateForm(UserForm):
|
||||
|
|
@ -125,8 +104,7 @@ class UserCreateForm(UserForm):
|
|||
self.save_m2m()
|
||||
return user
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
class Meta(UserForm.Meta):
|
||||
fields = [
|
||||
"username",
|
||||
"password",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue