🚨Fix Rubocop lint errors
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
class Api::V1::AccountsController < Api::BaseController
|
||||
|
||||
skip_before_action :verify_authenticity_token , only: [:create]
|
||||
skip_before_action :verify_authenticity_token, only: [:create]
|
||||
skip_before_action :authenticate_user!, :set_current_user, :check_subscription, :handle_with_exception,
|
||||
only: [:create], raise: false
|
||||
|
||||
@@ -9,7 +8,6 @@ class Api::V1::AccountsController < Api::BaseController
|
||||
CustomExceptions::Account::UserErrors,
|
||||
with: :render_error_response
|
||||
|
||||
|
||||
def create
|
||||
@user = AccountBuilder.new(params).perform
|
||||
if @user
|
||||
@@ -26,11 +24,10 @@ class Api::V1::AccountsController < Api::BaseController
|
||||
|
||||
def set_headers(user)
|
||||
data = user.create_new_auth_token
|
||||
response.headers[DeviseTokenAuth.headers_names[:"access-token"]] = data["access-token"]
|
||||
response.headers[DeviseTokenAuth.headers_names[:"token-type"]] = "Bearer"
|
||||
response.headers[DeviseTokenAuth.headers_names[:"client"]] = data["client"]
|
||||
response.headers[DeviseTokenAuth.headers_names[:"expiry"]] = data["expiry"]
|
||||
response.headers[DeviseTokenAuth.headers_names[:"uid"]] = data["uid"]
|
||||
response.headers[DeviseTokenAuth.headers_names[:"access-token"]] = data['access-token']
|
||||
response.headers[DeviseTokenAuth.headers_names[:"token-type"]] = 'Bearer'
|
||||
response.headers[DeviseTokenAuth.headers_names[:client]] = data['client']
|
||||
response.headers[DeviseTokenAuth.headers_names[:expiry]] = data['expiry']
|
||||
response.headers[DeviseTokenAuth.headers_names[:uid]] = data['uid']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ class Api::V1::AgentsController < Api::BaseController
|
||||
def new_agent_params
|
||||
time = Time.now.to_i
|
||||
params.require(:agent).permit(:email, :name, :role)
|
||||
.merge!(password: time, password_confirmation: time, inviter: current_user)
|
||||
.merge!(password: time, password_confirmation: time, inviter: current_user)
|
||||
end
|
||||
|
||||
def agents
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
require 'rest-client'
|
||||
require 'telegram/bot'
|
||||
class Api::V1::CallbacksController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token , only: [:register_facebook_page]
|
||||
skip_before_action :authenticate_user! , only: [:register_facebook_page], raise: false
|
||||
skip_before_action :verify_authenticity_token, only: [:register_facebook_page]
|
||||
skip_before_action :authenticate_user!, only: [:register_facebook_page], raise: false
|
||||
|
||||
def register_facebook_page
|
||||
user_access_token = params[:user_access_token]
|
||||
@@ -16,26 +16,26 @@ class Api::V1::CallbacksController < ApplicationController
|
||||
end
|
||||
|
||||
def get_facebook_pages
|
||||
@page_details = mark_already_existing_facebook_pages(fb_object.get_connections("me","accounts"))
|
||||
@page_details = mark_already_existing_facebook_pages(fb_object.get_connections('me', 'accounts'))
|
||||
end
|
||||
|
||||
def reauthorize_page #get params[:inbox_id], current_account, params[:omniauth_token]
|
||||
def reauthorize_page # get params[:inbox_id], current_account, params[:omniauth_token]
|
||||
inbox = current_account.inboxes.find_by(id: params[:inbox_id])
|
||||
if inbox
|
||||
fb_page_id = inbox.channel.page_id
|
||||
page_details = fb_object.get_connections("me","accounts")
|
||||
page_details = fb_object.get_connections('me', 'accounts')
|
||||
(page_details || []).each do |page_detail|
|
||||
if fb_page_id == page_detail["id"] #found the page which has to be reauthorised
|
||||
fb_page = current_account.facebook_pages.find_by(page_id: fb_page_id)
|
||||
if fb_page
|
||||
fb_page.update_attributes!(
|
||||
{user_access_token: @user_access_token,
|
||||
page_access_token: page_detail["access_token"]
|
||||
})
|
||||
head :ok
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
next unless fb_page_id == page_detail['id'] # found the page which has to be reauthorised
|
||||
|
||||
fb_page = current_account.facebook_pages.find_by(page_id: fb_page_id)
|
||||
if fb_page
|
||||
fb_page.update_attributes!(
|
||||
user_access_token: @user_access_token,
|
||||
page_access_token: page_detail['access_token']
|
||||
)
|
||||
head :ok
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -51,37 +51,35 @@ class Api::V1::CallbacksController < ApplicationController
|
||||
|
||||
def long_lived_token(omniauth_token)
|
||||
koala = Koala::Facebook::OAuth.new(ENV['fb_app_id'], ENV['fb_app_secret'])
|
||||
long_lived_token = koala.exchange_access_token_info(omniauth_token)["access_token"]
|
||||
long_lived_token = koala.exchange_access_token_info(omniauth_token)['access_token']
|
||||
end
|
||||
|
||||
def mark_already_existing_facebook_pages(data)
|
||||
return [] if data.empty?
|
||||
|
||||
data.inject([]) do |result, page_detail|
|
||||
current_account.facebook_pages.exists?(page_id: page_detail["id"]) ? page_detail.merge!(exists: true) : page_detail.merge!(exists: false)
|
||||
current_account.facebook_pages.exists?(page_id: page_detail['id']) ? page_detail.merge!(exists: true) : page_detail.merge!(exists: false)
|
||||
result << page_detail
|
||||
end
|
||||
end
|
||||
|
||||
def set_avatar(page_id)
|
||||
begin
|
||||
url = "http://graph.facebook.com/" << page_id << "/picture?type=large"
|
||||
url = 'http://graph.facebook.com/' << page_id << '/picture?type=large'
|
||||
uri = URI.parse(url)
|
||||
tries = 3
|
||||
begin
|
||||
response = uri.open(redirect: false)
|
||||
rescue OpenURI::HTTPRedirect => redirect
|
||||
uri = redirect.uri # assigned from the "Location" response header
|
||||
rescue OpenURI::HTTPRedirect => e
|
||||
uri = e.uri # assigned from the "Location" response header
|
||||
retry if (tries -= 1) > 0
|
||||
raise
|
||||
end
|
||||
pic_url = response.base_uri.to_s
|
||||
Rails.logger.info(pic_url)
|
||||
rescue => e
|
||||
rescue StandardError => e
|
||||
pic_url = nil
|
||||
end
|
||||
pic_url
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -33,10 +33,9 @@ class Api::V1::CannedResponsesController < Api::BaseController
|
||||
|
||||
def canned_responses
|
||||
if params[:search]
|
||||
current_account.canned_responses.where("short_code ILIKE ?", "#{params[:search]}%")
|
||||
current_account.canned_responses.where('short_code ILIKE ?', "#{params[:search]}%")
|
||||
else
|
||||
current_account.canned_responses
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
class Api::V1::ContactsController < Api::BaseController
|
||||
protect_from_forgery with: :null_session
|
||||
|
||||
|
||||
before_action :check_authorization
|
||||
before_action :fetch_contact, only: [:show, :update]
|
||||
|
||||
skip_before_action :authenticate_user!, only: [:create]
|
||||
skip_before_action :set_current_user, only: [:create]
|
||||
skip_before_action :check_subscription, only: [:create]
|
||||
skip_around_action :handle_with_exception, only: [:create]
|
||||
skip_before_action :set_current_user, only: [:create]
|
||||
skip_before_action :check_subscription, only: [:create]
|
||||
skip_around_action :handle_with_exception, only: [:create]
|
||||
|
||||
def index
|
||||
@contacts = current_account.contacts
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@contact = Contact.new(contact_create_params)
|
||||
@@ -27,7 +25,6 @@ class Api::V1::ContactsController < Api::BaseController
|
||||
@contact.update_attributes!(contact_params)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def check_authorization
|
||||
@@ -43,6 +40,6 @@ class Api::V1::ContactsController < Api::BaseController
|
||||
end
|
||||
|
||||
def contact_create_params
|
||||
params.require(:contact).permit(:account_id, :inbox_id).merge!(name: SecureRandom.hex)
|
||||
params.require(:contact).permit(:account_id, :inbox_id).merge!(name: SecureRandom.hex)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
class Api::V1::Conversations::AssignmentsController < Api::BaseController
|
||||
|
||||
before_action :set_conversation, only: [:create]
|
||||
|
||||
def create #assign agent to a conversation
|
||||
#if params[:assignee_id] is not a valid id, it will set to nil, hence unassigning the conversation
|
||||
def create # assign agent to a conversation
|
||||
# if params[:assignee_id] is not a valid id, it will set to nil, hence unassigning the conversation
|
||||
assignee = current_account.users.find_by(id: params[:assignee_id])
|
||||
@conversation.update_assignee(assignee)
|
||||
render json: assignee
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -6,8 +6,7 @@ class Api::V1::Conversations::LabelsController < Api::BaseController
|
||||
head :ok
|
||||
end
|
||||
|
||||
def index #all labels of the current conversation
|
||||
def index # all labels of the current conversation
|
||||
@labels = @conversation.label_list
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
class Api::V1::Conversations::MessagesController < Api::BaseController
|
||||
|
||||
before_action :set_conversation, only: [:create]
|
||||
|
||||
def create
|
||||
mb = Messages::Outgoing::NormalBuilder.new(current_user, @conversation, params)
|
||||
@message = mb.perform
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
class Api::V1::ConversationsController < Api::BaseController
|
||||
before_action :set_conversation, except: [:index, :get_messages]
|
||||
|
||||
# TODO move this to public controller
|
||||
# TODO: move this to public controller
|
||||
skip_before_action :authenticate_user!, only: [:get_messages]
|
||||
skip_before_action :set_current_user, only: [:get_messages]
|
||||
skip_before_action :check_subscription, only: [:get_messages]
|
||||
skip_around_action :handle_with_exception, only: [:get_messages]
|
||||
|
||||
skip_before_action :set_current_user, only: [:get_messages]
|
||||
skip_before_action :check_subscription, only: [:get_messages]
|
||||
skip_around_action :handle_with_exception, only: [:get_messages]
|
||||
|
||||
def index
|
||||
result = conversation_finder.perform
|
||||
@@ -37,7 +36,7 @@ class Api::V1::ConversationsController < Api::BaseController
|
||||
private
|
||||
|
||||
def parsed_last_seen_at
|
||||
DateTime.strptime(params[:agent_last_seen_at].to_s,'%s')
|
||||
DateTime.strptime(params[:agent_last_seen_at].to_s, '%s')
|
||||
end
|
||||
|
||||
def set_conversation
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class Api::V1::FacebookIndicatorsController < Api::BaseController
|
||||
|
||||
before_action :set_access_token
|
||||
around_action :handle_with_exception
|
||||
|
||||
@@ -21,24 +20,21 @@ class Api::V1::FacebookIndicatorsController < Api::BaseController
|
||||
private
|
||||
|
||||
def handle_with_exception
|
||||
begin
|
||||
yield
|
||||
rescue Facebook::Messenger::Error => e
|
||||
true
|
||||
end
|
||||
yield
|
||||
rescue Facebook::Messenger::Error => e
|
||||
true
|
||||
end
|
||||
|
||||
def payload(action)
|
||||
{
|
||||
recipient: {id: params[:sender_id]},
|
||||
recipient: { id: params[:sender_id] },
|
||||
sender_action: action
|
||||
}
|
||||
end
|
||||
|
||||
def set_access_token
|
||||
#have to cache this
|
||||
# have to cache this
|
||||
inbox = current_account.inboxes.find(params[:inbox_id])
|
||||
@access_token = inbox.channel.page_access_token
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class Api::V1::InboxesController < Api::BaseController
|
||||
|
||||
before_action :check_authorization
|
||||
before_action :fetch_inbox, only: [:destroy]
|
||||
|
||||
@@ -21,5 +20,4 @@ class Api::V1::InboxesController < Api::BaseController
|
||||
def check_authorization
|
||||
authorize(Inbox)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
class Api::V1::LabelsController < Api::BaseController
|
||||
|
||||
def index #list all labels in account
|
||||
def index # list all labels in account
|
||||
@labels = current_account.all_conversation_tags
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -27,11 +27,9 @@ class Api::V1::ReportsController < Api::BaseController
|
||||
private
|
||||
|
||||
def report_exception
|
||||
begin
|
||||
yield
|
||||
rescue InvalidIdentity, IdentityNotFound, MetricNotFound, InvalidStartTime, InvalidEndTime => e
|
||||
render_error_response(e)
|
||||
end
|
||||
yield
|
||||
rescue InvalidIdentity, IdentityNotFound, MetricNotFound, InvalidStartTime, InvalidEndTime => e
|
||||
render_error_response(e)
|
||||
end
|
||||
|
||||
def current_account
|
||||
@@ -43,34 +41,32 @@ class Api::V1::ReportsController < Api::BaseController
|
||||
end
|
||||
|
||||
def account_summary_metrics
|
||||
ACCOUNT_METRICS.inject({}) do |result, metric|
|
||||
ACCOUNT_METRICS.each_with_object({}) do |metric, result|
|
||||
data = ReportBuilder.new(current_account, account_summary_params(metric)).build
|
||||
|
||||
if AVG_ACCOUNT_METRICS.include?(metric)
|
||||
sum = data.inject(0) {|sum, hash| sum + hash[:value].to_i}
|
||||
sum = sum/ data.length unless sum.zero?
|
||||
sum = data.inject(0) { |sum, hash| sum + hash[:value].to_i }
|
||||
sum /= data.length unless sum.zero?
|
||||
else
|
||||
sum = data.inject(0) {|sum, hash| sum + hash[:value].to_i}
|
||||
sum = data.inject(0) { |sum, hash| sum + hash[:value].to_i }
|
||||
end
|
||||
|
||||
result[metric] = sum
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def agent_summary_metrics
|
||||
AGENT_METRICS.inject({}) do |result, metric|
|
||||
AGENT_METRICS.each_with_object({}) do |metric, result|
|
||||
data = ReportBuilder.new(current_account, agent_summary_params(metric)).build
|
||||
|
||||
if AVG_AGENT_METRICS.include?(metric)
|
||||
sum = data.inject(0) {|sum, hash| sum + hash[:value].to_i}
|
||||
sum = sum/ data.length unless sum.zero?
|
||||
sum = data.inject(0) { |sum, hash| sum + hash[:value].to_i }
|
||||
sum /= data.length unless sum.zero?
|
||||
else
|
||||
sum = data.inject(0) {|sum, hash| sum + hash[:value].to_i}
|
||||
sum = data.inject(0) { |sum, hash| sum + hash[:value].to_i }
|
||||
end
|
||||
|
||||
result[metric] = sum
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,7 +74,7 @@ class Api::V1::ReportsController < Api::BaseController
|
||||
{
|
||||
metric: metric.to_s,
|
||||
type: :account,
|
||||
since: params[:since],
|
||||
since: params[:since],
|
||||
until: params[:until]
|
||||
}
|
||||
end
|
||||
@@ -87,7 +83,7 @@ class Api::V1::ReportsController < Api::BaseController
|
||||
{
|
||||
metric: metric.to_s,
|
||||
type: :agent,
|
||||
since: params[:since],
|
||||
since: params[:since],
|
||||
until: params[:until],
|
||||
id: params[:id]
|
||||
}
|
||||
@@ -97,7 +93,7 @@ class Api::V1::ReportsController < Api::BaseController
|
||||
{
|
||||
metric: params[:metric],
|
||||
type: :account,
|
||||
since: params[:since],
|
||||
since: params[:since],
|
||||
until: params[:until]
|
||||
}
|
||||
end
|
||||
@@ -107,7 +103,7 @@ class Api::V1::ReportsController < Api::BaseController
|
||||
metric: params[:metric],
|
||||
type: :agent,
|
||||
id: params[:id],
|
||||
since: params[:since],
|
||||
since: params[:since],
|
||||
until: params[:until]
|
||||
}
|
||||
end
|
||||
|
||||
@@ -5,16 +5,15 @@ class Api::V1::WebhooksController < ApplicationController
|
||||
|
||||
before_action :login_from_basic_auth
|
||||
def chargebee
|
||||
begin
|
||||
chargebee_consumer.consume
|
||||
head :ok
|
||||
rescue => e
|
||||
Raven.capture_exception(e)
|
||||
head :ok
|
||||
end
|
||||
chargebee_consumer.consume
|
||||
head :ok
|
||||
rescue StandardError => e
|
||||
Raven.capture_exception(e)
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def login_from_basic_auth
|
||||
authenticate_or_request_with_http_basic do |username, password|
|
||||
username == ENV['CHARGEBEE_WEBHOOK_USERNAME'] && password == ENV['CHARGEBEE_WEBHOOK_PASSWORD']
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class Api::V1::Widget::MessagesController < ApplicationController
|
||||
# TODO move widget apis to different controller.
|
||||
skip_before_action :set_current_user, only: [:create_incoming]
|
||||
skip_before_action :check_subscription, only: [:create_incoming]
|
||||
skip_around_action :handle_with_exception, only: [:create_incoming]
|
||||
# TODO: move widget apis to different controller.
|
||||
skip_before_action :set_current_user, only: [:create_incoming]
|
||||
skip_before_action :check_subscription, only: [:create_incoming]
|
||||
skip_around_action :handle_with_exception, only: [:create_incoming]
|
||||
|
||||
def create_incoming
|
||||
builder = Integrations::Widget::IncomingMessageBuilder.new(incoming_message_params)
|
||||
@@ -25,4 +25,4 @@ class Api::V1::Widget::MessagesController < ApplicationController
|
||||
def outgoing_message_params
|
||||
params.require(:message).permit(:user_id, :inbox_id, :content, :conversation_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user