Add conditional logic

This commit is contained in:
zandercymatics 2024-01-08 09:59:24 -07:00
parent 01a6de2392
commit 4c27186545
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 38 additions and 25 deletions

View file

@ -31,7 +31,9 @@
<tr> <tr>
<th data-sortable scope="col" role="columnheader">Email</th> <th data-sortable scope="col" role="columnheader">Email</th>
<th data-sortable scope="col" role="columnheader">Role</th> <th data-sortable scope="col" role="columnheader">Role</th>
<th scope="col" role="columnheader"><span class="sr-only">Action</span></th> {% if can_delete_users %}
<th scope="col" role="columnheader"><span class="sr-only">Action</span></th>
{% endif %}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -41,31 +43,33 @@
{{ permission.user.email }} {{ permission.user.email }}
</th> </th>
<td data-label="Role">{{ permission.role|title }}</td> <td data-label="Role">{{ permission.role|title }}</td>
<td class="shift-action-button"> {% if can_delete_users %}
<a <td class="shift-action-button">
id="button-toggle-user-alert-{{ forloop.counter }}" <a
href="#toggle-user-alert-{{ forloop.counter }}" id="button-toggle-user-alert-{{ forloop.counter }}"
class="usa-button--unstyled" href="#toggle-user-alert-{{ forloop.counter }}"
aria-controls="toggle-user-alert-{{ forloop.counter }}" class="usa-button--unstyled"
data-open-modal aria-controls="toggle-user-alert-{{ forloop.counter }}"
> data-open-modal
Remove >
</a> Remove
</a>
<div <div
class="usa-modal" class="usa-modal"
id="toggle-user-alert-{{ forloop.counter }}" id="toggle-user-alert-{{ forloop.counter }}"
aria-labelledby="Are you sure you want to continue?" aria-labelledby="Are you sure you want to continue?"
aria-describedby="User will be removed" aria-describedby="User will be removed"
data-force-action data-force-action
> >
<form method="POST" action="{% url "domain-user-delete" pk=domain.id user_pk=permission.user.id %}"> <form method="POST" action="{% url "domain-user-delete" pk=domain.id user_pk=permission.user.id %}">
{% with heading="Are you sure you want to remove <"|add:permission.user.email|add:">?" %} {% with heading="Are you sure you want to remove <"|add:permission.user.email|add:">?" %}
{% include 'includes/modal.html' with modal_heading=heading modal_description="<"|add:permission.user.email|add:"> will no longer be able to manage the domain "|add:domain.name|add:"." modal_button=modal_button|safe %} {% include 'includes/modal.html' with modal_heading=heading modal_description="<"|add:permission.user.email|add:"> will no longer be able to manage the domain "|add:domain.name|add:"." modal_button=modal_button|safe %}
{% endwith %} {% endwith %}
</form> </form>
</div> </div>
</td> </td>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View file

@ -630,6 +630,15 @@ class DomainUsersView(DomainBaseView):
"""The initial value for the form (which is a formset here).""" """The initial value for the form (which is a formset here)."""
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
domain_pk = None
can_delete_users = False
if self.kwargs is not None and "pk" in self.kwargs:
domain_pk = self.kwargs["pk"]
# Prevent the end user from deleting themselves as a manager if they are the
# only manager that exists on a domain.
can_delete_users = UserDomainRole.objects.filter(domain__id=domain_pk).count() > 1
context["can_delete_users"] = can_delete_users
# Create HTML for the modal button # Create HTML for the modal button
modal_button = ( modal_button = (
'<button type="submit" ' '<button type="submit" '