fix queue

This commit is contained in:
javad committed 2026-09-11 18:04:51 +03:30
1 parent 049cc41afc
commit 9a1c99cbd3
14 files changed
+237 -32

No files matched your search

+14 -7
View File
@@ -75,7 +75,7 @@ class TicketPolicy:
scope = cls.unit_scope(user, unit)
if scope == "UNIT": return True
return bool(ticket.origin_visibility == "PUBLIC" and ticket.owner_id is None and ticket.selected_expert_id is None)
return bool(not ticket.owning_unit_id and ticket.origin_visibility == "PUBLIC" and ticket.owner_id is None and ticket.selected_expert_id is None and user.has_perm("tickets.view_ticket"))
return False
@classmethod
def viewable_q(cls, user):
"""Database equivalent of can_view; use it for every staff ticket collection."""
@@ -88,14 +88,22 @@ class TicketPolicy:
if cls.has_unit_permission(user, item.unit, "tickets.view_ticket")
}
unit_wide_ids = set(memberships.filter(ticket_scope="UNIT", unit_id__in=permitted_ids).values_list("unit_id", flat=True))
unit_wide = Q(owning_unit_id__in=unit_wide_ids) | Q(assigned_unit_id__in=unit_wide_ids)
unit_wide = Q(assigned_unit_id__in=unit_wide_ids) | Q(
assigned_unit__isnull=True,
owning_unit_id__in=unit_wide_ids,
)
limited_ids = permitted_ids - unit_wide_ids
public_unassigned = (
(Q(owning_unit_id__in=limited_ids) | Q(assigned_unit_id__in=limited_ids))
& Q(origin_visibility="PUBLIC", selected_expert__isnull=True)
(
Q(assigned_unit_id__in=limited_ids)
| Q(assigned_unit__isnull=True, owning_unit_id__in=limited_ids)
)
& Q(origin_visibility="PUBLIC", owner__isnull=True, selected_expert__isnull=True)
)
legacy = Q(owning_unit__isnull=True, origin_visibility="PUBLIC", selected_expert__isnull=True) if user.has_perm("tickets.view_ticket") else Q(pk__in=[])
return direct | unit_wide | public_unassigned | legacy
# There is deliberately no global/unitless public queue. Legacy tickets
# must be assigned to a unit by the data migration before staff can see
# them through a unit queue.
return direct | unit_wide | public_unassigned
@classmethod
def can_reply(cls,user,ticket):
if not cls.can_view(user,ticket): return False
@@ -103,7 +111,6 @@ class TicketPolicy:
if cls.has_unit_permission(user,ticket.assigned_unit or ticket.owning_unit,"messaging.add_message"): return True
if user.has_perm("tickets.view_all_tickets") or ticket.owner_id==user.id or ticket.selected_expert_id==user.id or ticket.created_by_id==user.id: return True
if ticket.owner_id is None and ticket.selected_expert_id is None and user.has_perm("messaging.add_message"): return True
if not ticket.owning_unit_id and ticket.owner_id is None and ticket.selected_expert_id is None and user.has_perm("tickets.view_ticket"): return True
return ticket.access_grants.filter(user=user,revoked_at__isnull=True,permission_level__in=[TicketAccessGrant.Level.REPLY,TicketAccessGrant.Level.FULL]).exists()
@classmethod
def can_claim(cls,user,ticket):