chore: lint files (#2)
* chore: lint files * chore: suppress warning * chore: disable suggest extensions * chore: do not stage changes in pre-commit * chore: remove git add from FE lint and `-a` flag from rubocop on husky
This commit is contained in:
parent
1d6b15b23d
commit
52a55827c3
@ -5,7 +5,7 @@
|
|||||||
npx --no-install lint-staged
|
npx --no-install lint-staged
|
||||||
|
|
||||||
# lint only staged ruby files
|
# lint only staged ruby files
|
||||||
git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop --force-exclusion -a
|
git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop --force-exclusion
|
||||||
|
|
||||||
# stage rubocop changes to files
|
# stage rubocop changes to files
|
||||||
git diff --name-only --cached | xargs git add
|
# git diff --name-only --cached | xargs git add
|
||||||
|
|||||||
@ -154,6 +154,7 @@ CustomCopLocation:
|
|||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
NewCops: enable
|
NewCops: enable
|
||||||
|
SuggestExtensions: false
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'bin/**/*'
|
- 'bin/**/*'
|
||||||
- 'db/schema.rb'
|
- 'db/schema.rb'
|
||||||
@ -166,3 +167,6 @@ AllCops:
|
|||||||
- 'tmp/**/*'
|
- 'tmp/**/*'
|
||||||
- 'storage/**/*'
|
- 'storage/**/*'
|
||||||
- 'db/migrate/20230426130150_init_schema.rb'
|
- 'db/migrate/20230426130150_init_schema.rb'
|
||||||
|
|
||||||
|
Layout/LeadingCommentSpace:
|
||||||
|
Enabled: false
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@ -40,7 +40,7 @@ gem 'down'
|
|||||||
# authentication type to fetch and send mail over oauth2.0
|
# authentication type to fetch and send mail over oauth2.0
|
||||||
gem 'gmail_xoauth'
|
gem 'gmail_xoauth'
|
||||||
# Lock net-smtp to 0.3.4 to avoid issues with gmail_xoauth2
|
# Lock net-smtp to 0.3.4 to avoid issues with gmail_xoauth2
|
||||||
gem 'net-smtp', '~> 0.3.4'
|
gem 'net-smtp', '~> 0.3.4'
|
||||||
# Prevent CSV injection
|
# Prevent CSV injection
|
||||||
gem 'csv-safe'
|
gem 'csv-safe'
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,7 @@ class ContactIdentifyAction
|
|||||||
end
|
end
|
||||||
|
|
||||||
def merge_contacts?(existing_contact, key)
|
def merge_contacts?(existing_contact, key)
|
||||||
return if existing_contact.blank?
|
return false if existing_contact.blank?
|
||||||
|
|
||||||
return true if params[:identifier].blank?
|
return true if params[:identifier].blank?
|
||||||
|
|
||||||
|
|||||||
@ -166,7 +166,7 @@ class Messages::Instagram::MessageBuilder < Messages::Messenger::MessageBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def all_unsupported_files?
|
def all_unsupported_files?
|
||||||
return if attachments.empty?
|
return false if attachments.empty?
|
||||||
|
|
||||||
attachments_type = attachments.pluck(:type).uniq.first
|
attachments_type = attachments.pluck(:type).uniq.first
|
||||||
unsupported_file_type?(attachments_type)
|
unsupported_file_type?(attachments_type)
|
||||||
|
|||||||
@ -24,7 +24,6 @@ class Api::V1::Accounts::AutomationRulesController < Api::V1::Accounts::BaseCont
|
|||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
automation_rule_update
|
automation_rule_update
|
||||||
process_attachments
|
process_attachments
|
||||||
|
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
Rails.logger.error e
|
Rails.logger.error e
|
||||||
render json: { error: @automation_rule.errors.messages }.to_json, status: :unprocessable_entity
|
render json: { error: @automation_rule.errors.messages }.to_json, status: :unprocessable_entity
|
||||||
|
|||||||
@ -82,7 +82,7 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_not_found_if_empty
|
def render_not_found_if_empty
|
||||||
return head :not_found if conversation.nil?
|
head :not_found if conversation.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def permitted_params
|
def permitted_params
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class ApiController < ApplicationController
|
|||||||
|
|
||||||
def redis_status
|
def redis_status
|
||||||
r = Redis.new(Redis::Config.app)
|
r = Redis.new(Redis::Config.app)
|
||||||
return 'ok' if r.ping
|
'ok' if r.ping
|
||||||
rescue Redis::CannotConnectError
|
rescue Redis::CannotConnectError
|
||||||
'failing'
|
'failing'
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,7 +6,7 @@ class SuperAdmin::AccountUsersController < SuperAdmin::ApplicationController
|
|||||||
resource = resource_class.new(resource_params)
|
resource = resource_class.new(resource_params)
|
||||||
authorize_resource(resource)
|
authorize_resource(resource)
|
||||||
|
|
||||||
notice = resource.save ? translate_with_resource('create.success') : resource.errors.full_messages.first
|
notice = resource.save ? translate_with_resource('create.success') : resource.errors.full_messages.first
|
||||||
redirect_back(fallback_location: [namespace, resource.account], notice: notice)
|
redirect_back(fallback_location: [namespace, resource.account], notice: notice)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -52,8 +52,8 @@ module ReportingEventHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def format_time(hour, minute)
|
def format_time(hour, minute)
|
||||||
hour = hour < 10 ? "0#{hour}" : hour
|
hour = "0#{hour}" if hour < 10
|
||||||
minute = minute < 10 ? "0#{minute}" : minute
|
minute = "0#{minute}" if minute < 10
|
||||||
"#{hour}:#{minute}"
|
"#{hour}:#{minute}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,6 +14,6 @@ module TimezoneHelper
|
|||||||
zone.now.utc_offset == offset_in_seconds
|
zone.now.utc_offset == offset_in_seconds
|
||||||
end
|
end
|
||||||
|
|
||||||
return matching_zone.name if matching_zone
|
matching_zone&.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -47,6 +47,6 @@ class Webhooks::WhatsappEventsJob < ApplicationJob
|
|||||||
phone_number_id = wb_params[:entry].first[:changes].first.dig(:value, :metadata, :phone_number_id)
|
phone_number_id = wb_params[:entry].first[:changes].first.dig(:value, :metadata, :phone_number_id)
|
||||||
channel = Channel::Whatsapp.find_by(phone_number: phone_number)
|
channel = Channel::Whatsapp.find_by(phone_number: phone_number)
|
||||||
# validate to ensure the phone number id matches the whatsapp channel
|
# validate to ensure the phone number id matches the whatsapp channel
|
||||||
return channel if channel && channel.provider_config['phone_number_id'] == phone_number_id
|
channel if channel && channel.provider_config['phone_number_id'] == phone_number_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -53,8 +53,8 @@ class AgentBotListener < BaseListener
|
|||||||
private
|
private
|
||||||
|
|
||||||
def connected_agent_bot_exist?(inbox)
|
def connected_agent_bot_exist?(inbox)
|
||||||
return if inbox.agent_bot_inbox.blank?
|
return false if inbox.agent_bot_inbox.blank?
|
||||||
return unless inbox.agent_bot_inbox.active?
|
return false unless inbox.agent_bot_inbox.active?
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -70,7 +70,7 @@ class AutomationRuleListener < BaseListener
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rule_present?(event_name, account)
|
def rule_present?(event_name, account)
|
||||||
return if account.blank?
|
return false if account.blank?
|
||||||
|
|
||||||
current_account_rules(event_name, account).any?
|
current_account_rules(event_name, account).any?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -72,8 +72,8 @@ class ConversationReplyMailer < ApplicationMailer
|
|||||||
|
|
||||||
def conversation_already_viewed?
|
def conversation_already_viewed?
|
||||||
# whether contact already saw the message on widget
|
# whether contact already saw the message on widget
|
||||||
return unless @conversation.contact_last_seen_at
|
return false unless @conversation.contact_last_seen_at
|
||||||
return unless last_outgoing_message&.created_at
|
return false unless last_outgoing_message&.created_at
|
||||||
|
|
||||||
@conversation.contact_last_seen_at > last_outgoing_message&.created_at
|
@conversation.contact_last_seen_at > last_outgoing_message&.created_at
|
||||||
end
|
end
|
||||||
|
|||||||
@ -123,9 +123,9 @@ class Attachment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def should_validate_file?
|
def should_validate_file?
|
||||||
return unless file.attached?
|
return false unless file.attached?
|
||||||
# we are only limiting attachment types in case of website widget
|
# we are only limiting attachment types in case of website widget
|
||||||
return unless message.inbox.channel_type == 'Channel::WebWidget'
|
return false unless message.inbox.channel_type == 'Channel::WebWidget'
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class ContentAttributeValidator < ActiveModel::Validator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_item_actions!(record)
|
def validate_item_actions!(record)
|
||||||
if record.items.select { |item| item[:actions].blank? }.present?
|
if record.items.select { |item| item[:actions].blank? }.present? # rubocop:disable Style/RedundantFilterChain
|
||||||
record.errors.add(:content_attributes, 'contains items missing actions') && return
|
record.errors.add(:content_attributes, 'contains items missing actions') && return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -25,8 +25,8 @@ module Featurable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable_features!(*names)
|
def enable_features!(*)
|
||||||
enable_features(*names)
|
enable_features(*)
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ module Featurable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable_features!(*names)
|
def disable_features!(*)
|
||||||
disable_features(*names)
|
disable_features(*)
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -290,8 +290,9 @@ class Conversation < ApplicationRecord
|
|||||||
|
|
||||||
def conversation_status_changed_to_open?
|
def conversation_status_changed_to_open?
|
||||||
return false unless open?
|
return false unless open?
|
||||||
|
|
||||||
# saved_change_to_status? method only works in case of update
|
# saved_change_to_status? method only works in case of update
|
||||||
return true if previous_changes.key?(:id) || saved_change_to_status?
|
true if previous_changes.key?(:id) || saved_change_to_status?
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_label_change(user_name)
|
def create_label_change(user_name)
|
||||||
|
|||||||
@ -359,9 +359,9 @@ class Message < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def can_notify_via_mail?
|
def can_notify_via_mail?
|
||||||
return unless email_notifiable_message?
|
return false unless email_notifiable_message?
|
||||||
return unless email_notifiable_channel?
|
return false unless email_notifiable_channel?
|
||||||
return if conversation.contact.email.blank?
|
return false if conversation.contact.email.blank?
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -109,8 +109,8 @@ class User < ApplicationRecord
|
|||||||
self.email = email.try(:downcase)
|
self.email = email.try(:downcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_devise_notification(notification, *args)
|
def send_devise_notification(notification, *)
|
||||||
devise_mailer.with(account: Current.account).send(notification, self, *args).deliver_later
|
devise_mailer.with(account: Current.account).send(notification, self, *).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_password_and_uid
|
def set_password_and_uid
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class AutoAssignment::InboxRoundRobinService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_queue?
|
def validate_queue?
|
||||||
return true if inbox.inbox_members.map(&:user_id).sort == queue.map(&:to_i).sort
|
true if inbox.inbox_members.map(&:user_id).sort == queue.map(&:to_i).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def queue
|
def queue
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class Line::IncomingMessageService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def message_created?(event)
|
def message_created?(event)
|
||||||
return unless event_type_message?(event)
|
return false unless event_type_message?(event)
|
||||||
|
|
||||||
@message = @conversation.messages.build(
|
@message = @conversation.messages.build(
|
||||||
content: message_content(event),
|
content: message_content(event),
|
||||||
|
|||||||
@ -66,10 +66,10 @@ class MessageTemplates::HookExecutionService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def should_send_csat_survey?
|
def should_send_csat_survey?
|
||||||
return unless csat_enabled_conversation?
|
return false unless csat_enabled_conversation?
|
||||||
|
|
||||||
# only send CSAT once in a conversation
|
# only send CSAT once in a conversation
|
||||||
return if conversation.messages.where(content_type: :input_csat).present?
|
return false if conversation.messages.where(content_type: :input_csat).present?
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -12,8 +12,8 @@ class ArticleKeyConverter
|
|||||||
|
|
||||||
def convert_key(id)
|
def convert_key(id)
|
||||||
verifier_name = 'ActiveStorage'
|
verifier_name = 'ActiveStorage'
|
||||||
key_generator = ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base, iterations: 1000,
|
key_generator = ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base, iterations: 1000,
|
||||||
hash_digest_class: OpenSSL::Digest::SHA1)
|
hash_digest_class: OpenSSL::Digest::SHA1)
|
||||||
key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator)
|
key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator)
|
||||||
secret = key_generator.generate_key(verifier_name.to_s)
|
secret = key_generator.generate_key(verifier_name.to_s)
|
||||||
verifier = ActiveSupport::MessageVerifier.new(secret)
|
verifier = ActiveSupport::MessageVerifier.new(secret)
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class Internal::ReconcilePlanConfigService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def premium_config
|
def premium_config
|
||||||
@premium_config ||= YAML.safe_load(File.read("#{config_path}/premium_installation_config.yml")).freeze
|
@premium_config ||= YAML.safe_load_file("#{config_path}/premium_installation_config.yml").freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_premium_config_reset_warning
|
def remove_premium_config_reset_warning
|
||||||
@ -46,7 +46,7 @@ class Internal::ReconcilePlanConfigService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def premium_features
|
def premium_features
|
||||||
@premium_features ||= YAML.safe_load(File.read("#{config_path}/premium_features.yml")).freeze
|
@premium_features ||= YAML.safe_load_file("#{config_path}/premium_features.yml").freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def reconcile_premium_features
|
def reconcile_premium_features
|
||||||
|
|||||||
@ -63,7 +63,7 @@ class Captain::Agent
|
|||||||
"Tool execution failed: #{e.message}"
|
"Tool execution failed: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def construct_prompt(config)
|
def construct_prompt(config) # rubocop:disable Metrics/MethodLength
|
||||||
return config[:prompt] if config[:prompt]
|
return config[:prompt] if config[:prompt]
|
||||||
|
|
||||||
<<~PROMPT
|
<<~PROMPT
|
||||||
|
|||||||
@ -12,7 +12,7 @@ module ChatwootApp
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.enterprise?
|
def self.enterprise?
|
||||||
return if ENV.fetch('DISABLE_ENTERPRISE', false)
|
return false if ENV.fetch('DISABLE_ENTERPRISE', false)
|
||||||
|
|
||||||
@enterprise ||= root.join('enterprise').exist?
|
@enterprise ||= root.join('enterprise').exist?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -18,7 +18,7 @@ class ChatwootCaptcha
|
|||||||
secret: @server_key
|
secret: @server_key
|
||||||
})
|
})
|
||||||
|
|
||||||
return unless response.success?
|
return false unless response.success?
|
||||||
|
|
||||||
response.parsed_response['success']
|
response.parsed_response['success']
|
||||||
end
|
end
|
||||||
|
|||||||
@ -28,13 +28,13 @@ class ConfigLoader
|
|||||||
|
|
||||||
def general_configs
|
def general_configs
|
||||||
@config_path ||= Rails.root.join('config')
|
@config_path ||= Rails.root.join('config')
|
||||||
@general_configs ||= YAML.safe_load(File.read("#{@config_path}/installation_config.yml")).freeze
|
@general_configs ||= YAML.safe_load_file("#{@config_path}/installation_config.yml").freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def account_features
|
def account_features
|
||||||
@account_features ||= YAML.safe_load(File.read("#{@config_path}/features.yml")).freeze
|
@account_features ||= YAML.safe_load_file("#{@config_path}/features.yml").freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def reconcile_general_config
|
def reconcile_general_config
|
||||||
|
|||||||
@ -14,9 +14,9 @@ class Integrations::BotProcessorService
|
|||||||
private
|
private
|
||||||
|
|
||||||
def should_run_processor?(message)
|
def should_run_processor?(message)
|
||||||
return if message.private?
|
return false if message.private?
|
||||||
return unless processable_message?(message)
|
return false unless processable_message?(message)
|
||||||
return unless conversation.pending?
|
return false unless conversation.pending?
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
@ -43,8 +43,8 @@ class Integrations::BotProcessorService
|
|||||||
|
|
||||||
def processable_message?(message)
|
def processable_message?(message)
|
||||||
# TODO: change from reportable and create a dedicated method for this?
|
# TODO: change from reportable and create a dedicated method for this?
|
||||||
return unless message.reportable?
|
return false unless message.reportable?
|
||||||
return if message.outgoing? && !processable_outgoing_message?(message)
|
return false if message.outgoing? && !processable_outgoing_message?(message)
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -160,8 +160,7 @@
|
|||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"app/**/*.{js,vue}": [
|
"app/**/*.{js,vue}": [
|
||||||
"eslint --fix",
|
"eslint --fix"
|
||||||
"git add"
|
|
||||||
],
|
],
|
||||||
"*.scss": [
|
"*.scss": [
|
||||||
"scss-lint"
|
"scss-lint"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user