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>
{% if can_delete_users %}
<th scope="col" role="columnheader"><span class="sr-only">Action</span></th> <th scope="col" role="columnheader"><span class="sr-only">Action</span></th>
{% endif %}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -41,6 +43,7 @@
{{ permission.user.email }} {{ permission.user.email }}
</th> </th>
<td data-label="Role">{{ permission.role|title }}</td> <td data-label="Role">{{ permission.role|title }}</td>
{% if can_delete_users %}
<td class="shift-action-button"> <td class="shift-action-button">
<a <a
id="button-toggle-user-alert-{{ forloop.counter }}" id="button-toggle-user-alert-{{ forloop.counter }}"
@ -66,6 +69,7 @@
</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" '