-
-
Notifications
You must be signed in to change notification settings - Fork 199
feat: add database-backed invitation logging and resilient bulk invitations #2546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mroderick
merged 12 commits into
codebar:master
from
mroderick:fix/workshop-invitation-resilience
Mar 31, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6a73071
fix: make bulk invitation creation resilient to individual failures
mroderick 5db1552
feat(invitations): add invitation_logs migration and models
mroderick 9312a82
feat(invitations): add InvitationLogger service
mroderick c3bbc8d
feat(invitations): integrate logging into InvitationManager
mroderick 234fca5
feat(invitations): add admin UI for viewing invitation logs
mroderick 189a0ba
feat(invitations): add cleanup job for expired logs
mroderick ace2366
refactor(invitations): use destroy_by for expired log cleanup
mroderick ac4248d
style(specs): remove redundant type: :controller metadata
mroderick 66708fc
style(workshops): normalize params.expect indentation
mroderick 503acea
refactor(invitations): extract send_email_with_logging helper method
mroderick 309389f
Update spec/models/invitation_log_entry_spec.rb
mroderick 01c2dba
Update spec/policies/invitation_log_policy_spec.rb
mroderick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
app/controllers/admin/workshop_invitation_logs_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| module Admin | ||
| class WorkshopInvitationLogsController < Admin::ApplicationController | ||
| def index | ||
| @workshop = Workshop.find(params[:workshop_id]) | ||
| authorize @workshop, :show? | ||
| logs = InvitationLog.where(loggable: @workshop) | ||
| .order(created_at: :desc) | ||
| .includes(:initiator, :entries) | ||
| @pagy, @logs = pagy(logs) | ||
| end | ||
|
|
||
| def show | ||
| @workshop = Workshop.find(params[:workshop_id]) | ||
| authorize @workshop, :show? | ||
| @log = InvitationLog.find(params[:id]) | ||
| @entries = @log.entries.order(processed_at: :desc).includes(:member) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class CleanupExpiredInvitationLogsJob < ApplicationJob | ||
| queue_as :default | ||
|
|
||
| def perform | ||
| InvitationLog.destroy_by(expires_at: ..Time.current) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| class InvitationLog < ApplicationRecord | ||
| enum :action, { invite: 'invite', reminder: 'reminder', waiting_list_notification: 'waiting_list_notification' }, | ||
mroderick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| prefix: false | ||
| enum :status, { running: 'running', completed: 'completed', failed: 'failed' }, prefix: false | ||
|
|
||
| belongs_to :loggable, polymorphic: true | ||
| belongs_to :initiator, class_name: 'Member', optional: true | ||
| belongs_to :chapter, optional: true | ||
| has_many :entries, class_name: 'InvitationLogEntry', dependent: :destroy | ||
|
|
||
| before_create :set_expires_at | ||
|
|
||
| private | ||
|
|
||
| def set_expires_at | ||
| self.expires_at ||= 180.days.from_now | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class InvitationLogEntry < ApplicationRecord | ||
| enum :status, { success: 'success', failed: 'failed', skipped: 'skipped' }, prefix: false | ||
|
|
||
| belongs_to :invitation_log | ||
| belongs_to :member | ||
| belongs_to :invitation, polymorphic: true, optional: true | ||
|
|
||
| validates :member_id, uniqueness: { scope: %i[invitation_type invitation_id] }, allow_nil: true | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class InvitationLogPolicy < ApplicationPolicy | ||
| def index? | ||
| is_admin_or_chapter_organiser? | ||
| end | ||
|
|
||
| def show? | ||
| is_admin_or_chapter_organiser? | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| class InvitationLogger | ||
| def initialize(loggable, initiator, audience, action) | ||
| @loggable = loggable | ||
| @initiator = initiator | ||
| @audience = audience | ||
| @action = action | ||
| @log = nil | ||
| end | ||
|
|
||
| def start_batch | ||
| @log = InvitationLog.create!( | ||
| loggable: @loggable, | ||
| initiator: @initiator, | ||
| chapter_id: @loggable.try(:chapter_id), | ||
| audience: @audience, | ||
| action: @action, | ||
| started_at: Time.current, | ||
| status: :running | ||
| ) | ||
| end | ||
|
|
||
| def log_success(member, invitation = nil) | ||
| return unless @log | ||
|
|
||
| @log.entries.create!( | ||
| member: member, | ||
| invitation: invitation, | ||
| status: :success, | ||
| processed_at: Time.current | ||
| ).tap { @log.increment!(:success_count) } | ||
| end | ||
|
|
||
| def log_failure(member, invitation, error) | ||
| return unless @log | ||
|
|
||
| @log.entries.create!( | ||
| member: member, | ||
| invitation: invitation, | ||
| status: :failed, | ||
| failure_reason: error.message, | ||
| processed_at: Time.current | ||
| ).tap { @log.increment!(:failure_count) } | ||
| end | ||
|
|
||
| def log_skipped(member, invitation, reason) | ||
| return unless @log | ||
|
|
||
| @log.entries.create!( | ||
| member: member, | ||
| invitation: invitation, | ||
| status: :skipped, | ||
| failure_reason: reason, | ||
| processed_at: Time.current | ||
| ).tap { @log.increment!(:skipped_count) } | ||
| end | ||
|
|
||
| def finish_batch(total_invitees) | ||
| return unless @log | ||
|
|
||
| @log.update!( | ||
| total_invitees: total_invitees, | ||
| completed_at: Time.current, | ||
| status: :completed | ||
| ) | ||
| end | ||
|
|
||
| def fail_batch(error) | ||
| return unless @log | ||
|
|
||
| @log.update!( | ||
| status: :failed, | ||
| error_message: error.message, | ||
| completed_at: Time.current | ||
| ) | ||
| end | ||
|
|
||
| attr_reader :log | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.