fix contact for admin
This commit is contained in:
1 parent
f4fa16d9e7
commit
5fc9a908c5
2 files changed
+34
-1
No files matched your search
@@ -338,7 +338,15 @@ def staff_create(request):
|
||||
return render(request,"tickets/staff_create.html",{"form":form,"staff_unit":TicketPolicy.primary_unit(request.user),"active_tab_title":"ثبت تیکت برای مشتری"})
|
||||
|
||||
def _customer_rows(search="", user=None):
|
||||
qs=User.objects.filter(account_type=User.AccountType.CUSTOMER).select_related("customer_profile")
|
||||
# A CUSTOMER account can temporarily exist without its one-to-one profile
|
||||
# (legacy/imported or interrupted registrations). Such an account is not
|
||||
# an address-book contact and would make the contacts template dereference
|
||||
# a missing profile, especially for superusers whose scope includes all
|
||||
# customers.
|
||||
qs=User.objects.filter(
|
||||
account_type=User.AccountType.CUSTOMER,
|
||||
customer_profile__isnull=False,
|
||||
).select_related("customer_profile")
|
||||
has_unit_membership = user is not None and user.unit_memberships.filter(is_active=True, unit__is_active=True).exists()
|
||||
if user is not None and has_unit_membership and not (user.is_superuser or user.has_perm("tickets.view_all_tickets")):
|
||||
visible_customer_ids = staff_ticket_rows(user).values_list("customer_id", flat=True)
|
||||
|
||||
@@ -232,6 +232,31 @@ def test_staff_operations_pages_respect_unit_scoped_permissions(client):
|
||||
assert client.get(reverse("staff_tickets:sms_templates")).status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_superuser_without_staff_profile_can_open_all_staff_contacts(client):
|
||||
unit = OrganizationalUnit.objects.create(name="واحد مخاطبان مدیر", slug="admin-contacts-unit")
|
||||
contact = make_contact("admin-visible-contact", "09120000503")
|
||||
group = ContactGroup.objects.create(name="گروه قابل مشاهده مدیر", unit=unit)
|
||||
contact.customer_profile.groups.add(group)
|
||||
User.objects.create_user(
|
||||
username="customer-without-profile",
|
||||
mobile="09120000504",
|
||||
account_type=User.AccountType.CUSTOMER,
|
||||
)
|
||||
admin = User.objects.create_superuser(
|
||||
username="contacts-admin",
|
||||
password="safe-password",
|
||||
account_type=User.AccountType.STAFF,
|
||||
)
|
||||
|
||||
client.force_login(admin)
|
||||
response = client.get(reverse("staff_tickets:contacts"))
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "admin-visible-contact" in response.content.decode()
|
||||
assert "customer-without-profile" not in response.content.decode()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unit_scoped_add_ticket_preserves_contact_ownership_and_stakeholder(client):
|
||||
unit=OrganizationalUnit.objects.create(name="حسابداری عملیاتی",slug="accounting-ops")
|
||||
|
||||
Reference in new issue
Block a user