diff --git a/app/controllers/accounts/invitations_controller.rb b/app/controllers/accounts/invitations_controller.rb index 1ef2c49ac..d6978bbb2 100644 --- a/app/controllers/accounts/invitations_controller.rb +++ b/app/controllers/accounts/invitations_controller.rb @@ -25,11 +25,15 @@ def create end def destroy - @invite = Accounts::Organization.find_by!(slug: params[:organization_id]) - .pending_invites.find(params[:id]) - @invite.destroy - redirect_to accounts_organization_teams_path(current_organization), - notice: "Invitation to #{@invite.email} has been cancelled" + @invite = current_organization.pending_invites.find_by(id: params[:id]) + + if @invite&.destroy + redirect_to accounts_organization_teams_path(current_organization), + notice: "Invitation to #{@invite.email} has been cancelled" + else + redirect_to accounts_organization_teams_path(current_organization), + flash: {error: "Could not cancel the invitation."} + end end protected