fix: Обновить тесты и диагностические скрипты после удаления type='department'
- Обновлена фикстура department_chat: использует GenericFK и type='channel' - Обновлен тест test_create_department_chat для новой модели - Обновлен скрипт check_chat_access.py: удалена логика department - Добавлена поддержка типов group/channel в диагностике - Удалены все ссылки на удаленное поле department
This commit is contained in:
parent
9744009d6b
commit
359c5f7f9d
@ -46,12 +46,15 @@ def check_chat_access():
|
||||
participants = chat.participants.all()
|
||||
print(f" Участники (через participants): {[u.username for u in participants]}")
|
||||
|
||||
if chat.type == "department":
|
||||
print(f" Отдел: {chat.department}")
|
||||
if chat.department:
|
||||
# Используем get_participants для department чатов
|
||||
dept_users = chat.get_participants
|
||||
print(f" Сотрудники отдела: {[u.username or u.id for u in dept_users[:5]]}")
|
||||
if chat.type == "group" or chat.type == "channel":
|
||||
# Для групповых чатов и каналов показываем участников
|
||||
participants = chat.participants.all()
|
||||
if participants.exists():
|
||||
print(f" Участники: {[u.username for u in participants[:5]]}")
|
||||
|
||||
# Для каналов может быть привязан объект через GenericFK
|
||||
if chat.context_object:
|
||||
print(f" Привязан к: {chat.context_object} (тип: {chat.context_content_type})")
|
||||
|
||||
# Проверяем membership
|
||||
memberships = ChatMembership.objects.filter(chat=chat)
|
||||
@ -61,15 +64,15 @@ def check_chat_access():
|
||||
# Проверяем доступ для каждого пользователя
|
||||
print(f"\n Доступ пользователей к этому чату:")
|
||||
for user in users[:3]:
|
||||
departments = user.departments
|
||||
membership_chat_ids = ChatMembership.objects.filter(
|
||||
user=user
|
||||
).values_list('chat_id', flat=True)
|
||||
|
||||
has_access = Chat.objects.filter(
|
||||
Q(type="global")
|
||||
| Q(type="department", department__in=departments)
|
||||
| Q(type="private", participants=user)
|
||||
| Q(type="group", participants=user)
|
||||
| Q(type="channel", participants=user)
|
||||
| Q(id__in=membership_chat_ids)
|
||||
).filter(id=chat.id).exists()
|
||||
|
||||
@ -79,15 +82,16 @@ def check_chat_access():
|
||||
if not has_access:
|
||||
# Детальная проверка
|
||||
is_global = chat.type == "global"
|
||||
is_dept = chat.type == "department" and departments.filter(id=chat.department_id).exists()
|
||||
is_private = chat.type == "private" and chat.participants.filter(id=user.id).exists()
|
||||
is_group = chat.type == "group" and chat.participants.filter(id=user.id).exists()
|
||||
is_channel = chat.type == "channel" and chat.participants.filter(id=user.id).exists()
|
||||
is_member = chat.id in membership_chat_ids
|
||||
|
||||
print(f" - Глобальный: {is_global}")
|
||||
print(f" - Отдел: {is_dept}")
|
||||
print(f" - Личный участник: {is_private}")
|
||||
print(f" - Группа: {is_group}")
|
||||
print(f" - Канал: {is_channel}")
|
||||
print(f" - Через membership: {is_member}")
|
||||
print(f" - Отделы пользователя: {[d.name for d in departments]}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_chat_access()
|
||||
|
||||
@ -80,11 +80,14 @@ def group_chat(user1, user2, user3):
|
||||
|
||||
@pytest.fixture
|
||||
def department_chat(department, user1):
|
||||
"""Чат отдела"""
|
||||
"""Чат отдела (через GenericFK context_object)"""
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
dept_ct = ContentType.objects.get_for_model(Department)
|
||||
return Chat.objects.create(
|
||||
type="department",
|
||||
type="channel",
|
||||
name="Department Chat",
|
||||
department=department,
|
||||
context_content_type=dept_ct,
|
||||
context_object_id=department.id,
|
||||
created_by=user1,
|
||||
)
|
||||
|
||||
@ -1576,20 +1579,23 @@ class TestChatCreation:
|
||||
assert chat.participants.count() >= 3
|
||||
|
||||
def test_create_department_chat(self, auth_client, user1, department):
|
||||
"""Создание чата отдела"""
|
||||
"""Создание чата отдела через GenericFK"""
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
url = "/api/v1/communications/chats/"
|
||||
dept_ct = ContentType.objects.get_for_model(Department)
|
||||
data = {
|
||||
"type": "department",
|
||||
"type": "channel",
|
||||
"name": "Department Chat",
|
||||
"department": department.id,
|
||||
"context_content_type": dept_ct.id,
|
||||
"context_object_id": department.id,
|
||||
}
|
||||
response = auth_client.post(url, data, format="json")
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert response.data["type"] == "department"
|
||||
assert response.data["type"] == "channel"
|
||||
|
||||
chat = Chat.objects.get(id=response.data["id"])
|
||||
assert chat.department_id == department.id
|
||||
assert chat.context_object == department
|
||||
|
||||
def test_create_announcement_chat(self, auth_client, user1):
|
||||
"""Создание чата-объявления"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user