Add logic for self deletion

This commit is contained in:
zandercymatics 2024-01-16 10:56:56 -07:00
parent 0618a72c11
commit 40e91ead1f
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 69 additions and 47 deletions

View file

@ -26,18 +26,21 @@ a.usa-button {
text-decoration: none;
}
a.usa-button.disabled-link {
a.usa-button.disabled-link,
a.usa-button--unstyled.disabled-link {
background-color: #ccc !important;
color: #454545 !important
}
a.usa-button.disabled-link:hover {
a.usa-button.disabled-link:hover,
a.usa-button--unstyled.disabled-link {
background-color: #ccc !important;
cursor: not-allowed !important;
color: #454545 !important
}
a.usa-button.disabled-link:focus {
a.usa-button.disabled-link:focus,
a.usa-button--unstyled.disabled-link {
background-color: #ccc !important;
cursor: not-allowed !important;
outline: none !important;

View file

@ -16,10 +16,8 @@
<li>There is no limit to the number of domain managers you can add.</li>
<li>After adding a domain manager, an email invitation will be sent to that user with
instructions on how to set up an account.</li>
<li>To remove a domain manager, <a href="{% public_site_url 'contact/' %}"
target="_blank" rel="noopener noreferrer" class="usa-link">contact us</a> for
assistance.</li>
<li>All domain managers must keep their contact information updated and be responsive if contacted by the .gov team.</li>
<li>Domains must have at least one domain manager. You cant remove yourself as a domain manager if youre the only one assigned to this domain. Add another domain manager before you remove yourself from this domain.</li>
</ul>
{% if domain.permissions %}
@ -31,9 +29,7 @@
<tr>
<th data-sortable scope="col" role="columnheader">Email</th>
<th data-sortable scope="col" role="columnheader">Role</th>
{% if can_delete_users %}
<th scope="col" role="columnheader"><span class="sr-only">Action</span></th>
{% endif %}
<th scope="col" role="columnheader"><span class="sr-only">Action</span></th>
</tr>
</thead>
<tbody>
@ -43,49 +39,66 @@
{{ permission.user.email }}
</th>
<td data-label="Role">{{ permission.role|title }}</td>
<td class="shift-action-button">
{% if can_delete_users %}
<td class="shift-action-button">
<a
id="button-toggle-user-alert-{{ forloop.counter }}"
href="#toggle-user-alert-{{ forloop.counter }}"
class="usa-button--unstyled text-no-underline"
aria-controls="toggle-user-alert-{{ forloop.counter }}"
data-open-modal
<a
id="button-toggle-user-alert-{{ forloop.counter }}"
href="#toggle-user-alert-{{ forloop.counter }}"
class="usa-button--unstyled text-no-underline"
aria-controls="toggle-user-alert-{{ forloop.counter }}"
data-open-modal
>
Remove
</a>
{# Display a custom message if the user is trying to delete themselves #}
{% if permission.user.email == current_user_email %}
<div
class="usa-modal usa-modal--lg"
id="toggle-user-alert-{{ forloop.counter }}"
aria-labelledby="Are you sure you want to continue?"
aria-describedby="You will be removed from this domain"
data-force-action
>
Remove
</a>
{# Display a custom message if the user is trying to delete themselves #}
{% if permission.user.email == current_user_email %}
<div
<form method="POST" action="{% url "domain-user-delete" pk=domain.id user_pk=permission.user.id %}">
{% with domain_name=domain.name|force_escape %}
{% include 'includes/modal.html' with modal_heading="Are you sure you want to remove yourself as a domain manager for "|add:domain_name|add:"?"|safe modal_description="You will no longer be able to manage the domain <strong>"|add:domain_name|add:"</strong>."|safe modal_button=modal_button_self|safe %}
{% endwith %}
</form>
</div>
{% else %}
<div
class="usa-modal usa-modal--lg"
id="toggle-user-alert-{{ forloop.counter }}"
aria-labelledby="Are you sure you want to continue?"
aria-describedby="You will be removed from this domain"
aria-describedby="{{ permission.user.email }} will be removed"
data-force-action
>
<form method="POST" action="{% url "domain-user-delete" pk=domain.id user_pk=permission.user.id %}">
{% with domain_name=domain.name|force_escape %}
{% include 'includes/modal.html' with modal_heading="Are you sure you want to remove yourself as a domain manager for "|add:domain_name|add:"?"|safe modal_description="You will no longer be able to manage the domain <strong>"|add:domain_name|add:"</strong>."|safe modal_button=modal_button_self|safe %}
{% endwith %}
</form>
</div>
{% else %}
<div
class="usa-modal usa-modal--lg"
id="toggle-user-alert-{{ forloop.counter }}"
aria-labelledby="Are you sure you want to continue?"
aria-describedby="{{ permission.user.email }} will be removed"
data-force-action
>
<form method="POST" action="{% url "domain-user-delete" pk=domain.id user_pk=permission.user.id %}">
{% with email=permission.user.email|force_escape domain_name=domain.name|force_escape %}
{% include 'includes/modal.html' with modal_heading="Are you sure you want to remove &lt;"|add:email|add:"&gt;?"|safe modal_description="<strong>&lt;"|add:email|add:"&gt;</strong> will no longer be able to manage the domain <strong>"|add:domain_name|add:"</strong>."|safe modal_button=modal_button|safe %}
{% endwith %}
</form>
</div>
{% endif %}
</td>
>
<form method="POST" action="{% url "domain-user-delete" pk=domain.id user_pk=permission.user.id %}">
{% with email=permission.user.email|default:permission.user|force_escape domain_name=domain.name|force_escape %}
{% include 'includes/modal.html' with modal_heading="Are you sure you want to remove &lt;"|add:email|add:"&gt;?"|safe modal_description="<strong>&lt;"|add:email|add:"&gt;</strong> will no longer be able to manage the domain <strong>"|add:domain_name|add:"</strong>."|safe modal_button=modal_button|safe %}
{% endwith %}
</form>
</div>
{% endif %}
{% else %}
<a
class="usa-button--unstyled disabled-link usa-tooltip text-no-underline "
data-position="top"
title="Domains must have at least one domain manager"
aria-disabled="true"
data-tooltip="true"
>
Remove
</a>
{% endif %}
</td>
{% comment %}
usa-tooltip disabled-link"
data-position="right"
title="Coming in 2024"
aria-disabled="true"
data-tooltip="true"
{% endcomment %}
</tr>
{% endfor %}
</tbody>

View file

@ -820,13 +820,18 @@ class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
return UserDomainRole.objects.get(domain=domain_id, user=user_id)
def get_success_url(self):
"""Refreshes the page after a delete is successful"""
return reverse("domain-users", kwargs={"pk": self.object.domain.id})
def get_success_message(self, delete_self = False):
"""Returns confirmation content for the deletion event """
email_or_name = self.object.user.email
if email_or_name is None:
email_or_name = self.object.user
if delete_self:
message = f"You are no longer managing the domain {self.object.domain}."
else:
message = f"Removed {self.object.user.email} as a manager for this domain."
message = f"Removed {email_or_name} as a manager for this domain."
return message
def form_valid(self, form):
@ -842,10 +847,11 @@ class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
return redirect(self.get_success_url())
def post(self, request, *args, **kwargs):
"""Custom post implementation to redirect to home in the event that the user deletes themselves"""
response = super().post(request, *args, **kwargs)
# If the user is deleting themselves, redirect to home
if self.request.user.email == self.object.user.email:
if self.request.user == self.object.user:
return redirect(reverse("home"))
return response