2020-03-09 17:57:10 +00:00
|
|
|
class Api::V1::Accounts::ContactsController < Api::BaseController
|
2019-08-14 09:48:44 +00:00
|
|
|
protect_from_forgery with: :null_session
|
|
|
|
|
|
|
|
before_action :check_authorization
|
|
|
|
before_action :fetch_contact, only: [:show, :update]
|
|
|
|
|
|
|
|
skip_before_action :authenticate_user!, only: [:create]
|
2019-10-20 08:47:26 +00:00
|
|
|
skip_before_action :set_current_user, only: [:create]
|
|
|
|
skip_before_action :check_subscription, only: [:create]
|
|
|
|
skip_around_action :handle_with_exception, only: [:create]
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@contacts = current_account.contacts
|
|
|
|
end
|
|
|
|
|
2019-10-20 08:47:26 +00:00
|
|
|
def show; end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
def create
|
|
|
|
@contact = Contact.new(contact_create_params)
|
|
|
|
@contact.save!
|
|
|
|
render json: @contact
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-12-10 04:59:35 +00:00
|
|
|
@contact.update!(contact_params)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_authorization
|
|
|
|
authorize(Contact)
|
|
|
|
end
|
|
|
|
|
|
|
|
def contact_params
|
|
|
|
params.require(:contact).permit(:name, :email, :phone_number)
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_contact
|
|
|
|
@contact = current_account.contacts.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def contact_create_params
|
2019-10-20 08:47:26 +00:00
|
|
|
params.require(:contact).permit(:account_id, :inbox_id).merge!(name: SecureRandom.hex)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
2019-10-20 08:47:26 +00:00
|
|
|
end
|