fix focus on ticket new, sitebranding, customer edit error

This commit is contained in:
javad committed 2026-09-16 12:44:43 +03:30
1 parent d72381f0ac
commit 6b841dc5fa
11 files changed
+139 -10

No files matched your search

+19 -3
View File
@@ -682,9 +682,19 @@ def _visible_dispatches(user):
def _contact_queryset(user):
"""Contacts visible through at least one of the staff member's units."""
"""Contacts visible through a permitted group or a viewable ticket.
A customer created by login or ticket intake may not have a contact group
yet. Keeping ticket-visible customers in this queryset makes the contact
list and its edit endpoint use the same visibility rule.
"""
visible_groups = ContactGroup.objects.filter(unit_id__in=_unit_ids_with_permission(user, "customers.view_customerprofile")).select_related("unit")
return CustomerProfile.objects.filter(groups__in=visible_groups).select_related("user").prefetch_related(Prefetch("groups", queryset=visible_groups, to_attr="visible_groups")).distinct()
visible_customer_ids = staff_ticket_rows(user).values_list("customer_id", flat=True)
return CustomerProfile.objects.filter(
Q(groups__in=visible_groups) | Q(user_id__in=visible_customer_ids)
).select_related("user").prefetch_related(
Prefetch("groups", queryset=visible_groups, to_attr="visible_groups")
).distinct()
def _has_any_unit_permission(user, permission):
@@ -747,7 +757,13 @@ def staff_contact_create(request):
def staff_contact_edit(request, public_id):
profile = get_object_or_404(_contact_queryset(request.user), user__public_id=public_id)
manageable_unit_ids = _unit_ids_with_permission(request.user, "customers.change_customerprofile")
if not set(profile.groups.values_list("unit_id", flat=True)) & manageable_unit_ids:
editable_through_group = profile.groups.filter(unit_id__in=manageable_unit_ids).exists()
editable_through_ticket = staff_ticket_rows(request.user).filter(
Q(assigned_unit_id__in=manageable_unit_ids)
| Q(assigned_unit__isnull=True, owning_unit_id__in=manageable_unit_ids),
customer_id=profile.user_id,
).exists()
if not (editable_through_group or editable_through_ticket):
raise PermissionDenied
form = StaffContactForm(request.POST or None, user=request.user, instance=profile, unit_ids=manageable_unit_ids)
if request.method == "POST" and form.is_valid():