Skip to content
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base
rescue_from error, with: :render_timeout
end

helper_method :decorated_sp_session, :user_fully_authenticated?
helper_method :decorated_sp_session, :current_sp, :user_fully_authenticated?

prepend_before_action :add_new_relic_trace_attributes
prepend_before_action :session_expires_at
Expand Down
4 changes: 0 additions & 4 deletions app/decorators/null_service_provider_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def sp_name; end

def sp_issuer; end

def sp_logo; end

def sp_logo_url; end

def sp_redirect_uris; end

def requested_attributes; end
Expand Down
29 changes: 0 additions & 29 deletions app/decorators/service_provider_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class ServiceProviderSession
include ActionView::Helpers::TranslationHelper
include Rails.application.routes.url_helpers

DEFAULT_LOGO = 'generic.svg'

def initialize(sp:, view_context:, sp_session:, service_provider_request:)
@sp = sp
@view_context = view_context
Expand All @@ -25,33 +23,6 @@ def sp_redirect_uris
@sp.redirect_uris
end

def sp_logo
sp.logo.presence || DEFAULT_LOGO
end

def sp_logo_url
if FeatureManagement.logo_upload_enabled? && sp.remote_logo_key.present?
s3_logo_url(sp)
else
legacy_logo_url
end
end

def s3_logo_url(service_provider)
region = IdentityConfig.store.aws_region
bucket = IdentityConfig.store.aws_logo_bucket
key = service_provider.remote_logo_key

"https://s3.#{region}.amazonaws.com/#{bucket}/#{key}"
end

def legacy_logo_url
logo = sp_logo
ActionController::Base.helpers.image_path("sp-logos/#{logo}")
rescue Propshaft::MissingAssetError
''
end

def new_session_heading
I18n.t('headings.sign_in_with_sp', sp: sp_name)
end
Expand Down
9 changes: 8 additions & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,19 @@ def in_person_ready_to_verify(enrollment:, is_enhanced_ipp:)
IdentityConfig.store.in_person_outage_emailed_by_date.present? &&
IdentityConfig.store.in_person_outage_expected_update_date.present?
@header = is_enhanced_ipp ?
t('in_person_proofing.headings.barcode_eipp') : t('in_person_proofing.headings.barcode')
t('in_person_proofing.headings.barcode_eipp') : t('in_person_proofing.headings.barcode')
@presenter = Idv::InPerson::ReadyToVerifyPresenter.new(
enrollment: enrollment,
barcode_image_url: attachments['barcode.png'].url,
is_enhanced_ipp: is_enhanced_ipp,
)

if enrollment&.service_provider&.logo_is_email_compatible?
@logo_url = enrollment.service_provider.logo_url
else
@logo_url = nil
end
@sp_name = enrollment.service_provider&.friendly_name
@is_enhanced_ipp = is_enhanced_ipp

mail(
Expand Down
27 changes: 27 additions & 0 deletions app/models/service_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ServiceProvider < ApplicationRecord
scope(:internal, -> { where(iaa: IAA_INTERNAL) })
scope(:external, -> { where.not(iaa: IAA_INTERNAL).or(where(iaa: nil)) })

DEFAULT_LOGO = 'generic.svg'

def metadata
attributes.symbolize_keys.merge(certs: ssl_certs)
end
Expand Down Expand Up @@ -94,8 +96,33 @@ def attempts_public_key
end
end

def logo_url
if FeatureManagement.logo_upload_enabled? && remote_logo_key.present?
s3_logo_url
else
legacy_logo_url
end
end

def logo_is_email_compatible?
logo_url.end_with?('.png')
end

private

def s3_logo_url
region = IdentityConfig.store.aws_region
bucket = IdentityConfig.store.aws_logo_bucket

"https://s3.#{region}.amazonaws.com/#{bucket}/#{remote_logo_key}"
end

def legacy_logo_url
ActionController::Base.helpers.image_path("sp-logos/#{logo || DEFAULT_LOGO}")
rescue Propshaft::MissingAssetError
''
end

def attempts_config
IdentityConfig.store.allowed_attempts_providers.find do |config|
config['issuer'] == issuer
Expand Down
25 changes: 25 additions & 0 deletions app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@
</table>
<table class="row">
<tbody>
<% if @sp_name %>
<tr>
<th class="small-12 large-12 columns first last">
<table>
<tr style="display: table">
<th width="142px" style="padding-right: 20px; vertical-align: middle; display: table-cell">
<%= image_tag(
attachments['logo.png'].url,
size: '142x19',
style: 'width: 142px; height: 19px;',
alt: t('mailer.logo', app_name: APP_NAME),
) %>
</th>
<% if @logo_url %>
<th style="vertical-align: middle; display: table-cell; border-left-width: 1px; padding-left: 20px; border-left-style: solid; border-color: #3C3C3C"> <%= image_tag(@logo_url, height: 40, width: 'auto', alt: @sp_name) %> </th>
<% else %>
<th style="vertical-align: middle; display: table-cell; border-left-width: 1px; padding-left: 20px; border-left-style: solid; border-color: #3C3C3C"> <%= @sp_name =%> </th>
<% end %>
<th class="expander"></th>
</tr>
</table>
</th>
</tr>
<% else %>
<tr>
<th class="small-12 large-12 columns first last">
<table>
Expand All @@ -54,6 +78,7 @@
</table>
</th>
</tr>
<% end %>
</tbody>
</table>
<table class="row">
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_nav_branded.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= image_tag(asset_url('logo.svg'), height: 15, width: 111, alt: APP_NAME) %>
<div class="margin-x-105 height-5 border-right border-primary-light"></div>
<%= image_tag(decorated_sp_session.sp_logo_url, height: 40, alt: decorated_sp_session.sp_name) %>
<%= image_tag(current_sp.logo_url, height: 40, alt: decorated_sp_session.sp_name) %>
1 change: 1 addition & 0 deletions spec/controllers/idv/enter_password_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ def show
receive(:resolved_authn_context_result).and_return(authn_context_result),
)
end

it 'passes the correct param to the enrollment helper method' do
expect(UspsInPersonProofing::EnrollmentHelper).to receive(:schedule_in_person_enrollment)
.with(
Expand Down
6 changes: 0 additions & 6 deletions spec/decorators/null_service_provider_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
end
end

describe '#sp_logo' do
it 'returns nil' do
expect(subject.sp_logo).to be_nil
end
end

describe '#sp_name' do
it 'returns nil' do
expect(subject.sp_name).to be_nil
Expand Down
81 changes: 0 additions & 81 deletions spec/decorators/service_provider_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,87 +90,6 @@
end
end

describe '#sp_logo' do
context 'service provider has a logo' do
it 'returns the logo' do
sp_logo = 'real_logo.svg'
sp = build_stubbed(:service_provider, logo: sp_logo)

subject = ServiceProviderSession.new(
sp: sp,
view_context: view_context,
sp_session: {},
service_provider_request: ServiceProviderRequestProxy.new,
)

expect(subject.sp_logo).to eq sp_logo
end
end

context 'service provider does not have a logo' do
it 'returns the default logo' do
sp = build_stubbed(:service_provider, logo: nil)

subject = ServiceProviderSession.new(
sp: sp,
view_context: view_context,
sp_session: {},
service_provider_request: ServiceProviderRequestProxy.new,
)

expect(subject.sp_logo).to eq 'generic.svg'
end
end
end

describe '#sp_logo_url' do
context 'service provider has a logo' do
it 'returns the logo' do
sp_logo = '18f.svg'
sp = build_stubbed(:service_provider, logo: sp_logo)

subject = ServiceProviderSession.new(
sp: sp,
view_context: view_context,
sp_session: {},
service_provider_request: ServiceProviderRequestProxy.new,
)

expect(subject.sp_logo_url).to match(%r{sp-logos/18f-[0-9a-f]+\.svg$})
end
end

context 'service provider does not have a logo' do
it 'returns the default logo' do
sp = build_stubbed(:service_provider, logo: nil)

subject = ServiceProviderSession.new(
sp: sp,
view_context: view_context,
sp_session: {},
service_provider_request: ServiceProviderRequestProxy.new,
)

expect(subject.sp_logo_url).to match(%r{/sp-logos/generic-.+\.svg})
end
end

context 'service provider has a poorly configured logo' do
it 'does not raise an exception' do
sp = build_stubbed(:service_provider, logo: 'abc')

subject = ServiceProviderSession.new(
sp: sp,
view_context: view_context,
sp_session: {},
service_provider_request: ServiceProviderRequestProxy.new,
)

expect(subject.sp_logo_url).to be_kind_of(String)
end
end
end

describe '#cancel_link_url' do
subject(:decorator) do
ServiceProviderSession.new(
Expand Down
2 changes: 2 additions & 0 deletions spec/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def in_person_enrollment_id_ipp
service_provider: ServiceProvider.new(
friendly_name: 'Test Service Provider',
issuer: SecureRandom.uuid,
logo: 'gsa.png',
),
status_updated_at: Time.zone.now - 1.hour,
current_address_matches_id: params['current_address_matches_id'] == 'true',
Expand Down Expand Up @@ -359,6 +360,7 @@ def in_person_enrollment_enhanced_ipp
service_provider: ServiceProvider.new(
friendly_name: 'Test Service Provider',
issuer: SecureRandom.uuid,
logo: '18f.svg',
),
status_updated_at: Time.zone.now - 1.hour,
current_address_matches_id: params['current_address_matches_id'] == 'true',
Expand Down
6 changes: 6 additions & 0 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ def expect_email_body_to_have_help_and_contact_links
create(
:in_person_enrollment,
:pending,
:with_service_provider,
selected_location_details: { name: 'FRIENDSHIP' },
status_updated_at: Time.zone.now - 2.hours,
current_address_matches_id: current_address_matches_id,
Expand All @@ -815,6 +816,7 @@ def expect_email_body_to_have_help_and_contact_links
:in_person_enrollment,
:pending,
:enhanced_ipp,
:with_service_provider,
)
end
let(:visited_location_name) { 'ACQUAINTANCESHIP' }
Expand All @@ -824,6 +826,7 @@ def expect_email_body_to_have_help_and_contact_links
create(
:in_person_enrollment,
:expired,
:with_service_provider,
selected_location_details: { name: 'FRIENDSHIP' },
)
end
Expand Down Expand Up @@ -1205,6 +1208,7 @@ def expect_email_body_to_have_help_and_contact_links
let(:enrollment) do
create(
:in_person_enrollment,
:with_service_provider,
selected_location_details: { name: 'FRIENDSHIP' },
status_updated_at: Time.zone.now - 2.hours,
)
Expand Down Expand Up @@ -1236,6 +1240,7 @@ def expect_email_body_to_have_help_and_contact_links
let!(:enrollment) do
create(
:in_person_enrollment,
:with_service_provider,
selected_location_details: { name: 'FRIENDSHIP' },
status_updated_at: Time.zone.now - 2.hours,
current_address_matches_id: current_address_matches_id,
Expand Down Expand Up @@ -1268,6 +1273,7 @@ def expect_email_body_to_have_help_and_contact_links
let(:enrollment) do
create(
:in_person_enrollment,
:with_service_provider,
selected_location_details: { name: 'FRIENDSHIP' },
status_updated_at: Time.zone.now - 2.hours,
)
Expand Down
Loading