feat: IP lookup (#1315)

- feature to store contact IP for accounts
- IP lookup through geocoder gem
- ability to do IP lookup through external APIs
- add commit hook to prevent push to develop and master
- migrations to fix default values for jsonb columns
This commit is contained in:
Sojan Jose
2020-10-28 02:14:36 +05:30
committed by GitHub
parent ff96d43953
commit 1d9debaee0
16 changed files with 163 additions and 9 deletions

View File

@@ -19,13 +19,16 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
def create
ActiveRecord::Base.transaction do
@contact = Current.account.contacts.new(contact_params)
set_ip
@contact.save!
@contact_inbox = build_contact_inbox
end
end
def update
@contact.update!(contact_update_params)
@contact.assign_attributes(contact_update_params)
set_ip
@contact.save!
rescue ActiveRecord::RecordInvalid => e
render json: {
message: e.record.errors.full_messages.join(', '),
@@ -67,4 +70,11 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
def fetch_contact
@contact = Current.account.contacts.includes(contact_inboxes: [:inbox]).find(params[:id])
end
def set_ip
return if @contact.account.feature_enabled?('ip_lookup')
@contact[:additional_attributes][:created_at_ip] ||= request.remote_ip
@contact[:additional_attributes][:updated_at_ip] = request.remote_ip
end
end