This commit is contained in:
zandercymatics 2024-01-17 09:41:19 -07:00
parent 12d5905ef9
commit f16382e946
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 25 additions and 23 deletions

View file

@ -10,6 +10,7 @@ from django.contrib import messages
from registrar.forms import application_wizard as forms from registrar.forms import application_wizard as forms
from registrar.models import DomainApplication from registrar.models import DomainApplication
from registrar.models.user import User
from registrar.utility import StrEnum from registrar.utility import StrEnum
from registrar.views.utility import StepsHelper from registrar.views.utility import StepsHelper
@ -131,11 +132,19 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
if self._application: if self._application:
return self._application return self._application
# For linter. The else block should never be hit, but if it does,
# there may be a UI consideration. That will need to be handled in another ticket.
creator = None
if self.request.user is not None and isinstance(self.request.user, User):
creator = self.request.user
else:
raise ValueError("Invalid value for User")
if self.has_pk(): if self.has_pk():
id = self.storage["application_id"] id = self.storage["application_id"]
try: try:
self._application = DomainApplication.objects.get( self._application = DomainApplication.objects.get(
creator=self.request.user, # type: ignore creator=creator,
pk=id, pk=id,
) )
return self._application return self._application
@ -476,6 +485,7 @@ class DotgovDomain(ApplicationWizard):
self.application.save() self.application.save()
return response return response
class Purpose(ApplicationWizard): class Purpose(ApplicationWizard):
template_name = "application_purpose.html" template_name = "application_purpose.html"
forms = [forms.PurposeForm] forms = [forms.PurposeForm]

View file

@ -34,7 +34,7 @@ from registrar.utility.errors import (
SecurityEmailErrorCodes, SecurityEmailErrorCodes,
) )
from registrar.models.utility.contact_error import ContactError from registrar.models.utility.contact_error import ContactError
from registrar.views.utility.permission_views import UserDomainRolePermissionDeleteView, UserDomainRolePermissionView from registrar.views.utility.permission_views import UserDomainRolePermissionDeleteView
from ..forms import ( from ..forms import (
ContactForm, ContactForm,
@ -643,7 +643,6 @@ class DomainUsersView(DomainBaseView):
return context return context
def _add_booleans_to_context(self, context): def _add_booleans_to_context(self, context):
# Determine if the current user can delete managers # Determine if the current user can delete managers
domain_pk = None domain_pk = None
can_delete_users = False can_delete_users = False
@ -660,17 +659,17 @@ class DomainUsersView(DomainBaseView):
"""Adds modal buttons (and their HTML) to the context""" """Adds modal buttons (and their HTML) to the context"""
# Create HTML for the modal button # Create HTML for the modal button
modal_button = self._create_modal_button_html( modal_button = self._create_modal_button_html(
button_name="delete_domain_manager", button_name="delete_domain_manager",
button_text_content="Yes, remove domain manager", button_text_content="Yes, remove domain manager",
classes=["usa-button", "usa-button--secondary"] classes=["usa-button", "usa-button--secondary"],
) )
context["modal_button"] = modal_button context["modal_button"] = modal_button
# Create HTML for the modal button when deleting yourself # Create HTML for the modal button when deleting yourself
modal_button_self= self._create_modal_button_html( modal_button_self = self._create_modal_button_html(
button_name="delete_domain_manager_self", button_name="delete_domain_manager_self",
button_text_content="Yes, remove myself", button_text_content="Yes, remove myself",
classes=["usa-button", "usa-button--secondary"] classes=["usa-button", "usa-button--secondary"],
) )
context["modal_button_self"] = modal_button_self context["modal_button_self"] = modal_button_self
@ -686,11 +685,7 @@ class DomainUsersView(DomainBaseView):
html_class = f'class="{class_list}"' if class_list else None html_class = f'class="{class_list}"' if class_list else None
modal_button = ( modal_button = '<button type="submit" ' f"{html_class} " f'name="{button_name}">{button_text_content}</button>'
'<button type="submit" '
f"{html_class} "
f'name="{button_name}">{button_text_content}</button>'
)
return modal_button return modal_button
@ -809,8 +804,8 @@ class DomainInvitationDeleteView(DomainInvitationPermissionDeleteView, SuccessMe
class DomainDeleteUserView(UserDomainRolePermissionDeleteView): class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
"""Inside of a domain's user management, a form for deleting users. """Inside of a domain's user management, a form for deleting users."""
"""
object: UserDomainRole # workaround for type mismatch in DeleteView object: UserDomainRole # workaround for type mismatch in DeleteView
def get_object(self, queryset=None): def get_object(self, queryset=None):
@ -823,8 +818,8 @@ class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
"""Refreshes the page after a delete is successful""" """Refreshes the page after a delete is successful"""
return reverse("domain-users", kwargs={"pk": self.object.domain.id}) return reverse("domain-users", kwargs={"pk": self.object.domain.id})
def get_success_message(self, delete_self = False): def get_success_message(self, delete_self=False):
"""Returns confirmation content for the deletion event """ """Returns confirmation content for the deletion event"""
# Grab the text representation of the user we want to delete # Grab the text representation of the user we want to delete
email_or_name = self.object.user.email email_or_name = self.object.user.email
@ -860,5 +855,5 @@ class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
delete_self = self.request.user == self.object.user delete_self = self.request.user == self.object.user
if delete_self: if delete_self:
return redirect(reverse("home")) return redirect(reverse("home"))
return response return response

View file

@ -307,7 +307,7 @@ class UserDomainRolePermission(PermissionsLoginMixin):
# Check if the UserDomainRole object exists, then check # Check if the UserDomainRole object exists, then check
# if the user requesting the delete has permissions to do so # if the user requesting the delete has permissions to do so
has_delete_permission = UserDomainRole.objects.filter( has_delete_permission = UserDomainRole.objects.filter(
user=user_pk, user=user_pk,
domain=domain_pk, domain=domain_pk,
domain__permissions__user=self.request.user, domain__permissions__user=self.request.user,
).exists() ).exists()
@ -316,9 +316,7 @@ class UserDomainRolePermission(PermissionsLoginMixin):
# Check if more than one manager exists on the domain. # Check if more than one manager exists on the domain.
# If only one exists, prevent this from happening # If only one exists, prevent this from happening
has_multiple_managers = len(UserDomainRole.objects.filter( has_multiple_managers = len(UserDomainRole.objects.filter(domain=domain_pk)) > 1
domain=domain_pk
)) > 1
if not has_multiple_managers: if not has_multiple_managers:
return False return False

View file

@ -152,4 +152,3 @@ class UserDomainRolePermissionDeleteView(UserDomainRolePermissionView, DeleteVie
model = UserDomainRole model = UserDomainRole
# variable name in template context for the model object # variable name in template context for the model object
context_object_name = "userdomainrole" context_object_name = "userdomainrole"