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 если пользователь имеет доступ