fix del contact from group and image for ticket

This commit is contained in:
javad committed 2026-09-13 20:11:59 +03:30
1 parent 5fc9a908c5
commit a18a68578f
7 files changed
+168 -9

No files matched your search

+86
View File
@@ -257,6 +257,92 @@ def test_superuser_without_staff_profile_can_open_all_staff_contacts(client):
assert "customer-without-profile" not in response.content.decode()
@pytest.mark.django_db
def test_staff_can_visually_add_and_remove_contact_group_memberships(client):
unit = OrganizationalUnit.objects.create(name="واحد ویرایش مخاطب", slug="contact-membership-editor")
unit.permissions.add(*Permission.objects.filter(
content_type__app_label="customers",
codename__in=("view_customerprofile", "change_customerprofile"),
))
staff = make_staff("contact-membership-agent", unit)
contact = make_contact("editable-contact", "09120000505")
first = ContactGroup.objects.create(name="گروه اولیه", unit=unit)
second = ContactGroup.objects.create(name="گروه جایگزین", unit=unit)
contact.customer_profile.groups.add(first)
client.force_login(staff)
url = reverse("staff_tickets:contact_edit", args=[contact.public_id])
page = client.get(url)
content = page.content.decode()
assert page.status_code == 200
assert "data-contact-group-selector" in content
assert "data-group-search" in content
assert str(first.pk) in {str(value) for value in page.context["form"]["groups"].value()}
assert f'value="{second.pk}"' in content
response = client.post(url, {
"mobile": contact.local_mobile,
"first_name": "مخاطب",
"last_name": "ویرایش‌شده",
"organization_name": "",
"stakeholder_type": CustomerProfile.StakeholderType.CUSTOMER,
"groups": [second.pk],
"province": "",
"city": "",
})
assert response.status_code == 302
assert set(contact.customer_profile.groups.values_list("pk", flat=True)) == {second.pk}
@pytest.mark.django_db
def test_staff_ticket_create_supports_multiple_previewable_attachments(client, monkeypatch, settings, tmp_path):
settings.MEDIA_ROOT = tmp_path
unit = OrganizationalUnit.objects.create(name="واحد پیوست کارشناس", slug="staff-attachment-unit")
unit.permissions.add(Permission.objects.get(content_type__app_label="tickets", codename="add_ticket"))
staff = make_staff("staff-attachment-agent", unit)
category = TicketCategory.objects.create(unit=unit, title="مدارک", slug="staff-attachment-category")
AttachmentPolicy.objects.create(attachment_type="IMAGE", max_file_size=1024 * 1024, allowed_extensions=[".jpg"])
AttachmentPolicy.objects.create(attachment_type="PDF", max_file_size=1024 * 1024, allowed_extensions=[".pdf"])
monkeypatch.setattr(
"apps.attachments.services.magic.from_buffer",
lambda content, mime=True: "image/jpeg" if content.startswith(b"\xff\xd8") else "application/pdf",
)
client.force_login(staff)
url = reverse("staff_tickets:create")
page = client.get(url)
content = page.content.decode()
assert page.status_code == 200
assert "data-ticket-composer" in content
assert "data-gallery-input" in content
assert "data-document-input" in content
assert "data-file-preview" in content
assert "attachment-uploader.js" in content
assert "ایجاد پرونده از طرف واحد پیوست کارشناس" in content
response = client.post(url, {
"unit": unit.pk,
"customer_mobile": "09120000506",
"first_name": "مشتری",
"last_name": "پیوست",
"stakeholder_type": CustomerProfile.StakeholderType.CUSTOMER,
"category": category.pk,
"subject": "ارسال همزمان تصویر و سند",
"body": "دو فایل برای این پرونده ثبت می‌شود.",
"files": [
SimpleUploadedFile("photo.jpg", b"\xff\xd8\xff\xe0image", content_type="image/jpeg"),
SimpleUploadedFile("document.pdf", b"%PDF-1.4\n%%EOF", content_type="application/pdf"),
],
})
assert response.status_code == 302
ticket = Ticket.objects.get(subject="ارسال همزمان تصویر و سند")
assert set(ticket.ticket_messages.get().attachments.values_list("original_name", flat=True)) == {
"photo.jpg", "document.pdf",
}
@pytest.mark.django_db
def test_unit_scoped_add_ticket_preserves_contact_ownership_and_stakeholder(client):
unit=OrganizationalUnit.objects.create(name="حسابداری عملیاتی",slug="accounting-ops")