@@ -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:
-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