From 7c8ed68a6b58b75cc8921c5c3e5cbdafb5f61416 Mon Sep 17 00:00:00 2001 From: lizerk Date: Wed, 11 Mar 2026 16:48:20 +0300 Subject: [PATCH] =?UTF-8?q?refactor(communications):=20=D0=9F=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?Employee=20=D0=B2=20User=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=BD?= =?UTF-8?q?=D0=B8=D0=B2=D0=B5=D1=80=D1=81=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Заменено Employee на User во всех файлах модуля communications - Использование нейтрального названия вместо проектно-специфичного - Изменено 6 файлов: models.py, viewsets.py, serializers.py, handlers.py, signals.py, utils.py - Улучшена переиспользуемость модуля communications --- backend/communications/api/serializers.py | 4 ++-- backend/communications/api/viewsets.py | 2 +- backend/communications/models.py | 8 ++++---- backend/communications/notifications/handlers.py | 6 +++--- backend/communications/notifications/signals.py | 4 ++-- backend/communications/utils.py | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/communications/api/serializers.py b/backend/communications/api/serializers.py index ab22096c..40400314 100644 --- a/backend/communications/api/serializers.py +++ b/backend/communications/api/serializers.py @@ -10,7 +10,7 @@ from ..models import ( ) from ..serialization import serialize_message -Employee = get_user_model() +User = get_user_model() class ChatUserSettingsSerializer(serializers.ModelSerializer): @@ -112,7 +112,7 @@ class ChatDetailSerializer(serializers.ModelSerializer): """Детальный сериализатор чата""" participants = serializers.PrimaryKeyRelatedField( many=True, - queryset=Employee.objects.all(), + queryset=User.objects.all(), required=False ) participant_details = serializers.SerializerMethodField() diff --git a/backend/communications/api/viewsets.py b/backend/communications/api/viewsets.py index 839c938c..295953db 100644 --- a/backend/communications/api/viewsets.py +++ b/backend/communications/api/viewsets.py @@ -44,7 +44,7 @@ from .serializers import (BulkDeleteSerializer, ChatDetailSerializer, ReactionSerializer) logger = logging.getLogger(__name__) -Employee = get_user_model() +User = get_user_model() class ChatViewSet(viewsets.ModelViewSet): diff --git a/backend/communications/models.py b/backend/communications/models.py index 8aefc49d..3a993136 100644 --- a/backend/communications/models.py +++ b/backend/communications/models.py @@ -8,7 +8,7 @@ from django.db import IntegrityError, models from django.db.models import Q from django.utils import timezone -Employee = get_user_model() +User = get_user_model() class ChatReadState(models.Model): @@ -320,10 +320,10 @@ class Chat(models.Model): return self.participants.all() if self.type == "global": - return Employee.objects.filter(is_active=True) + return User.objects.filter(is_active=True) if self.type in ["announcement", "channel"] and self.include_all_users: - return Employee.objects.filter(is_active=True) + return User.objects.filter(is_active=True) # Для group/channel/announcement без флага - явные участники from communications.models import ChatMembership @@ -332,7 +332,7 @@ class Chat(models.Model): chat=self ).values_list("user_id", flat=True) - return Employee.objects.filter( + return User.objects.filter( Q(id__in=self.participants.values_list('id', flat=True)) | Q(id__in=membership_ids) ).distinct() diff --git a/backend/communications/notifications/handlers.py b/backend/communications/notifications/handlers.py index a256bab1..e5c1318f 100644 --- a/backend/communications/notifications/handlers.py +++ b/backend/communications/notifications/handlers.py @@ -20,7 +20,7 @@ from .config import ( get_chat_name, ) -Employee = get_user_model() +User = get_user_model() def get_users_with_notifications_enabled(chat, users) -> dict[int, bool]: @@ -92,7 +92,7 @@ def notify_new_message(message): if mentioned_users: for email in mentioned_users: try: - user = Employee.objects.get(email=email) + user = User.objects.get(email=email) if user in participants_list and user.id != author.id: if notification_settings.get(user.id, True): notify.send( @@ -111,7 +111,7 @@ def notify_new_message(message): } ) notified_user_ids.add(user.id) - except Employee.DoesNotExist: + except User.DoesNotExist: continue # 2. ОТВЕТЫ НА СООБЩЕНИЯ diff --git a/backend/communications/notifications/signals.py b/backend/communications/notifications/signals.py index 034766a0..25a711b7 100644 --- a/backend/communications/notifications/signals.py +++ b/backend/communications/notifications/signals.py @@ -13,7 +13,7 @@ from django.dispatch import receiver from ..models import Message, Chat from .handlers import notify_new_message, notify_chat_added -Employee = get_user_model() +User = get_user_model() @receiver(post_save, sender=Message) @@ -56,7 +56,7 @@ def create_chat_added_notifications(sender, instance, action, pk_set, **kwargs): added_by = getattr(chat, 'created_by', None) or chat.participants.first() # ОПТИМИЗАЦИЯ: Получаем всех новых пользователей одним запросом - new_users = Employee.objects.filter(id__in=pk_set) + new_users = User.objects.filter(id__in=pk_set) # Отправляем уведомления через handlers notify_chat_added(chat, new_users, added_by=added_by) diff --git a/backend/communications/utils.py b/backend/communications/utils.py index f99ac789..488af82b 100644 --- a/backend/communications/utils.py +++ b/backend/communications/utils.py @@ -69,7 +69,7 @@ def user_can_access_chat(chat: Chat, user) -> bool: Args: chat: Объект Chat - user: Объект User (Employee) + user: Объект User Returns: bool: True если пользователь имеет доступ