Skip to content

Commit

Permalink
Get rid of EmailContext
Browse files Browse the repository at this point in the history
  • Loading branch information
vrajmohan committed Dec 19, 2024
1 parent 4571446 commit 28b0797
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def identity
end

def last_email
EmailContext.new(current_user).last_sign_in_email_address.id
current_user.last_sign_in_email_address.id
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/mfa_setup_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def threatmetrix_attrs
user_id: current_user.id,
request_ip: request&.remote_ip,
threatmetrix_session_id: session[:threatmetrix_session_id],
email: EmailContext.new(current_user).last_sign_in_email_address.email,
email: current_user.last_sign_in_email_address.email,
uuid_prefix: current_sp&.app_id,
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sign_up/completions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def update
update_verified_attributes
send_in_person_completion_survey
if user_session[:selected_email_id_for_linked_identity].nil?
user_session[:selected_email_id_for_linked_identity] = EmailContext.new(current_user)
user_session[:selected_email_id_for_linked_identity] = current_user
.last_sign_in_email_address.id
end
if decider.go_back_to_mobile_app?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sign_up/select_email_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def last_email
if user_session[:selected_email_id_for_linked_identity]
user_emails.find(user_session[:selected_email_id_for_linked_identity]).email
else
EmailContext.new(current_user).last_sign_in_email_address.email
current_user.last_sign_in_email_address.email
end
end

Expand Down
21 changes: 0 additions & 21 deletions app/decorators/email_context.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def qrcode(otp_secret_key)
interval: IdentityConfig.store.totp_code_interval,
}
url = ROTP::TOTP.new(otp_secret_key, options).provisioning_uri(
EmailContext.new(self).last_sign_in_email_address.email,
last_sign_in_email_address.email,
)
qrcode = RQRCode::QRCode.new(url)
qrcode.as_png(size: 240).to_data_url
Expand Down
8 changes: 4 additions & 4 deletions app/policies/email_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class EmailPolicy
def initialize(user)
@user = EmailContext.new(user)
@user = user
end

def can_delete_email?(email)
Expand All @@ -12,17 +12,17 @@ def can_delete_email?(email)
end

def can_add_email?
user.email_address_count < IdentityConfig.store.max_emails_per_account
user.email_addresses.count < IdentityConfig.store.max_emails_per_account
end

private

def last_confirmed_email_address?
user.confirmed_email_address_count <= 1
user.confirmed_email_addresses.count <= 1
end

def last_email_address?
user.email_address_count <= 1
user.email_addresses.count <= 1
end

attr_reader :user
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/account_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def personal_key_generated_at
def header_personalization
return decrypted_pii.first_name if decrypted_pii.present?

EmailContext.new(user).last_sign_in_email_address.email
user.last_sign_in_email_address.email
end

def totp_content
Expand Down
4 changes: 0 additions & 4 deletions app/presenters/openid_connect_user_info_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ def all_emails_from_sp_identity(identity)
identity.user.confirmed_email_addresses.map(&:email)
end

def email_context
@email_context ||= EmailContext.new(identity.user)
end

def ial2_attributes
{
given_name: stringify_attr(ial2_data.first_name),
Expand Down
2 changes: 1 addition & 1 deletion app/services/displayable_pii_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def email
if @selected_email_id
current_user.confirmed_email_addresses.find(@selected_email_id).email
else
EmailContext.new(current_user).last_sign_in_email_address.email
current_user.last_sign_in_email_address.email
end
end

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/saml_idp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
config.name_id.formats =
{
persistent: ->(principal) { principal.asserted_attributes[:uuid][:getter].call(principal) },
email_address: ->(principal) { EmailContext.new(principal).last_sign_in_email_address.email },
email_address: ->(principal) { principal.last_sign_in_email_address.email },
}

## Technical contact ##
Expand Down
23 changes: 0 additions & 23 deletions spec/decorators/email_context_spec.rb

This file was deleted.

7 changes: 3 additions & 4 deletions spec/services/attribute_asserter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@
end

it 'does not create a getter function for IAL1 attributes' do
expected_email = EmailContext.new(user).last_sign_in_email_address.email
expect(get_asserted_attribute(user, :email)).to eq expected_email
expect(get_asserted_attribute(user, :email)).to eq user.last_sign_in_email_address.email
end

it 'gets UUID from Service Provider' do
Expand All @@ -293,8 +292,8 @@
end

it 'does not create a getter function for IAL1 attributes' do
expected_email = EmailContext.new(user).last_sign_in_email_address.email
expect(get_asserted_attribute(user, :email)).to eq expected_email
expect(get_asserted_attribute(user, :email))
.to eq user.last_sign_in_email_address.email
end

it 'gets UUID from Service Provider' do
Expand Down

0 comments on commit 28b0797

Please sign in to comment.