feat(poc): Disable widget based on country (#6658)

This commit is contained in:
Pranav Raj S
2023-03-14 09:09:57 -07:00
committed by GitHub
parent e8a174f689
commit eb7070d946
8 changed files with 72 additions and 53 deletions

View File

@@ -0,0 +1,14 @@
module Enterprise::WidgetsController
private
def ensure_location_is_supported
countries = @web_widget.inbox.account.custom_attributes['allowed_countries']
return if countries.blank?
geocoder_result = IpLookupService.new.perform(request.remote_ip)
return unless geocoder_result
country_enabled = countries.include?(geocoder_result.country_code)
render json: { error: 'Location is not supported' }, status: :unauthorized unless country_enabled
end
end