Skip to content
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

Add before_action in IncomingEmail webhook controller #4443

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/mailgun_webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def create_incoming_email
sender_email_address = parse_valid_email_address(from: params["from"], sender: params["sender"])
clients = Client.joins(:intake).where(intakes: { email_address: sender_email_address })
client_count = clients.count
if client_count.zero?
if sender_email_address.is_FYST?
# Create incoming EMail for FYST
elsif client_count.zero?
archived_intake = most_recent_intake(sender_email_address)
if archived_intake.present?
locale = archived_intake.locale || "en"
Expand Down
1 change: 1 addition & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

STATE_INTAKE_CLASS_NAMES = %w[StateFileAzIntake StateFileNyIntake].map(&:to_s).freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this here to make it available to all our models instead of just EfileSubmission

# Allow counting up to a max number; see https://alexcastano.com/the-hidden-cost-of-the-invisible-queries-in-rails/#how-far-do-you-plan-to-count
scope :count_greater_than?, ->(n) { limit(n + 1).count > n }

Expand Down
2 changes: 0 additions & 2 deletions app/models/efile_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class EfileSubmission < ApplicationRecord
has_one_attached :submission_bundle
validates :irs_submission_id, format: { with: /\A[0-9]{6}[0-9]{7}[0-9a-z]{7}\z/ }, presence: true, uniqueness: true, allow_nil: true

STATE_INTAKE_CLASS_NAMES = [StateFileAzIntake, StateFileNyIntake].map(&:to_s).freeze

include Statesman::Adapters::ActiveRecordQueries[
transition_class: EfileSubmissionTransition,
initial_state: EfileSubmissionStateMachine.initial_state,
Expand Down
8 changes: 8 additions & 0 deletions app/models/state_file_base_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,12 @@ def controller_for_current_step
end
end
end

def self.is_state_file_email?(email)
STATE_INTAKE_CLASS_NAMES.each do |state|
class_object = state.constantize
return true if class_object.where(email_address: email).length.positive?
end
false
end
end
13 changes: 13 additions & 0 deletions spec/models/efile_submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,17 @@
end
end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this spec since I moved STATE_INTAKE_CLASS_NAMES form the efile_submission model, and I wanted to make sure I didn't break anything.

describe '#is_for_state_filing?' do
let(:state_efile_submission) { create :efile_submission, :for_state }
let(:non_state_efile_submission) { create :efile_submission }

it 'returns true for state submission' do
expect(state_efile_submission.is_for_state_filing?).to eq true
end

it 'returns false for non-state submission' do
expect(non_state_efile_submission.is_for_state_filing?).to eq false
end
end
end
17 changes: 17 additions & 0 deletions spec/models/state_file_base_intake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,21 @@
end
end
end

describe 'is_state_file_email?' do
let!(:email) { 'email@test.com' }
let!(:intake) { create :state_file_az_intake, email_address: email }

context 'when is a FYST email' do
it 'returns true' do
expect(StateFileBaseIntake.is_state_file_email?(email)).to eq true
end
end

context 'when is NOT a FYST email' do
it 'returns false' do
expect(StateFileBaseIntake.is_state_file_email?('another_email@test.com')).to eq false
end
end
end
end
Loading