Skip to content

Commit

Permalink
Show better error message for discarded invitees
Browse files Browse the repository at this point in the history
  • Loading branch information
samrat committed Jan 6, 2025
1 parent f396e8b commit ba1fc23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Authentication::Email::InviteConfirmationsController < ApplicationController
before_action :set_invite_token, only: [:new, :create]
before_action :set_invite, only: [:new, :create]
before_action :check_valid_invitation, only: [:new]
before_action :check_accepted_invitation, only: [:new]
helper_method :current_user

Expand Down Expand Up @@ -28,6 +29,12 @@ def create

private

def check_valid_invitation
if @invite.nil?
redirect_to root_path, flash: {error: t("invitation.flash.invalid_or_expired")}
end
end

def check_accepted_invitation
redirect_to root_path, notice: t("invitation.flash.already_accepted") if @invite.accepted?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class Authentication::Email::RegistrationsController < Devise::RegistrationsCont

def new
if @token.present?
# Check if invite exists and is valid
if @invite.nil?
flash.clear
flash[:alert] = t("invitation.flash.invalid_or_expired")
redirect_to new_email_authentication_session_path and return
end

flash[:notice] = t("invitation.flash.signup_before", org: @invite.organization.name)
end

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ en:
accepted: "Invitation was accepted. Please sign in to continue."
already_accepted: "Invitation was already accepted!"
failed: "Failed to accept your invitation. Please contact support!"
invalid_or_expired: "This invitation link is no longer valid. Please contact the organization admin for a new invitation."
invite_mailer:
existing_user:
subject: "%{sender} invited you to join the %{org} team on Tramline"
Expand Down

0 comments on commit ba1fc23

Please sign in to comment.