@@ -4,3 +4,8 @@ from django.utils.translation import gettext as _ class BusinessAccountNotFound(Exception): def __str__(self): return _('Business account not found') + + +class AdminReinviteForbidden(Exception): + def __str__(self): + return _('You cannot reinvite other administrators') @@ -63,9 +63,7 @@ class BusinessAccountService: @classmethod def get_company_name(cls, user: CustomUserModel): - if user.account_type == 'business_host': - return user.host_account - return user.business_account.parent_company + return user.host or user.employee.parent_company def update(self, data: OrderedDict) -> BusinessAccount: if data['status'] == InvitationStatus.ACCEPTED: @@ -6,7 +6,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_account import BusinessAccountNotFound, AdminReinviteForbidden from authentication.exceptions.business_host_exceptions import AlreadyAccount, InviteeHasPlan from authentication.exceptions.business_host_exceptions.access_denied import AccessDenied from authentication.exceptions.business_host_exceptions.already_host import ( @@ -258,11 +258,8 @@ class BusinessHostService: return BusinessHostSelector(self.user).get_allowed_models() def reinvite_business_account(self, business_account: BusinessAccount) -> None: - if ( - self.user.account_type == business_account.user.account_type - and self.user.account_type == 'business_admin' - ): - raise AccessDenied + if self.user.account_type == 'business_admin' == business_account.user.account_type: + raise AdminReinviteForbidden password = generate_token(15) business_account.user.set_password(password) business_account.user.save() @@ -127,9 +127,15 @@ class EmailService: ) def send_reinvited_email(self, account: BusinessAccount, password: str | None = None) -> None: + token = EmailTokenService(account.user).generate_user_token() html_message = self._render_letter_template( - template_name='authentication/reinvited_employee_letter', - context={'email': account.user.email, 'password': password}, + template_name='authentication/corporate_greeting_email', + context={ + 'business_account': account, + 'invitation_url': settings.INVITATION_RESPONSE_URL, + 'token': token.key, + 'password': password, + }, ) self.send_email( subject='Ваш аккаунт на платформе AIR', message=html_message, user_emails=(account.user.email,) @@ -16,7 +16,7 @@ class EmailTokenService: return EmailToken.objects.create(user=self.user, key=generate_token(22)) @classmethod - def get_token(self, key: str) -> EmailToken: + def get_token(cls, key: str) -> EmailToken: try: return EmailToken.objects.get(key=key) except EmailToken.DoesNotExist: @@ -1,12 +0,0 @@ - - - - - Ваш аккаунт на платформе AIR: - - -

Новые данные для входа на платформу AIR:

-

E-mail: {{ email }}

-

Пароль: {{ password }}

- - @@ -23,7 +23,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from authentication.exceptions import BaseAlready -from authentication.exceptions.business_host_exceptions.access_denied import AccessDenied +from authentication.exceptions.business_account import AdminReinviteForbidden from authentication.exceptions.business_host_exceptions.not_allowed_ip import ( NotAllowedIP, ) @@ -348,7 +348,7 @@ class ReinviteBusinessAccountAPIView(APIView): except LetterUnknownException as exc: logger.exception(exc) return Response({'detail': f'{exc}'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - except AccessDenied as exc: + except AdminReinviteForbidden as exc: return Response({'detail': f'{exc}'}, status=status.HTTP_403_FORBIDDEN) except Exception as exc: logger.exception(exc) @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-01-13 16:09+0300\n" +"POT-Creation-Date: 2026-01-15 12:49+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -24,9 +24,13 @@ msgstr "" msgid "Business account not found" msgstr "Сотрудник не найден" +#: authentication/exceptions/business_account.py:11 +msgid "You cannot reinvite other administrators" +msgstr "Вы не можете повторно приглашать администраторов" + #: authentication/exceptions/business_host_exceptions/access_denied.py:6 -#: authentication/services/business_account_service.py:105 -#: authentication/services/business_account_service.py:108 +#: authentication/services/business_account_service.py:104 +#: authentication/services/business_account_service.py:107 msgid "You do not have sufficient rights to perform this action" msgstr "У вас недостаточно прав для выполнения этого действия" @@ -492,17 +496,17 @@ msgstr "Не найден пользователь с данным ID" msgid "BusinessAccount for this user doesn't exist" msgstr "Бизнес-аккаунт для данного юзера не найден" -#: authentication/services/business_account_service.py:76 +#: authentication/services/business_account_service.py:75 msgid "Invited account can either accept or reject an invitation" msgstr "Приглашенный аккаунт может принять или отклонить приглашение" -#: authentication/services/business_account_service.py:102 +#: authentication/services/business_account_service.py:101 #, fuzzy #| msgid "Passwords do not match" msgid "Passwords don't match" msgstr "Пароли не совпадают" -#: authentication/services/business_account_service.py:111 +#: authentication/services/business_account_service.py:110 msgid "You cannot change the password of an unconfirmed e-mail user." msgstr "Вы не можете изменить пароль неподтвержденного по e-mail пользователя." @@ -518,7 +522,7 @@ msgstr "Случилась ошибка во время отправки email" msgid "Regular users cannot send introductory letters" msgstr "Обычные пользователи не могут отсылать письма" -#: authentication/services/email_service.py:140 +#: authentication/services/email_service.py:146 msgid "Regular users cannot send invitation letters" msgstr "Обычные пользователи не могут отправлять письма для приглашений"