diff --git a/.rubocop.yml b/.rubocop.yml index 248a11eed..975f045f6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,8 @@ inherit_from: .rubocop_todo.yml Metrics/LineLength: Max: 150 +Metrics/ClassLength: + Max: 125 RSpec/ExampleLength: Max: 15 Documentation: diff --git a/Gemfile b/Gemfile index d0e53f197..fd1d783e4 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,9 @@ gem 'valid_email2' gem 'uglifier' ##-- for active storage --## +gem 'aws-sdk-s3', require: false +gem 'azure-storage', require: false +gem 'google-cloud-storage', require: false gem 'mini_magick' ##-- gems for database --# @@ -68,9 +71,7 @@ gem 'haikunator' gem 'brakeman' gem 'sentry-raven' -##-- TODO: move these gems to appropriate groups --## -# remove this gem in favor of active storage - github #158 -gem 'carrierwave-aws' +##-- background job processing --## gem 'sidekiq' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index a7bb9d402..cba93566b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,7 +68,7 @@ GEM ast (2.4.0) attr_extras (6.2.1) aws-eventstream (1.0.3) - aws-partitions (1.259.0) + aws-partitions (1.262.0) aws-sdk-core (3.86.0) aws-eventstream (~> 1.0, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) @@ -87,6 +87,15 @@ GEM descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) + azure-core (0.1.15) + faraday (~> 0.9) + faraday_middleware (~> 0.10) + nokogiri (~> 1.6) + azure-storage (0.15.0.preview) + azure-core (~> 0.1) + faraday (~> 0.9) + faraday_middleware (~> 0.10) + nokogiri (~> 1.6, >= 1.6.8) bcrypt (3.1.13) bindex (0.8.1) bootsnap (1.4.5) @@ -104,16 +113,6 @@ GEM bundler (>= 1.2.0, < 3) thor (~> 0.18) byebug (11.0.1) - carrierwave (2.0.2) - activemodel (>= 5.0.0) - activesupport (>= 5.0.0) - addressable (~> 2.6) - image_processing (~> 1.1) - mimemagic (>= 0.3.0) - mini_mime (>= 0.1.3) - carrierwave-aws (1.4.0) - aws-sdk-s3 (~> 1.0) - carrierwave (>= 0.7, < 2.1) chargebee (2.7.1) json_pure (~> 2.1) rest-client (>= 1.8, < 3.0) @@ -123,6 +122,8 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) + declarative (0.0.10) + declarative-option (0.1.0) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) devise (4.7.1) @@ -136,6 +137,7 @@ GEM devise (> 3.5.2, < 5) rails (>= 4.2.0, < 6.1) diff-lcs (1.3) + digest-crc (0.4.1) docile (1.3.2) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) @@ -158,10 +160,38 @@ GEM i18n (>= 1.6, < 1.8) faraday (0.17.1) multipart-post (>= 1.2, < 3) + faraday_middleware (0.13.1) + faraday (>= 0.7.4, < 1.0) ffi (1.11.3) foreman (0.86.0) globalid (0.4.2) activesupport (>= 4.2.0) + google-api-client (0.36.4) + addressable (~> 2.5, >= 2.5.1) + googleauth (~> 0.9) + httpclient (>= 2.8.1, < 3.0) + mini_mime (~> 1.0) + representable (~> 3.0) + retriable (>= 2.0, < 4.0) + signet (~> 0.12) + google-cloud-core (1.4.1) + google-cloud-env (~> 1.0) + google-cloud-env (1.3.0) + faraday (~> 0.11) + google-cloud-storage (1.25.1) + addressable (~> 2.5) + digest-crc (~> 0.4) + google-api-client (~> 0.33) + google-cloud-core (~> 1.2) + googleauth (~> 0.9) + mini_mime (~> 1.0) + googleauth (0.10.0) + faraday (~> 0.12) + jwt (>= 1.4, < 3.0) + memoist (~> 0.16) + multi_json (~> 1.11) + os (>= 0.9, < 2.0) + signet (~> 0.12) haikunator (1.1.0) hashie (4.0.0) http (3.3.0) @@ -177,12 +207,10 @@ GEM httparty (0.17.3) mime-types (~> 3.0) multi_xml (>= 0.5.2) + httpclient (2.8.3) i18n (1.7.0) concurrent-ruby (~> 1.0) ice_nine (0.11.2) - image_processing (1.10.0) - mini_magick (>= 4.9.5, < 5) - ruby-vips (>= 2.0.13, < 3) inflecto (0.0.2) jaro_winkler (1.5.4) jbuilder (2.9.1) @@ -221,6 +249,7 @@ GEM mini_mime (>= 0.1.1) marcel (0.3.3) mimemagic (~> 0.3.2) + memoist (0.16.2) memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) method_source (0.9.2) @@ -234,6 +263,7 @@ GEM minitest (5.13.0) mock_redis (0.22.0) msgpack (1.3.1) + multi_json (1.14.1) multi_xml (0.6.0) multipart-post (2.1.1) naught (1.1.0) @@ -243,6 +273,7 @@ GEM nokogiri (1.10.7) mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) + os (1.0.1) parallel (1.19.1) parser (2.6.5.0) ast (~> 2.4.0) @@ -307,6 +338,10 @@ GEM redis-store (>= 1.6, < 2) redis-store (1.8.1) redis (>= 4, < 5) + representable (3.0.4) + declarative (< 0.1.0) + declarative-option (< 0.2.0) + uber (< 0.2.0) responders (3.0.0) actionpack (>= 5.0) railties (>= 5.0) @@ -315,6 +350,7 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) + retriable (3.1.2) rspec-core (3.9.0) rspec-support (~> 3.9.0) rspec-expectations (3.9.0) @@ -347,8 +383,6 @@ GEM rubocop-rspec (1.37.1) rubocop (>= 0.68.1) ruby-progressbar (1.10.1) - ruby-vips (2.0.16) - ffi (~> 1.9) seed_dump (3.3.1) activerecord (>= 4) activesupport (>= 4) @@ -361,6 +395,11 @@ GEM rack (>= 2.0.0) rack-protection (>= 2.0.0) redis (>= 4.1.0) + signet (0.12.0) + addressable (~> 2.3) + faraday (~> 0.9) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) simple_oauth (0.3.1) simplecov (0.17.1) docile (~> 1.1) @@ -402,6 +441,7 @@ GEM thread_safe (~> 0.1) tzinfo-data (1.2019.3) tzinfo (>= 1.0.0) + uber (0.1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) @@ -442,13 +482,14 @@ DEPENDENCIES acts-as-taggable-on annotate attr_extras + aws-sdk-s3 + azure-storage bootsnap brakeman browser bullet bundle-audit byebug - carrierwave-aws chargebee devise devise_token_auth @@ -457,6 +498,7 @@ DEPENDENCIES factory_bot_rails faker foreman + google-cloud-storage haikunator hashie jbuilder diff --git a/app/bot/bot_configurator.rb b/app/bot/bot_configurator.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/builders/messages/message_builder.rb b/app/builders/messages/message_builder.rb index 67d3272ba..6611cfe5b 100644 --- a/app/builders/messages/message_builder.rb +++ b/app/builders/messages/message_builder.rb @@ -36,19 +36,26 @@ module Messages def build_contact return if contact.present? - @contact = Contact.create!(contact_params) + @contact = Contact.create!(contact_params.except(:remote_avatar_url)) + avatar_resource = LocalResource.new(contact_params[:remote_avatar_url]) + @contact.avatar.attach(io: avatar_resource.file, filename: avatar_resource.tmp_filename, content_type: avatar_resource.encoding) + ContactInbox.create(contact: contact, inbox: @inbox, source_id: @sender_id) end def build_message - @message = conversation.messages.new(message_params) + @message = conversation.messages.create!(message_params) (response.attachments || []).each do |attachment| - @message.build_attachment(attachment_params(attachment)) + attachment_obj = @message.build_attachment(attachment_params(attachment).except(:remote_file_url)) + attachment_obj.save! + attach_file(attachment_obj, attachment_params(attachment)[:remote_file_url]) if attachment_params(attachment)[:remote_file_url] end - @message.save! end - def build_attachment; end + def attach_file(attachment, file_url) + file_resource = LocalResource.new(file_url) + attachment.file.attach(io: file_resource.file, filename: file_resource.tmp_filename, content_type: file_resource.encoding) + end def conversation @conversation ||= Conversation.find_by(conversation_params) || Conversation.create!(conversation_params) @@ -123,7 +130,7 @@ module Messages { name: "#{result['first_name'] || 'John'} #{result['last_name'] || 'Doe'}", account_id: @inbox.account_id, - remote_avatar_url: result['profile_pic'] || nil + remote_avatar_url: result['profile_pic'] || '' } end end diff --git a/app/controllers/api/v1/callbacks_controller.rb b/app/controllers/api/v1/callbacks_controller.rb index 6731c7a20..cc6b00958 100644 --- a/app/controllers/api/v1/callbacks_controller.rb +++ b/app/controllers/api/v1/callbacks_controller.rb @@ -12,8 +12,9 @@ class Api::V1::CallbacksController < ApplicationController inbox_name = params[:inbox_name] facebook_channel = current_account.facebook_pages.create!( name: page_name, page_id: page_id, user_access_token: user_access_token, - page_access_token: page_access_token, remote_avatar_url: set_avatar(page_id) + page_access_token: page_access_token ) + set_avatar(facebook_channel, page_id) inbox = current_account.inboxes.create!(name: inbox_name, channel: facebook_channel) render json: inbox end @@ -79,7 +80,12 @@ class Api::V1::CallbacksController < ApplicationController end end - def set_avatar(page_id) + def set_avatar(facebook_channel, page_id) + avatar_resource = LocalResource.new(get_avatar_url(page_id)) + facebook_channel.avatar.attach(io: avatar_resource.file, filename: avatar_resource.tmp_filename, content_type: avatar_resource.encoding) + end + + def get_avatar_url(page_id) begin url = 'http://graph.facebook.com/' << page_id << '/picture?type=large' uri = URI.parse(url) diff --git a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue index 6c33e96c6..93a8feb32 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue @@ -3,7 +3,7 @@