@@ -0,0 +1,6 @@ +from django.utils.translation import gettext as _ + + +class BusinessAccountNotFound(Exception): + def __str__(self): + return _('Business account not found') @@ -5,6 +5,7 @@ from django.utils.translation import gettext_lazy as _ from rest_framework.request import Request from authentication.exceptions import business_host_exceptions +from authentication.exceptions.business_account import BusinessAccountNotFound from authentication.exceptions.business_host_exceptions import ( AlreadyAccount, AlreadyHasPlan, @@ -114,9 +115,6 @@ class BusinessHostService: return account_service - def delete_account(self, account: BusinessAccount): - account.delete() - def create(self, request: Request) -> BusinessAccountDataSerializer: serializer = NewBusinessAccountSerializer(data=request.data) serializer.is_valid(raise_exception=True) @@ -191,14 +189,14 @@ class BusinessHostService: def delete(self, request: Request): serializer = DeleteBusinessAccountSerializer(data=request.data) serializer.is_valid(raise_exception=True) - account = BusinessAccount.objects.filter( - parent_company=self.user.host_account, **serializer.validated_data - ) - if not account.exists(): - raise Exception(_('No business account by this uid at your company')) + parent_company=self.user.host_account, user__uid=serializer.validated_data['uid'] + ).first() + + if not account: + raise BusinessAccountNotFound - self.delete_account(account.first()) + account.delete() def create_host(self, request: Request) -> UserDataSerializer: serializer = NewBusinessHostSerializer(data=request.data) @@ -176,6 +176,7 @@ class DeleteBusinessAccountSerializer(serializers.Serializer): class BusinessAccountDataSerializer(serializers.Serializer): + uid = serializers.UUIDField(source='user.uid', read_only=True) email = serializers.EmailField(source='user.email') account_type = serializers.SerializerMethodField() acceptance_status = serializers.ChoiceField(choices=InvitationStatus.choices) @@ -25,7 +25,13 @@ from authentication.exceptions import BaseAlready from authentication.exceptions.business_host_exceptions.not_allowed_ip import ( NotAllowedIP, ) -from authentication.exceptions.user import EmailNotConfirmed, UserAlreadyExists, WrongEmail, WrongPassword, DomainNotFound +from authentication.exceptions.user import ( + DomainNotFound, + EmailNotConfirmed, + UserAlreadyExists, + WrongEmail, + WrongPassword, +) from authentication.models.business_group import BusinessGroup from authentication.models.business_host import BusinessUserHost from authentication.models.choices import AccountPrivileges, InvitationStatus @@ -103,7 +109,9 @@ class UserLoginAPIView(APIView): return Response({'detail': f'{exc}'}, status=status.HTTP_403_FORBIDDEN) except Exception as exc: logger.exception(exc) - return Response({'detail': _('Unexpected error')}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response( + {'detail': _('Server error occured')}, status=status.HTTP_500_INTERNAL_SERVER_ERROR + ) class MailWhitelist(APIView): @@ -210,7 +218,9 @@ class UserAPIView(APIView): return Response({'detail': _('Email not found')}, status=status.HTTP_400_BAD_REQUEST) except Exception as exc: logger.exception(exc) - return Response({'detail': _('Unexpected error')}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response( + {'detail': _('Server error occured')}, status=status.HTTP_500_INTERNAL_SERVER_ERROR + ) class UserTelegramAPIView(APIView): @@ -301,9 +311,12 @@ class BusinessHostAPIView(APIView): """Delete user company""" try: BusinessHostService(self.request.user).delete(request) - return Response({'detail': 'user deleted'}, status=status.HTTP_200_OK) - except Exception as err: - return Response({'detail': f'{err}'}, status=status.HTTP_400_BAD_REQUEST) + return Response({'detail': _('Business account has been deleted')}, status=status.HTTP_200_OK) + except Exception as exc: + logger.exception(exc) + return Response( + {'detail': _('Server error occured')}, status=status.HTTP_500_INTERNAL_SERVER_ERROR + ) class HostWorkersAPIView(APIView): @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-04-21 16:56+0300\n" +"POT-Creation-Date: 2025-04-27 01:01+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -44,8 +44,8 @@ msgid "Description" msgstr "Описание" #: achievements/models.py:43 authentication/models/business_host.py:21 -#: authentication/models/email_token.py:12 authentication/models/user.py:245 -#: authentication/models/user.py:246 authentication/models/user_telegram.py:22 +#: authentication/models/email_token.py:12 authentication/models/user.py:246 +#: authentication/models/user.py:247 authentication/models/user_telegram.py:22 #: authentication/models/user_vk.py:12 payments/models/invoice.py:15 #: payments/models/payment.py:26 payments/models/payment_plan.py:61 msgid "User" @@ -64,6 +64,10 @@ msgstr "Достижение %(achievement_title)s пользователя %(us msgid "Issued achievement" msgstr "Выданное достижение" +#: authentication/exceptions/business_account.py:6 +msgid "Business account not found" +msgstr "Сотрудник не найден" + #: authentication/exceptions/business_host_exceptions/not_allowed_ip.py:6 msgid "Current IP not allowed in this context" msgstr "Текущий IP не разрешен в данном контексте" @@ -159,7 +163,7 @@ msgstr "Бизнес Группы" msgid "Affiliated by" msgstr "Кем привлечена" -#: authentication/models/business_host.py:35 authentication/models/user.py:151 +#: authentication/models/business_host.py:35 authentication/models/user.py:152 #: authentication/models/whitelist.py:16 ml_model/models.py:163 #: payments/models/promocode.py:85 msgid "Is active" @@ -310,43 +314,43 @@ msgstr "Email Токен" msgid "Email Tokens" msgstr "Email Токены" -#: authentication/models/user.py:124 authentication/models/user_telegram.py:9 +#: authentication/models/user.py:125 authentication/models/user_telegram.py:9 msgid "First name" msgstr "Имя" -#: authentication/models/user.py:131 authentication/models/user_telegram.py:10 +#: authentication/models/user.py:132 authentication/models/user_telegram.py:10 msgid "Last name" msgstr "Фамилия" -#: authentication/models/user.py:138 authentication/models/user_telegram.py:11 +#: authentication/models/user.py:139 authentication/models/user_telegram.py:11 msgid "Username" msgstr "Имя пользователя" -#: authentication/models/user.py:145 +#: authentication/models/user.py:146 msgid "Email" msgstr "Email" -#: authentication/models/user.py:153 +#: authentication/models/user.py:154 msgid "Is staff" msgstr "Административный" -#: authentication/models/user.py:154 +#: authentication/models/user.py:155 msgid "Is superuser" msgstr "Суперюзер" -#: authentication/models/user.py:155 +#: authentication/models/user.py:156 msgid "Is email confirmed" msgstr "Email подтвержден" -#: authentication/models/user.py:156 +#: authentication/models/user.py:157 msgid "Is subscribed" msgstr "Подписан на уведомления" -#: authentication/models/user.py:162 +#: authentication/models/user.py:163 msgid "Picture name" msgstr "Имя аватара" -#: authentication/models/user.py:171 authentication/models/utm.py:21 +#: authentication/models/user.py:172 authentication/models/utm.py:21 msgid "UTM" msgstr "UTM" @@ -459,14 +463,10 @@ msgstr "Приглашенный аккаунт может принять или msgid "Account is already confirmed" msgstr "Аккаунт уже подтвержден" -#: authentication/services/business_host_service.py:152 +#: authentication/services/business_host_service.py:150 msgid "No user_email is provided" msgstr "" -#: authentication/services/business_host_service.py:199 -msgid "No business account by this uid at your company" -msgstr "Такого аккаунта нет в вашей компании" - #: authentication/services/email_service.py:45 msgid "Error occured when proceed email sending" msgstr "Случилась ошибка во время отправки email" @@ -479,42 +479,47 @@ msgstr "Обычные пользователи не могут отсылать msgid "Regular users cannot send invitation letters" msgstr "Обычные пользователи не могут отправлять письма для приглашений" -#: authentication/services/user_services.py:164 +#: authentication/services/user_services.py:161 msgid "No user like this in a database" msgstr "Такой пользователь отсутствует" -#: authentication/services/user_services.py:181 +#: authentication/services/user_services.py:178 msgid "token is not provided" msgstr "" -#: authentication/services/user_services.py:185 +#: authentication/services/user_services.py:182 msgid "No user token like this in a database" msgstr "" -#: authentication/services/user_services.py:205 +#: authentication/services/user_services.py:202 msgid "No email token provided" msgstr "Токен не получен" -#: authentication/services/user_services.py:209 +#: authentication/services/user_services.py:206 msgid "No token like this in a database" msgstr "Не найдено такого токена" -#: authentication/services/user_services.py:215 +#: authentication/services/user_services.py:212 msgid "Passwords do not match" msgstr "Пароли не совпадают" -#: authentication/services/user_services.py:253 +#: authentication/services/user_services.py:250 msgid "Current password is wrong" msgstr "Текущий пароль неверен" -#: authentication/views.py:107 authentication/views.py:214 -msgid "Unexpected error" -msgstr "Непредвиденная ошибка" +#: authentication/views.py:113 authentication/views.py:222 +#: authentication/views.py:318 +msgid "Server error occured" +msgstr "Случилась серверная ошибка" -#: authentication/views.py:211 +#: authentication/views.py:218 msgid "Email not found" msgstr "Email не найден" +#: authentication/views.py:314 +msgid "Business account has been deleted" +msgstr "Сотрудник успешно удален" + #: backend/urls.py:30 msgid "Requested object does not exists" msgstr ""