mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 10:59:21 +02:00
Merge branch 'main' into za/1851-check-how-user-was-verified
This commit is contained in:
commit
cb030cb694
15 changed files with 1623 additions and 81 deletions
|
@ -48,6 +48,34 @@ 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 is copied from the base implementation of UserChangeForm.
|
||||
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 <a href="{link}">this form</a>.'
|
||||
)
|
||||
|
||||
|
||||
class DomainInformationAdminForm(forms.ModelForm):
|
||||
"""This form utilizes the custom widget for its class's ManyToMany UIs."""
|
||||
|
@ -535,7 +563,7 @@ class MyUserAdmin(BaseUserAdmin):
|
|||
analyst_fieldsets = (
|
||||
(
|
||||
None,
|
||||
{"fields": ("password", "status", "verification_type")},
|
||||
{"fields": ("status", "verification_type",)},
|
||||
),
|
||||
("Personal Info", {"fields": ("first_name", "last_name", "email")}),
|
||||
(
|
||||
|
@ -561,7 +589,6 @@ class MyUserAdmin(BaseUserAdmin):
|
|||
# NOT all fields are readonly for admin, otherwise we would have
|
||||
# set this at the permissions level. The exception is 'status'
|
||||
analyst_readonly_fields = [
|
||||
"password",
|
||||
"Personal Info",
|
||||
"first_name",
|
||||
"last_name",
|
||||
|
@ -1727,21 +1754,27 @@ class DomainAdmin(ListHeaderAdmin):
|
|||
if domain is not None and hasattr(domain, "domain_info"):
|
||||
extra_context["original_object"] = domain.domain_info
|
||||
|
||||
extra_context["state_help_message"] = Domain.State.get_admin_help_text(domain.state)
|
||||
extra_context["domain_state"] = domain.get_state_display()
|
||||
|
||||
# Pass in what the an extended expiration date would be for the expiration date modal
|
||||
years_to_extend_by = self._get_calculated_years_for_exp_date(domain)
|
||||
try:
|
||||
curr_exp_date = domain.registry_expiration_date
|
||||
except KeyError:
|
||||
# No expiration date was found. Return none.
|
||||
extra_context["extended_expiration_date"] = None
|
||||
return super().changeform_view(request, object_id, form_url, extra_context)
|
||||
new_date = curr_exp_date + relativedelta(years=years_to_extend_by)
|
||||
extra_context["extended_expiration_date"] = new_date
|
||||
else:
|
||||
extra_context["extended_expiration_date"] = None
|
||||
self._set_expiration_date_context(domain, extra_context)
|
||||
|
||||
return super().changeform_view(request, object_id, form_url, extra_context)
|
||||
|
||||
def _set_expiration_date_context(self, domain, extra_context):
|
||||
"""Given a domain, calculate the an extended expiration date
|
||||
from the current registry expiration date."""
|
||||
years_to_extend_by = self._get_calculated_years_for_exp_date(domain)
|
||||
try:
|
||||
curr_exp_date = domain.registry_expiration_date
|
||||
except KeyError:
|
||||
# No expiration date was found. Return none.
|
||||
extra_context["extended_expiration_date"] = None
|
||||
else:
|
||||
new_date = curr_exp_date + relativedelta(years=years_to_extend_by)
|
||||
extra_context["extended_expiration_date"] = new_date
|
||||
|
||||
def response_change(self, request, obj):
|
||||
# Create dictionary of action functions
|
||||
ACTION_FUNCTIONS = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue