Add user group archiving functionality with HTMX support

This commit is contained in:
Ross
2025-12-29 09:53:57 +00:00
parent 17330681a2
commit df0b26de36
4 changed files with 86 additions and 33 deletions
+31
View File
@@ -4919,6 +4919,37 @@ def user_group_view_all(request):
)
@user_is_cid_user_manager
def user_group_toggle_archive(request, pk):
"""HTMX endpoint to archive or unarchive a UserUserGroup.
POST params:
- archive: 'true' or 'false'
- view_all: optional '1' to indicate the caller is viewing the all-groups list
Returns an HTML fragment for the updated group card, or an empty
response when the card should be removed from the page (e.g. archiving
from the active-only view).
"""
if request.method != "POST":
return HttpResponse(status=405)
group = get_object_or_404(UserUserGroup, pk=pk)
archive_val = request.POST.get("archive", "true")
group.archive = True if archive_val == "true" else False
group.save()
view_all = True if request.POST.get("view_all") == "1" else False
# If the group is now archived and the caller is not viewing archived
# groups, remove the card from the page by returning an empty fragment.
if group.archive and not view_all:
return HttpResponse("")
return render(request, "generic/partials/user_group_card.html", {"group": group, "view_all": view_all})
@login_required
def user_toggle_group(request, user_id, group_id):
"""Toggle membership of a user in either a UserUserGroup or an auth Group.