Add group/club-wide event audiences and a Resend email backend
Events can now target members.Group audiences alongside teams, or go club_wide (every ACTIVE ClubMembership member for the event's season) instead of specific teams/groups -- the two are mutually exclusive, enforced in EventForm/EventSeriesForm.clean() since an M2M can't be validated via a DB CheckConstraint or Event.clean() (no PK yet). Attendance sync (events/signals.py) now reacts to GroupMembership and ClubMembership changes the same way it already did for TeamMembership. Authorization: club.services.access.groups_manageable_by mirrors teams_managed_by (all groups for an ADMIN, else only the ones the user belongs to -- Group has no manager/owner concept); a non-admin needs at least one managed team or belonged-to group to create/edit an event, club_wide stays admin-only, and EventManagerRequiredMixin gained a get_groups() hook so a non-admin who creates a group-only event isn't immediately locked out of managing it. Also adds rosterchief.mail.ResendEmailBackend, an HTTP-API-based Django email backend for Resend (resend.com) using the existing `requests` dependency -- no new SDK. Opt in via DJANGO_EMAIL_BACKEND and RESEND_API_KEY; every Django-sent email (allauth's password reset included) follows whichever EMAIL_BACKEND is configured, so this covers all of them for free. Resend's own SMTP relay remains a valid code-free alternative, documented alongside it in .env.production.example. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
"""Keep an event's attendance rows in sync with its effective audience.
|
||||
|
||||
The audience of an event is the union of the current rosters of its ``teams``
|
||||
(for the event's season) plus any individually ``invited_members``, minus any
|
||||
``excluded_members``. Attendance rows are reconciled against that set, but only
|
||||
for events that are still in the future — history is never rewritten.
|
||||
(for the event's season) and the current members of its ``groups``, plus any
|
||||
individually ``invited_members``, minus any ``excluded_members`` -- or, for a
|
||||
``club_wide`` event, every member with an ACTIVE ClubMembership for the
|
||||
event's season instead of teams/groups (the two are mutually exclusive, see
|
||||
EventForm/EventSeriesForm). Attendance rows are reconciled against that set,
|
||||
but only for events that are still in the future — history is never rewritten.
|
||||
"""
|
||||
|
||||
from django.db.models import Count, Q
|
||||
from django.utils import timezone
|
||||
|
||||
from club.models import Season
|
||||
from club.models import ClubMembership, Season
|
||||
from events.models import Attendance, Event
|
||||
from members.models import Member
|
||||
from teams.models import TeamMembership
|
||||
@@ -24,13 +27,22 @@ def resolve_season(event):
|
||||
|
||||
def effective_members(event):
|
||||
"""Return the ``Member`` queryset invited to ``event``."""
|
||||
member_ids: set = set()
|
||||
|
||||
season = resolve_season(event)
|
||||
if season is not None:
|
||||
team_ids = list(event.teams.values_list("id", flat=True))
|
||||
if team_ids:
|
||||
member_ids.update(TeamMembership.objects.filter(team_id__in=team_ids, season=season).values_list("member_id", flat=True))
|
||||
|
||||
if event.club_wide:
|
||||
member_ids = set()
|
||||
if season is not None:
|
||||
member_ids.update(ClubMembership.objects.filter(club=event.club, season=season, status=ClubMembership.StatusChoices.ACTIVE).values_list("member_id", flat=True))
|
||||
else:
|
||||
member_ids = set()
|
||||
if season is not None:
|
||||
team_ids = list(event.teams.values_list("id", flat=True))
|
||||
if team_ids:
|
||||
member_ids.update(TeamMembership.objects.filter(team_id__in=team_ids, season=season).values_list("member_id", flat=True))
|
||||
|
||||
group_ids = list(event.groups.values_list("id", flat=True))
|
||||
if group_ids:
|
||||
member_ids.update(Member.objects.filter(group_memberships__group_id__in=group_ids).values_list("id", flat=True))
|
||||
|
||||
member_ids.update(event.invited_members.values_list("id", flat=True))
|
||||
member_ids.difference_update(event.excluded_members.values_list("id", flat=True))
|
||||
|
||||
Reference in New Issue
Block a user