From e7f2215be41aebe18e6e5f405b73ee0289620ade Mon Sep 17 00:00:00 2001 From: Runar Ingebrigtsen Date: Thu, 29 Jan 2026 15:47:03 +0100 Subject: [PATCH] resend invitations --- .../admin/invitations_controller.rb | 18 ++++++++++++++++++ app/views/admin/invitations/index.html.erb | 3 ++- config/routes.rb | 6 +++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/invitations_controller.rb b/app/controllers/admin/invitations_controller.rb index 940bde2..fbe3f5d 100644 --- a/app/controllers/admin/invitations_controller.rb +++ b/app/controllers/admin/invitations_controller.rb @@ -29,6 +29,24 @@ class Admin::InvitationsController < Admin::BaseController end end + def resend + @invitation = User.find(params[:id]) + + if @invitation.invitation_accepted_at.present? + redirect_to admin_invitations_path, alert: "Cannot resend an accepted invitation." + return + end + + @invitation.update!( + invitation_token: SecureRandom.urlsafe_base64(32), + invitation_sent_at: Time.current + ) + + InvitationMailer.invite(@invitation).deliver_later + + redirect_to admin_invitations_path, notice: "Invitation resent to #{@invitation.email}" + end + def destroy @invitation = User.find(params[:id]) diff --git a/app/views/admin/invitations/index.html.erb b/app/views/admin/invitations/index.html.erb index 9b00a76..e5c3c92 100644 --- a/app/views/admin/invitations/index.html.erb +++ b/app/views/admin/invitations/index.html.erb @@ -65,7 +65,8 @@ <%= invitation.invited_by&.name || invitation.invited_by&.email || "-" %> - + + <%= button_to "Re-send", resend_admin_invitation_path(invitation), method: :put, class: "text-blue-600 hover:text-blue-900" %> <%= button_to "Cancel", admin_invitation_path(invitation), method: :delete, data: { turbo_confirm: "Are you sure you want to cancel this invitation?" }, class: "text-red-600 hover:text-red-900" %> diff --git a/config/routes.rb b/config/routes.rb index abf326b..33338ea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,7 +30,11 @@ Rails.application.routes.draw do root "dashboard#index" get "dashboard", to: "dashboard#index" resources :users, only: [ :index, :edit, :update, :destroy ] - resources :invitations, only: [ :index, :new, :create, :destroy ] + resources :invitations, only: [ :index, :new, :create, :destroy ] do + member do + put :resend + end + end end resources :entries do