Skip to content

Conversation

@hemantmm
Copy link

@hemantmm hemantmm commented Nov 6, 2025

closes: #1160

Add email notifications for registered users when they are invited to teams, ensuring all team members receive proper communication about their invitations.

✅ Changes Made:

1. Enhanced Team Invitation Email Flow
Files:
app/eventyay/control/views/organizer_views/team.py
app/eventyay/control/models/organizer.py

✅ Modified TeamInvite.send() to use a clearer, more professional email template.
✅ Updated email subject to include both team name and organizer name for clarity.
✅ Enhanced email body text to be appropriate for both registered and unregistered users.
✅ Implemented temporary invite creation for registered users to trigger email notifications.
✅ Added automatic cleanup of temporary invites after email dispatch.

2. Updated Team Member Addition Logic
Files:
app/eventyay/control/views/organizer_views/team.py
app/eventyay/control/views/organizer_views/team_view.py

✅ Modified post() method to send invitation emails to registered users before team addition.
✅ Created temporary invite objects for registered users to reuse the existing email system.
✅ Ensured cleanup of temporary invites to prevent database clutter.
✅ Maintained existing logging and audit trail functionality.

3. Improved Invitation Email Template
File:
app/eventyay/control/templates/pretixcontrol/email/invitation.txt

✅ Updated template text to be clearer for all user types.
✅ Added instructions for both logged-in and new users.
✅ Improved tone and formatting for a professional appearance.
✅ Made the email template consistent across all invitation flows.

4. Updated API Serializer
File:
app/eventyay/api/serializers/organizer.py

✅ Enhanced TeamInviteSerializer.create() to send emails to registered users.
✅ Improved email subject line for better readability.
✅ Ensured API endpoint feature parity with the web UI.
✅ Maintained backward compatibility with existing API consumers.

Summary:

This PR significantly improves team collaboration UX and transparency by ensuring all users — both registered and unregistered — receive email notifications when invited to teams.

Summary by Sourcery

Ensure all team invite flows send professional, branded email notifications to both registered and unregistered users, unify invitation templates across the codebase, and standardize temporary invite cleanup and logging.

New Features:

  • Send email invitations to existing registered users when they are invited to teams via the web UI and API

Enhancements:

  • Revise invitation email subject and body to include team and organizer names and improve tone
  • Unify invitation template usage across control views, common views, API serializers, and base models
  • Create and automatically remove temporary invite objects for registered users to leverage existing email logic
  • Rename log action key for team member additions to 'eventyay.team.member.added'

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 6, 2025

Reviewer's Guide

This PR extends the team invitation system to registered users by unifying and enhancing email flows across views, serializers, and models. It updates subjects and bodies with team and organizer context, introduces temporary invites for seamless email reuse, and aligns the API serializer and templates with the web UI behavior.

Sequence diagram for enhanced team invitation email flow

sequenceDiagram
    actor Organizer
    participant "TeamView (web/API)"
    participant "TeamInvite Model"
    participant "Mail Service"
    participant "User (Registered)"
    Organizer->>"TeamView (web/API)": Add member to team
    "TeamView (web/API)"->>"TeamInvite Model": Create temporary invite (if registered)
    "TeamInvite Model"->>"Mail Service": Send invitation email (with team & organizer info)
    "Mail Service"->>"User (Registered)": Deliver invitation email
    "TeamInvite Model"->>"TeamView (web/API)": Cleanup temporary invite
    "TeamView (web/API)"->>"TeamView (web/API)": Add user to team
    "TeamView (web/API)"->>Organizer: Success message
Loading

Class diagram for updated TeamInvite and email logic

classDiagram
    class TeamInvite {
        +email: str
        +team: Team
        +send()
        +invitation_url
    }
    class Team {
        +name: str
        +organizer: Organizer
        +members: User[]
        +log_action()
    }
    class Organizer {
        +name: str
        +slug: str
    }
    class User {
        +email: str
        +pk: int
    }
    class QueuedMail {
        +to: str
        +subject: str
        +body: str
    }
    TeamInvite --> Team
    Team --> Organizer
    Team --> User
    TeamInvite --> QueuedMail : send() creates
    QueuedMail --> User : to
    TeamInvite --> User : email
    TeamInvite : +send() now uses improved subject/body
    TeamInvite : +temporary invites for registered users
Loading

File-Level Changes

Change Details Files
Standardize invitation email content and delivery flow
  • Include team and organizer names in the subject line
  • Revise email body for clarity and professional tone
  • Cleanup temporary invites post email dispatch
app/eventyay/control/views/organizer_views/team.py
app/eventyay/eventyay_common/views/team.py
app/eventyay/base/models/organizer.py
Notify registered users before adding to team
  • Send invitation emails to existing users via try/catch
  • Create temporary invite objects to reuse email logic
  • Update success messages to reflect invite-and-add workflow
app/eventyay/control/views/organizer_views/team_view.py
app/eventyay/eventyay_common/views/team.py
Align API serializer invite behavior with UI
  • Trigger email dispatch in TeamInviteSerializer.create()
  • Match subject and body formatting to web flows
  • Maintain backward compatibility for existing API consumers
app/eventyay/api/serializers/organizer.py
Revise invitation email template text
  • Add instructions for both logged-in and new users
  • Improve tone, formatting, and consistency
  • Ensure template is consistent across all invite flows
app/eventyay/control/templates/pretixcontrol/email/invitation.txt

Assessment against linked issues

Issue Objective Addressed Explanation
#1160 Send team invitation email notifications to registered users when they are invited to a team.
#1160 Ensure the invitation email includes event name, team name, and a link to view/join the team.
#1160 Update the email subject line to clearly state the invitation, including team and event/organizer name.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider extracting the invitation email logic (subject formatting, template rendering, and mail dispatch) into a shared helper or service to reduce duplication and ensure consistency across views, models, and serializers.
  • Standardize URL construction for invitation links (e.g. build_global_uri vs build_absolute_uri) in a central place so web UI and API flows stay in sync and future changes apply uniformly.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the invitation email logic (subject formatting, template rendering, and mail dispatch) into a shared helper or service to reduce duplication and ensure consistency across views, models, and serializers.
- Standardize URL construction for invitation links (e.g. build_global_uri vs build_absolute_uri) in a central place so web UI and API flows stay in sync and future changes apply uniformly.

## Individual Comments

### Comment 1
<location> `app/eventyay/control/views/organizer_views/team_view.py:337` </location>
<code_context>
+                    data={'email': user.email, 'user': user.pk},
                 )
-                messages.success(self.request, _('The new member has been added to the team.'))
+                messages.success(self.request, _('The new member has been invited and added to the team.'))
                 return redirect(self.get_success_url())

</code_context>

<issue_to_address>
**suggestion:** Consider clarifying messaging for invitation and addition.

If the invitation email fails, the message may incorrectly state both actions succeeded. Please update the messaging to reflect the actual outcome.
</issue_to_address>

### Comment 2
<location> `app/eventyay/control/views/organizer_views/team_view.py:328-329` </location>
<code_context>
+                        locale=self.request.LANGUAGE_CODE,
+                    )
+                except SendMailException:
+                    logger.warning("Failed to send invitation to existing member %s", user.email)
+                
                 self.object.members.add(user)
</code_context>

<issue_to_address>
**suggestion:** Consider including exception details in the log for failed email sends.

Including exception details in the log will make it easier to identify why the email failed to send.

```suggestion
                except SendMailException as exc:
                    logger.warning(
                        "Failed to send invitation to existing member %s: %s",
                        user.email,
                        exc,
                    )
```
</issue_to_address>

### Comment 3
<location> `app/eventyay/eventyay_common/views/team.py:226` </location>
<code_context>
+                        locale=self.request.LANGUAGE_CODE,
+                    )
+                except SendMailException:
+                    logger.warning("Failed to send invitation email to existing user %s", user.email)
+
                 self.object.members.add(user)
</code_context>

<issue_to_address>
**suggestion:** Log message could include exception details for better traceability.

Consider passing exc_info=True to logger.warning to include the stack trace for easier debugging of email failures.

```suggestion
                    logger.warning("Failed to send invitation email to existing user %s", user.email, exc_info=True)
```
</issue_to_address>

### Comment 4
<location> `app/eventyay/api/serializers/organizer.py:231-233` </location>
<code_context>
+                        locale=get_language_without_region(),
+                    )
+                except SendMailException:
+                    logger.warning("Failed to send invitation email to existing user: %s", user.email)
+                    
                 self.context['team'].members.add(user)
</code_context>

<issue_to_address>
**suggestion:** Consider logging exception details for failed invitation emails.

Logging the exception details will make it easier to diagnose why email sending failed.

```suggestion
                except SendMailException as exc:
                    logger.warning(
                        "Failed to send invitation email to existing user: %s. Exception: %s",
                        user.email,
                        exc,
                    )

```
</issue_to_address>

### Comment 5
<location> `app/eventyay/control/templates/pretixcontrol/email/invitation.txt:14` </location>
<code_context>
-
 Your event team
-{% endblocktrans %}
+{% endblocktranslate %}
\ No newline at end of file
</code_context>

<issue_to_address>
**issue (typo):** Possible typo: use of '{% endblocktranslate %}' instead of '{% endblocktrans %}'.

Please confirm if this is intentional; otherwise, change to '{% endblocktrans %}' for correct Django syntax.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Signed-off-by: Hemant M Mehta <[email protected]>
@mariobehling mariobehling requested a review from Copilot November 6, 2025 10:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request improves team invitation emails by making them more descriptive and consistent across the platform. The changes update email subjects and body text to include specific team and organizer names, and ensure that existing users receive notification emails when added to teams.

  • Updated email subject lines to include team and organizer names for better clarity
  • Added email notifications for existing users when they're added to teams
  • Standardized invitation email template with clearer instructions

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
app/eventyay/eventyay_common/views/team.py Updated email subject in _send_invite method and added email notification for existing users being added to teams with logger import
app/eventyay/control/views/organizer_views/team_view.py Similar updates to email subjects and added email notifications for existing users with improved error handling
app/eventyay/control/templates/pretixcontrol/email/invitation.txt Refined email template with clearer language and structured formatting
app/eventyay/base/models/organizer.py Updated invitation email subject and body text in the send method to match new format
app/eventyay/api/serializers/organizer.py Updated email subjects and added email notifications for existing users in API serializer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The title is close to our preferred format, but could be made a bit clearer and more readable.

Please use the format:

type(scope): short description

For example, instead of:

fix: email-notifications-team-invites

it would be better to write:

fix(notifications): resolve email not sent for team invites

This makes it easier to understand what’s being fixed at a glance and follows the conventional commit style we use for changelogs and automation.

💡 Why this is better

  • Adds a scope (notifications → tells where the fix happens).
  • Uses normal words instead of hyphens — easier to read.
  • Describes the issue or outcome clearly (“email not sent” instead of just “email-notifications”).
  • Keeps consistency with other commits and changelogs.

@mariobehling
Copy link
Member

Also, could you please add screenshots or a short video showing the fix in action?

It helps reviewers confirm that the email notifications now work correctly for team invites.

@hemantmm
Copy link
Author

hemantmm commented Nov 6, 2025

Also, could you please add screenshots or a short video showing the fix in action?

It helps reviewers confirm that the email notifications now work correctly for team invites.

Will update it soon.

@hemantmm hemantmm changed the title fix: email-notifications-team-invites fix(notifications): resolve email not sent for team invites Nov 6, 2025
@hemantmm hemantmm requested a review from Copilot November 6, 2025 12:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hemantmm hemantmm requested a review from Copilot November 6, 2025 14:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Removed duplicate logging import and initialization.
Removed duplicate logging import and initialization.
@hemantmm hemantmm requested a review from Copilot November 6, 2025 14:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mariobehling mariobehling requested a review from Copilot November 6, 2025 15:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Hemant M Mehta <[email protected]>
@hemantmm hemantmm requested a review from Copilot November 6, 2025 16:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)
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.'))
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tense in this error message is inconsistent. At the time this message is shown, the member has not been added yet (that happens on line 339). The message should say 'will be added' to match the actual timing, or the code should be restructured to add the member before sending the email.

Suggested change
messages.warning(self.request, _('The new member was added to the team, but the invitation email could not be sent.'))
messages.warning(self.request, _('The new member will be added to the team, but the invitation email could not be sent.'))

Copilot uses AI. Check for mistakes.
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.'))

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace on this blank line. Remove the trailing whitespace to maintain code cleanliness.

Suggested change

Copilot uses AI. Check for mistakes.
@Gagan-Ram
Copy link
Member

There is a new implementation on email for tickets: #1190 . Please make sure this PR works once #1190 gets merged.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Registered users do not receive email notifications for team invitations

3 participants