From f5116315e840218424508e329dd15dcbb2c838c4 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:53:57 -0600 Subject: [PATCH] Override help text for AbstractUser --- src/registrar/admin.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 05bfc06b6..57c65199a 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -48,6 +48,35 @@ class MyUserAdminForm(UserChangeForm): "user_permissions": NoAutocompleteFilteredSelectMultiple("user_permissions", False), } + def __init__(self, *args, **kwargs): + """Custom init to modify the user form""" + super(MyUserAdminForm, self).__init__(*args, **kwargs) + self.override_base_help_texts() + + def override_base_help_texts(self): + """ + Used to override pre-existing help texts in AbstractUser. + This is done to avoid modifying the base AbstractUser class. + """ + is_superuser = self.fields.get("is_superuser") + is_staff = self.fields.get("is_staff") + password = self.fields.get("password") + + if is_superuser is not None: + is_superuser.help_text = ( + "For development purposes only; provides superuser access on the database level." + ) + + if is_staff is not None: + is_staff.help_text = "Designates whether the user can log in to this admin site." + + if password is not None: + link = f"../../{self.instance.pk}/password/" + password.help_text = ( + "Raw passwords are not stored, so they will not display here. " + f'You can change the password using this form.' + ) + class DomainInformationAdminForm(forms.ModelForm): """This form utilizes the custom widget for its class's ManyToMany UIs."""