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

[pro#622] Add Pro sign up ban check #1788

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions lib/alavetelitheme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def prepend_theme_assets
'mailer_patches.rb',
'analytics_event.rb',
'help_page_history.rb',
'pro_account_bans.rb',
'public_body_questions.rb',
'school_late_calculator.rb',
'volunteer_contact_form.rb',
Expand Down
4 changes: 4 additions & 0 deletions lib/model_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def late_calculator
]
}

ProAccount.class_eval do
prepend ProAccountBans::ModelMethods
end

PublicBody.class_eval do
# Return the domain part of an email address, canonicalised and with common
# extra UK Government server name parts removed.
Expand Down
31 changes: 31 additions & 0 deletions lib/pro_account_bans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module ProAccountBans
module ModelMethods
PRO_ACCOUNT_BANS_CONFIG = Rails.root.join('config/pro_account_bans.yml')

def update_source
return super unless pro_account_banned?

raise ProAccount::CardError, _("The card issuer couldn't authorize " \
"payment.")
end

def pro_account_banned?
return false unless bans_config

bans_config.any? do |ban|
ban.all? do |k, banned_value|
value = @token.card[k]
value.upcase.gsub(/\S/, '') if k == 'address_key'
value == banned_value
end
end
end

private

def bans_config
return unless File.exist?(PRO_ACCOUNT_BANS_CONFIG)
YAML.load_file(PRO_ACCOUNT_BANS_CONFIG)
end
end
end
Loading