Skip to content

Commit

Permalink
Merge branch 'develop' into chore/update-rails
Browse files Browse the repository at this point in the history
  • Loading branch information
sojan-official authored Apr 19, 2023
2 parents ecd435c + 9c0259d commit 24e521a
Show file tree
Hide file tree
Showing 717 changed files with 19,357 additions and 3,352 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.bundle
.env
.env.*
.git
.gitignore
docker-compose.*
docker/Dockerfile
docker/dockerfiles
Expand Down
5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ AWS_REGION=
RAILS_LOG_TO_STDOUT=true
LOG_LEVEL=info
LOG_SIZE=500
# Configure this environment variable if you want to use lograge instead of rails logger
#LOGRAGE_ENABLED=true

### This environment variables are only required if you are setting up social media channels

Expand Down Expand Up @@ -159,9 +161,6 @@ ANDROID_SHA256_CERT_FINGERPRINT=AC:73:8E:DE:EB:56:EA:CC:10:87:02:A7:65:37:7B:38:
# for mobile apps
# FCM_SERVER_KEY=

## Bot Customizations
USE_INBOX_AVATAR_FOR_BOT=true

### APM and Error Monitoring configurations
## Elastic APM
## https://www.elastic.co/guide/en/apm/agent/ruby/current/getting-started-rails.html
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ test/cypress/videos/*
/config/master.key
/config/*.enc

.vscode/settings.json
#ignore files under .vscode directory
.vscode

# yalc for local testing
.yalc
yalc.lock
yalc.lock
34 changes: 22 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ gem 'line-bot-api'
gem 'twilio-ruby', '~> 5.66'
# twitty will handle subscription of twitter account events
# gem 'twitty', git: 'https://github.com/chatwoot/twitty'
gem 'twitty'
gem 'twitty', '~> 0.1.5'
# facebook client
gem 'koala'
# slack client
Expand Down Expand Up @@ -149,7 +149,23 @@ gem 'net-imap', require: false
gem 'net-pop', require: false
gem 'net-smtp', require: false

group :production, :staging do
# Include logrange conditionally in intializer using env variable
gem 'lograge', '~> 0.12.0', require: false

# worked with microsoft refresh token
gem 'omniauth-oauth2'

gem 'audited', '~> 5.2'

# need for google auth
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'omniauth-rails_csrf_protection', '~> 1.0'

### Gems required only in specific deployment environments ###
##############################################################

group :production do
# we dont want request timing out in development while using byebug
gem 'rack-timeout'
end
Expand All @@ -165,6 +181,10 @@ group :development do

# When we want to squash migrations
gem 'squasher'

# profiling
gem 'rack-mini-profiler', require: false
gem 'stackprof'
end

group :test do
Expand Down Expand Up @@ -202,13 +222,3 @@ group :development, :test do
gem 'spring'
gem 'spring-watcher-listen'
end

# worked with microsoft refresh token
gem 'omniauth-oauth2'

gem 'audited', '~> 5.2'

# need for google auth
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'omniauth-rails_csrf_protection'
43 changes: 29 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ GEM
byebug (11.1.3)
climate_control (1.2.0)
coderay (1.1.3)
commonmarker (0.23.8)
commonmarker (0.23.9)
concurrent-ruby (1.2.2)
connection_pool (2.3.0)
crack (0.4.5)
Expand Down Expand Up @@ -423,6 +423,11 @@ GEM
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
lograge (0.12.0)
actionpack (>= 4)
activesupport (>= 4)
railties (>= 4)
request_store (~> 1.0)
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -465,14 +470,16 @@ GEM
sidekiq
newrelic_rpm (8.16.0)
nio4r (2.5.8)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
oauth (1.1.0)
oauth-tty (~> 1.0, >= 1.0.1)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
oauth-tty (1.0.5)
version_gem (~> 1.1, >= 1.1.1)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.14.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.14.3-x86_64-linux)
racc (~> 1.4)
oauth (0.5.10)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
Expand Down Expand Up @@ -523,6 +530,8 @@ GEM
rack (>= 1.0, < 3)
rack-cors (2.0.1)
rack (>= 2.0.0)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-protection (3.0.5)
rack
rack-proxy (0.7.6)
Expand Down Expand Up @@ -572,9 +581,11 @@ GEM
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
request_store (1.5.1)
rack (>= 1.4)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand Down Expand Up @@ -699,7 +710,8 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
squasher (0.7.2)
squasher (0.6.2)
stackprof (0.2.24)
statsd-ruby (1.5.0)
stripe (8.3.0)
telephone_number (1.4.20)
Expand Down Expand Up @@ -829,6 +841,7 @@ DEPENDENCIES
line-bot-api
liquid
listen
lograge (~> 0.12.0)
maxminddb
mock_redis
net-imap
Expand All @@ -848,6 +861,7 @@ DEPENDENCIES
pundit
rack-attack
rack-cors
rack-mini-profiler
rack-timeout
rails (~> 7)
redis
Expand All @@ -873,12 +887,13 @@ DEPENDENCIES
spring
spring-watcher-listen
squasher
stackprof
stripe
telephone_number
test-prof
time_diff
twilio-ruby (~> 5.66)
twitty
twitty (~> 0.1.5)
tzinfo-data
uglifier
valid_email2
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release: POSTGRES_STATEMENT_TIMEOUT=600s bundle exec rails db:chatwoot_prepare
release: POSTGRES_STATEMENT_TIMEOUT=600s bundle exec rails db:chatwoot_prepare && echo $SOURCE_VERSION > .git_sha
web: bundle exec rails ip_lookup:setup && bin/rails server -p $PORT -e $RAILS_ENV
worker: bundle exec rails ip_lookup:setup && bundle exec sidekiq -C config/sidekiq.yml
4 changes: 2 additions & 2 deletions app/builders/messages/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def process_emails
return unless @conversation.inbox&.inbox_type == 'Email'

cc_emails = []
cc_emails = @params[:cc_emails].split(',') if @params[:cc_emails].present?
cc_emails = @params[:cc_emails].gsub(/\s+/, '').split(',') if @params[:cc_emails].present?

bcc_emails = []
bcc_emails = @params[:bcc_emails].split(',') if @params[:bcc_emails].present?
bcc_emails = @params[:bcc_emails].gsub(/\s+/, '').split(',') if @params[:bcc_emails].present?

all_email_addresses = cc_emails + bcc_emails
validate_email_addresses(all_email_addresses)
Expand Down
14 changes: 12 additions & 2 deletions app/controllers/api/v1/accounts/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController
before_action :portal
before_action :check_authorization
before_action :fetch_article, except: [:index, :create, :attach_file]
before_action :fetch_article, except: [:index, :create, :attach_file, :reorder]
before_action :set_current_page, only: [:index]

def index
@portal_articles = @portal.articles
@all_articles = @portal_articles.search(list_params)
@articles_count = @all_articles.count
@articles = @all_articles.order_by_updated_at.page(@current_page)

@articles = if list_params[:category_slug].present?
@all_articles.order_by_position.page(@current_page).per(50)
else
@all_articles.order_by_updated_at.page(@current_page)
end
end

def create
Expand Down Expand Up @@ -43,6 +48,11 @@ def attach_file
render json: { file_url: url_for(file_blob) }
end

def reorder
Article.update_positions(params[:positions_hash])
head :ok
end

private

def fetch_article
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/api/v1/accounts/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ def set_current_page
end

def fetch_contacts_with_conversation_count(contacts)
contacts_with_conversation_count = filtrate(contacts).left_outer_joins(:conversations)
.select('contacts.*, COUNT(conversations.id) as conversations_count')
.group('contacts.id')
.includes([{ avatar_attachment: [:blob] }])
.page(@current_page).per(RESULTS_PER_PAGE)
conversation_count_sub_query = 'SELECT COUNT(*) FROM "conversations" WHERE "conversations"."contact_id" = "contacts"."id"'
contacts_with_conversation_count = filtrate(contacts)
.select("contacts.*, (#{conversation_count_sub_query}) as conversations_count")
.group('contacts.id')
.includes([{ avatar_attachment: [:blob] }])
.page(@current_page).per(RESULTS_PER_PAGE)

return contacts_with_conversation_count.includes([{ contact_inboxes: [:inbox] }]) if @include_contact_inboxes

Expand Down
13 changes: 13 additions & 0 deletions app/controllers/api/v1/accounts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Api::V1::AccountsController < Api::BaseController
include AuthHelper
include CacheKeysHelper

skip_before_action :authenticate_user!, :set_current_user, :handle_with_exception,
only: [:create], raise: false
Expand Down Expand Up @@ -30,6 +31,10 @@ def create
end
end

def cache_keys
render json: { cache_keys: get_cache_keys }, status: :ok
end

def show
@latest_chatwoot_version = ::Redis::Alfred.get(::Redis::Alfred::LATEST_CHATWOOT_VERSION)
render 'api/v1/accounts/show', format: :json
Expand All @@ -47,6 +52,14 @@ def update_active_at

private

def get_cache_keys
{
label: fetch_value_for_key(params[:id], Label.name.underscore),
inbox: fetch_value_for_key(params[:id], Inbox.name.underscore),
team: fetch_value_for_key(params[:id], Team.name.underscore)
}
end

def fetch_account
@account = current_user.accounts.find(params[:id])
@current_account_user = @account.account_users.find_by(user_id: current_user.id)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/api/v1/widget/conversations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ def toggle_status
head :ok
end

def set_custom_attributes
conversation.update!(custom_attributes: permitted_params[:custom_attributes])
end

def destroy_custom_attributes
conversation.custom_attributes = conversation.custom_attributes.excluding(params[:custom_attribute])
conversation.save!
render json: conversation
end

private

def trigger_typing_event(event)
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/api/v2/accounts/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Api::V2::Accounts::ReportsController < Api::V1::Accounts::BaseController
include Api::V2::Accounts::ReportsHelper
include Api::V2::Accounts::HeatmapHelper

before_action :check_authorization

def index
Expand Down Expand Up @@ -34,6 +36,9 @@ def teams

def conversation_traffic
@report_data = generate_conversations_heatmap_report
timezone_offset = (params[:timezone_offset] || 0).to_f
@timezone = ActiveSupport::TimeZone[timezone_offset]

generate_csv('conversation_traffic_reports', 'api/v2/accounts/reports/conversation_traffic')
end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def app_config
FB_APP_ID: GlobalConfigService.load('FB_APP_ID', ''),
FACEBOOK_API_VERSION: 'v14.0',
IS_ENTERPRISE: ChatwootApp.enterprise?,
AZURE_APP_ID: ENV.fetch('AZURE_APP_ID', '')
AZURE_APP_ID: ENV.fetch('AZURE_APP_ID', ''),
GIT_SHA: GIT_HASH
}
end
end
7 changes: 7 additions & 0 deletions app/controllers/super_admin/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ def seed
Internal::SeedAccountJob.perform_later(requested_resource)
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account seeding triggered')
end

def destroy
account = Account.find(params[:id])

DeleteObjectJob.perform_later(account) if account.present?
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account deletion is in progress.')
end
end
12 changes: 12 additions & 0 deletions app/controllers/super_admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
class SuperAdmin::UsersController < SuperAdmin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
# For example, you may want to send an email after a foo is updated.

def create
resource = resource_class.new(resource_params)
authorize_resource(resource)

if resource.save
redirect_to super_admin_user_path(resource), notice: translate_with_resource('create.success')
else
notice = resource.errors.full_messages.first
redirect_to new_super_admin_user_path, notice: notice
end
end
#
# def update
# super
Expand Down
Loading

0 comments on commit 24e521a

Please sign in to comment.