Skip to content

One invitation per member per event or workshop - #2867

Draft
mroderick wants to merge 2 commits into
masterfrom
fix/one-invite-per-member-per-event
Draft

One invitation per member per event or workshop#2867
mroderick wants to merge 2 commits into
masterfrom
fix/one-invite-per-member-per-event

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Members subscribed to a chapter as both student and coach received two invitation emails per event or workshop, one per role. They now get one invitation and one email. Coach emails for events are labelled "Coach Invitation" only when the event is actually for coaches.

Fixes #2861

Changes

  • InvitationManager now treats event or workshop plus member as the invitation identity and applies the role only on create. The second pass (students after coaches for events, coaches after students for workshops) finds the existing invitation and skips the member instead of creating a duplicate with the other role.
  • EventInvitationMailer#invite_coach used !event.audience, which is false for a blank audience string, so events saved through the admin form with audience untouched labelled coach emails "Coach Invitation". It now checks for 'Coaches' explicitly.

Review notes

  • The invitation pass order decides which single email a dual-role member receives: coach first for events, student first for workshops. If product wants a specific email type to win, that is a separate change.
  • Tests that stubbed find_or_create_by! with the role in the lookup hash were rewritten to assert created invitations and deliveries instead; behavior assertions are unchanged apart from the dual-role case, which previously asserted the buggy two-invitation behavior.
  • Existing workshop invitation rows with two roles per member are untouched by this change; no data migration is included.
Detail

Invitation creation for events and workshops used find_or_create_by!(event:, member:, role:). Because role was part of the lookup, a member subscribed as both student and coach was invited twice when both passes ran: once as a Coach, once as a Student, with an email each. On the reported event this affected 387 members. Workshops with audience everyone had the same behavior.

The fix changes the two shared creators in InvitationManager (create_event_invitation, create_invitation) to look up by event or workshop plus member only, assigning role in the create block. previously_new_record? still gates email sending, so the skipped member is logged as already invited.

The blank-audience subject bug came from events edited via the admin form: the audience select submits an empty string when untouched, and !'' is false, producing "Coach Invitation" for a general invite. The wording now matches the audience gate in send_event_emails, which already uses .eql? comparisons.

Members subscribed to a chapter as both student and coach received two
invitation emails, one per role, because each invitation pass matched on
(event or workshop, member, role). Match on identity only and set the
role on create, so the second pass finds the existing invitation and
skips the member.

For events with a blank audience, coach emails were labelled "Coach
Invitation" instead of a general "Invitation"; label coach emails as
such only when the event is actually for coaches.

Fixes #2861
…l-role invite contract

Applies the two validated findings from the ce-code-review run on PR
#2867:

- WorkshopsController#find_or_create_invitation keyed on
  (workshop, member, role), so a dual student+coach member self-RSVPing
  with the other role created a second invitation. Key on
  (workshop, member) and update the existing invitation to the chosen
  role, matching the InvitationManager identity semantics.
- The dual-role specs asserted counts only; pin the surviving role
  (Coach for events, Student for workshops - pass order decides) and the
  delivered email subject so a pass reorder cannot silently flip which
  email dual members receive.
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.

Received 2 invites for an "Event"

1 participant