diff --git a/app/eventyay/api/serializers/organizer.py b/app/eventyay/api/serializers/organizer.py index 552d96f1c9..9c62438aa7 100644 --- a/app/eventyay/api/serializers/organizer.py +++ b/app/eventyay/api/serializers/organizer.py @@ -173,10 +173,13 @@ def _send_invite(self, instance): try: mail( instance.email, - _('eventyay account invitation'), + _('You have been invited to join the team "{team}" for "{organizer}"').format( + team=instance.team.name, + organizer=self.context['organizer'].name, + ), 'pretixcontrol/email/invitation.txt', { - 'user': self, + 'user': instance, 'organizer': self.context['organizer'].name, 'team': instance.team.name, 'url': build_absolute_uri('control:auth.invite', kwargs={'token': instance.token}), @@ -208,14 +211,33 @@ def create(self, validated_data): else: if self.context['team'].members.filter(pk=user.pk).exists(): raise ValidationError(_('This user already has permissions for this team.')) - + try: + mail( + user.email, + _('You have been invited to join the team "{team}" for "{organizer}"').format( + team=self.context['team'].name, + organizer=self.context['organizer'].name, + ), + 'pretixcontrol/email/invitation.txt', + { + 'user': user, + 'organizer': self.context['organizer'].name, + 'team': self.context['team'].name, + 'url': build_absolute_uri('control:teams.detail', kwargs={'organizer': self.context['organizer'].slug, 'team': self.context['team'].pk}), + }, + event=None, + locale=get_language_without_region(), + ) + except SendMailException: + logger.warning( + "Failed to send invitation email to existing user: %s", + user.email, + exc_info=True + ) self.context['team'].members.add(user) self.context['team'].log_action( 'eventyay.team.member.added', - data={ - 'email': user.email, - 'user': user.pk, - }, + data={'email': user.email, 'user': user.pk}, **self.context['log_kwargs'], ) return TeamInvite(email=user.email) diff --git a/app/eventyay/base/models/organizer.py b/app/eventyay/base/models/organizer.py index 3c7b5e6418..3f98db2b1e 100644 --- a/app/eventyay/base/models/organizer.py +++ b/app/eventyay/base/models/organizer.py @@ -485,19 +485,27 @@ def send(self): invitation_link = self.invitation_url invitation_text = _( - """Hi! -You have been invited to the {name} event organizer team - Please click here to accept: + """Hello, + +You have been invited to join the team "{name}" for the organizer "{organizer}". + +Please click the following link to accept the invitation: {invitation_link} -See you there, -The {organizer} team""" +If you do not want to join, you can safely ignore or delete this email. + +Best regards, +Your event team""" ).format( name=str(self.team.name), invitation_link=invitation_link, organizer=str(self.team.organizer.name), ) - invitation_subject = _('You have been invited to an organizer team') + invitation_subject = _('You have been invited to join the team "{team}" for "{organizer}"').format( + team=str(self.team.name), + organizer=str(self.team.organizer.name), + ) mail = QueuedMail.objects.create( to=self.email, diff --git a/app/eventyay/control/templates/pretixcontrol/email/invitation.txt b/app/eventyay/control/templates/pretixcontrol/email/invitation.txt index a41a1e7508..b811e35d4b 100644 --- a/app/eventyay/control/templates/pretixcontrol/email/invitation.txt +++ b/app/eventyay/control/templates/pretixcontrol/email/invitation.txt @@ -1,16 +1,14 @@ -{% load i18n %}{% blocktrans with url=url|safe %}Hello, +{% load i18n %}{% blocktrans with url=url|safe team=team organizer=organizer %}Hello, -you have been invited to the following event team +You have been invited to join the team "{{ team }}" for the organizer "{{ organizer }}". -Organizer: {{ organizer }} -Team: {{ team }} - -If you want to join that team, just click on the following link: +Please click the following link to accept the invitation: {{ url }} +If you are already logged in, you will be automatically added to the team. Otherwise, please log in or create an account to join. + If you do not want to join, you can safely ignore or delete this email. Best regards, - Your event team -{% endblocktrans %} +{% endblocktrans %} \ No newline at end of file diff --git a/app/eventyay/control/views/organizer_views/team_view.py b/app/eventyay/control/views/organizer_views/team_view.py index e7a0a0eee1..84fbb343df 100644 --- a/app/eventyay/control/views/organizer_views/team_view.py +++ b/app/eventyay/control/views/organizer_views/team_view.py @@ -1,3 +1,7 @@ +import logging + +logger = logging.getLogger(__name__) + from django.contrib import messages from django.db import transaction from django.db.models import Count, ManyToManyField @@ -173,10 +177,13 @@ def _send_invite(self, instance): try: mail( instance.email, - _('eventyay account invitation'), + _('You have been invited to join the team "{team}" for "{organizer}"').format( + team=instance.team.name, + organizer=self.request.organizer.name, + ), 'pretixcontrol/email/invitation.txt', { - 'user': self, + 'user': instance, 'organizer': self.request.organizer.name, 'team': instance.team.name, 'url': build_global_uri('eventyay_common:auth.invite', kwargs={'token': instance.token}), @@ -304,16 +311,37 @@ def post(self, request, *args, **kwargs): ) return self.get(request, *args, **kwargs) + # Send email to registered user and then add them + try: + mail( + user.email, + _('You have been invited to join the team "{team}" for "{organizer}"').format( + team=self.object.name, + organizer=self.request.organizer.name, + ), + 'pretixcontrol/email/invitation.txt', + { + 'user': user, + 'organizer': self.request.organizer.name, + 'team': self.object.name, + 'url': build_global_uri('eventyay_common:organizer.team', kwargs={'organizer': self.request.organizer.slug, 'team': self.object.pk}), + }, + event=None, + locale=self.request.LANGUAGE_CODE, + ) + except SendMailException: + logger.warning("Failed to send invitation to existing member %s", user.email, exc_info=True) + messages.warning(self.request, _('The new member was added to the team, but the invitation email could not be sent.')) + + else: + messages.success(self.request, _('The new member has been invited and added to the team.')) + self.object.members.add(user) self.object.log_action( 'eventyay.team.member.added', user=self.request.user, - data={ - 'email': user.email, - 'user': user.pk, - }, + data={'email': user.email, 'user': user.pk}, ) - messages.success(self.request, _('The new member has been added to the team.')) return redirect(self.get_success_url()) elif 'name' in self.request.POST and self.add_token_form.is_valid() and self.add_token_form.has_changed(): diff --git a/app/eventyay/eventyay_common/views/team.py b/app/eventyay/eventyay_common/views/team.py index de4bb90af3..1d48db1a5a 100644 --- a/app/eventyay/eventyay_common/views/team.py +++ b/app/eventyay/eventyay_common/views/team.py @@ -1,5 +1,8 @@ +import logging from urllib.parse import urljoin +logger = logging.getLogger(__name__) + from django.conf import settings from django.contrib import messages from django.db import transaction @@ -67,10 +70,13 @@ def _send_invite(self, instance): try: mail( instance.email, - _('eventyay account invitation'), + _('You have been invited to join the team "{team}" for "{organizer}"').format( + team=instance.team.name, + organizer=self.request.organizer.name, + ), 'pretixcontrol/email/invitation.txt', { - 'user': self, + 'user': instance, 'organizer': self.request.organizer.name, 'team': instance.team.name, 'url': build_global_uri('eventyay_common:auth.invite', kwargs={'token': instance.token}), @@ -198,16 +204,39 @@ def post(self, request, *args, **kwargs): ) return self.get(request, *args, **kwargs) + # Send email to registered user even if they exist + try: + mail( + user.email, + _('You have been invited to join the team "{team}" for "{organizer}"').format( + team=self.object.name, + organizer=self.request.organizer.name, + ), + 'pretixcontrol/email/invitation.txt', + { + 'user': user, + 'organizer': self.request.organizer.name, + 'team': self.object.name, + 'url': build_global_uri('eventyay_common:organizer.team', kwargs={'organizer': self.request.organizer.slug, 'team': self.object.pk}), + }, + event=None, + locale=self.request.LANGUAGE_CODE, + ) + except SendMailException: + logger.warning("Failed to send invitation email to existing user %s", user.email, exc_info=True) + messages.warning( + self.request, + _('The new member will be added to the team, but the invitation email could not be delivered.') + ) + else: + messages.success(self.request, _('The new member has been invited and added to the team.')) + self.object.members.add(user) self.object.log_action( 'eventyay.team.member.added', user=self.request.user, - data={ - 'email': user.email, - 'user': user.pk, - }, + data={'email': user.email, 'user': user.pk}, ) - messages.success(self.request, _('The new member has been added to the team.')) return redirect(self.get_success_url()) elif 'name' in self.request.POST and self.add_token_form.is_valid() and self.add_token_form.has_changed():