Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 16 additions & 7 deletions app/services/phone_number_capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@ def self.load_config

attr_reader :phone, :phone_confirmed

def self.translated_international_codes
@translated_intl_codes_data = nil if Rails.env.development?
return @translated_intl_codes_data[I18n.locale] if @translated_intl_codes_data

@translated_intl_codes_data = Hash.new { |h, k| h[k] = {} }
def self.generate_translated_international_codes_data
translated_intl_codes_data = Hash.new { |h, k| h[k] = {} }
I18n.available_locales.each do |locale|
INTERNATIONAL_CODES.each do |k, value|
@translated_intl_codes_data[locale][k] =
translated_intl_codes_data[locale][k] =
value.merge('name' => I18n.t("countries.#{k.downcase}", locale: locale))
end
end
@translated_intl_codes_data[I18n.locale]
translated_intl_codes_data
end

def self.translated_international_codes
translated_intl_codes_data = if Rails.env.development?
generate_translated_international_codes_data
else
TRANSLATED_INTL_CODES_DATA
end

translated_intl_codes_data[I18n.locale] if translated_intl_codes_data
end

TRANSLATED_INTL_CODES_DATA = generate_translated_international_codes_data

def initialize(phone, phone_confirmed:)
@phone = phone
@phone_confirmed = phone_confirmed
Expand Down
25 changes: 9 additions & 16 deletions app/services/profanity_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,18 @@ def without_profanity(limit: 1_000)
# ProfanityFilter::Base.profane? splits by word, but this
# checks all substrings
def profane?(str)
preprocess_if_needed!

str_no_whitespace = str.gsub(/\W/, '').downcase

(min_profanity_length..[str_no_whitespace.length, max_profanity_length].min).each do |size|
profane_regex = @regex_by_length[size]
(MIN_PROFANITY_LENGTH..[str_no_whitespace.length, MAX_PROFANITY_LENGTH].min).each do |size|
profane_regex = REGEX_BY_LENGTH[size]
next if profane_regex.nil?
return true if profane_regex.match?(str_no_whitespace)
end

false
end

class << self
attr_reader :min_profanity_length
attr_reader :max_profanity_length
end

def preprocess_if_needed!
return if @preprocessed

def self.preprocess_lengths!
# Map of {Integer => Set<string>}
profanity_by_length = Hash.new { |h, k| h[k] = Set.new }

Expand All @@ -49,15 +40,17 @@ def preprocess_if_needed!
end

# Map of {Integer => Regexp}
@regex_by_length = Hash.new
regex_by_length = Hash.new

profanity_by_length.each do |k, v|
escaped = v.to_a.map { |x| Regexp.escape(x) }
@regex_by_length[k] = Regexp.new("(#{escaped.join('|')})")
regex_by_length[k] = Regexp.new("(#{escaped.join('|')})")
end

@min_profanity_length, @max_profanity_length = profanity_by_length.keys.minmax
min_profanity_length, max_profanity_length = profanity_by_length.keys.minmax

@preprocessed = true
return [regex_by_length, min_profanity_length, max_profanity_length]
Comment thread
mitchellhenke marked this conversation as resolved.
Outdated
end

REGEX_BY_LENGTH, MIN_PROFANITY_LENGTH, MAX_PROFANITY_LENGTH = self.preprocess_lengths!
end
2 changes: 1 addition & 1 deletion app/services/saml_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.suffixes
end

def self.endpoint_configs
@endpoint_configs ||= IdentityConfig.store.saml_endpoint_configs
IdentityConfig.store.saml_endpoint_configs
end

def secret_key
Expand Down
4 changes: 0 additions & 4 deletions config/initializers/rack_timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class Timeout
[path] + Idp::Constants::AVAILABLE_LOCALES.map { |locale| "/#{locale}#{path}" }
end + ['/api/verify/images']

class << self
attr_accessor :excludes
end

def call_with_excludes(env)
if EXCLUDES.any? { |path| env['REQUEST_URI']&.start_with?(path) }
@app.call(env)
Expand Down
2 changes: 0 additions & 2 deletions lib/aws/ses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
module Aws
module SES
class Base
cattr_accessor :region_pool

def initialize(*); end

def deliver(mail)
Expand Down