Skip to content

Commit

Permalink
Fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Jun 5, 2024
2 parents 0518456 + 7e784d3 commit 2527878
Show file tree
Hide file tree
Showing 30 changed files with 393 additions and 207 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @caiosba @melsawy @DGaffney
* @caiosba @melsawy @DGaffney @jayjay-w
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ gem 'elasticsearch-persistence', '7.1.1'
gem 'paper_trail', '13.0.0'
gem 'graphiql-rails', git: 'https://github.com/meedan/graphiql-rails.git', ref: '8db0eac'
gem 'graphql-formatter'
gem 'nokogiri', '1.16.2'
gem 'nokogiri', '1.16.5'
gem 'puma'
gem 'rack-attack'
gem 'rack-cors', '1.0.6', require: 'rack/cors'
Expand Down
122 changes: 62 additions & 60 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,62 +74,62 @@ GEM
specs:
aasm (5.2.0)
concurrent-ruby (~> 1.0)
actioncable (6.1.7.7)
actionpack (= 6.1.7.7)
activesupport (= 6.1.7.7)
actioncable (6.1.7.8)
actionpack (= 6.1.7.8)
activesupport (= 6.1.7.8)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.7.7)
actionpack (= 6.1.7.7)
activejob (= 6.1.7.7)
activerecord (= 6.1.7.7)
activestorage (= 6.1.7.7)
activesupport (= 6.1.7.7)
actionmailbox (6.1.7.8)
actionpack (= 6.1.7.8)
activejob (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
mail (>= 2.7.1)
actionmailer (6.1.7.7)
actionpack (= 6.1.7.7)
actionview (= 6.1.7.7)
activejob (= 6.1.7.7)
activesupport (= 6.1.7.7)
actionmailer (6.1.7.8)
actionpack (= 6.1.7.8)
actionview (= 6.1.7.8)
activejob (= 6.1.7.8)
activesupport (= 6.1.7.8)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.7.7)
actionview (= 6.1.7.7)
activesupport (= 6.1.7.7)
actionpack (6.1.7.8)
actionview (= 6.1.7.8)
activesupport (= 6.1.7.8)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.7.7)
actionpack (= 6.1.7.7)
activerecord (= 6.1.7.7)
activestorage (= 6.1.7.7)
activesupport (= 6.1.7.7)
actiontext (6.1.7.8)
actionpack (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
nokogiri (>= 1.8.5)
actionview (6.1.7.7)
activesupport (= 6.1.7.7)
actionview (6.1.7.8)
activesupport (= 6.1.7.8)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.7.7)
activesupport (= 6.1.7.7)
activejob (6.1.7.8)
activesupport (= 6.1.7.8)
globalid (>= 0.3.6)
activemodel (6.1.7.7)
activesupport (= 6.1.7.7)
activerecord (6.1.7.7)
activemodel (= 6.1.7.7)
activesupport (= 6.1.7.7)
activemodel (6.1.7.8)
activesupport (= 6.1.7.8)
activerecord (6.1.7.8)
activemodel (= 6.1.7.8)
activesupport (= 6.1.7.8)
activerecord-import (1.1.0)
activerecord (>= 3.2)
activestorage (6.1.7.7)
actionpack (= 6.1.7.7)
activejob (= 6.1.7.7)
activerecord (= 6.1.7.7)
activesupport (= 6.1.7.7)
activestorage (6.1.7.8)
actionpack (= 6.1.7.8)
activejob (= 6.1.7.8)
activerecord (= 6.1.7.8)
activesupport (= 6.1.7.8)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.7.7)
activesupport (6.1.7.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -365,7 +365,7 @@ GEM
ffi-compiler (>= 1.0, < 2.0)
http_parser.rb (0.6.0)
httpclient (2.8.3)
i18n (1.14.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
i18n-generators (1.1.3)
mechanize
Expand Down Expand Up @@ -420,7 +420,7 @@ GEM
mime-types-data (3.2022.0105)
mini_magick (4.10.1)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
mini_portile2 (2.8.7)
minitest (5.19.0)
minitest-hooks (1.5.0)
minitest (> 5.3)
Expand All @@ -447,7 +447,7 @@ GEM
net-protocol
netrc (0.11.0)
nio4r (2.7.0)
nokogiri (1.16.2)
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
numerizer (0.1.1)
Expand Down Expand Up @@ -635,7 +635,7 @@ GEM
pusher-signature (~> 0.1.8)
pusher-signature (0.1.8)
raabro (1.4.0)
racc (1.7.3)
racc (1.8.0)
rack (2.2.8.1)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
Expand All @@ -646,20 +646,20 @@ GEM
rack-test (1.1.0)
rack (>= 1.0, < 3)
railroady (1.6.0)
rails (6.1.7.7)
actioncable (= 6.1.7.7)
actionmailbox (= 6.1.7.7)
actionmailer (= 6.1.7.7)
actionpack (= 6.1.7.7)
actiontext (= 6.1.7.7)
actionview (= 6.1.7.7)
activejob (= 6.1.7.7)
activemodel (= 6.1.7.7)
activerecord (= 6.1.7.7)
activestorage (= 6.1.7.7)
activesupport (= 6.1.7.7)
rails (6.1.7.8)
actioncable (= 6.1.7.8)
actionmailbox (= 6.1.7.8)
actionmailer (= 6.1.7.8)
actionpack (= 6.1.7.8)
actiontext (= 6.1.7.8)
actionview (= 6.1.7.8)
activejob (= 6.1.7.8)
activemodel (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
bundler (>= 1.15.0)
railties (= 6.1.7.7)
railties (= 6.1.7.8)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
Expand All @@ -672,9 +672,9 @@ GEM
rails-graphql-generator (0.1.0)
rails-html-sanitizer (1.4.4)
loofah (~> 2.19, >= 2.19.1)
railties (6.1.7.7)
actionpack (= 6.1.7.7)
activesupport (= 6.1.7.7)
railties (6.1.7.8)
actionpack (= 6.1.7.8)
activesupport (= 6.1.7.8)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down Expand Up @@ -726,7 +726,8 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.2.5)
rexml (3.2.8)
strscan (>= 3.0.9)
rotp (6.3.0)
rqrcode (2.1.1)
chunky_png (~> 1.0)
Expand Down Expand Up @@ -816,6 +817,7 @@ GEM
ssrf_filter (1.0.7)
streamio-ffmpeg (3.0.2)
multi_json (~> 1.8)
strscan (3.1.0)
swagger-docs (0.2.9)
activesupport (>= 3)
rails (>= 3)
Expand Down Expand Up @@ -876,7 +878,7 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.13)
zeitwerk (2.6.15)

PLATFORMS
ruby
Expand Down Expand Up @@ -941,7 +943,7 @@ DEPENDENCIES
minitest-retry
mocha (~> 2.0)
multi_json (= 1.15.0)
nokogiri (= 1.16.2)
nokogiri (= 1.16.5)
omniauth-facebook
omniauth-google-oauth2!
omniauth-slack
Expand Down
14 changes: 8 additions & 6 deletions app/mailers/security_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class SecurityMailer < ApplicationMailer
layout nil

def notify(user, type, activity)
def notify(user_id, type, activity_id)
user = User.find_by_id(user_id)
activity = LoginActivity.find_by_id(activity_id)
address = []
Geocoder.configure(language: I18n.locale)
ip_result = Geocoder.search(activity.ip).first
ip_result = Geocoder.search(activity&.ip)&.first
unless ip_result.blank? || ip_result.data["loc"].blank?
loc_result = Geocoder.search(ip_result.data["loc"]).first
address = [loc_result.city, loc_result.country] unless loc_result.nil?
Expand All @@ -16,16 +18,16 @@ def notify(user, type, activity)
@location = address.compact.join(', ')
@timestamp = activity.created_at
@ip = activity.ip
@platform = @user_agent.os.split.first
@platform = begin @user_agent.os.split.first rescue 'Unknown' end
subject = I18n.t("mail_security.#{type}_subject",
app_name: CheckConfig.get('app_name'), browser: @user_agent.browser, platform: @platform)
mail(to: email, subject: subject)
end

def custom_notification(user, subject)
@user = user
def custom_notification(user_id, subject)
@user = User.find_by_id(user_id)
attachments.inline['signup.png'] = File.read('public/images/signup.png')
mail(to: user.email, subject: subject)
mail(to: @user.email, subject: subject)
end

end
10 changes: 6 additions & 4 deletions app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ def apply_rules_and_actions
def update_elasticsearch_assignment
if ['Annotation', 'Dynamic'].include?(self.assigned_type) && self.assigned.annotation_type == 'verification_status'
pm = self.assigned.annotated
# Update ES
uids = Assignment.where(assigned_type: self.assigned_type, assigned_id: self.assigned_id).map(&:user_id)
data = { 'assigned_user_ids' => uids }
pm.update_elasticsearch_doc(data.keys, data, pm.id)
unless pm.nil?
# Update ES
uids = Assignment.where(assigned_type: self.assigned_type, assigned_id: self.assigned_id).map(&:user_id)
data = { 'assigned_user_ids' => uids }
pm.update_elasticsearch_doc(data.keys, data, pm.id)
end
end
end
end
1 change: 1 addition & 0 deletions app/models/bot/alegre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def self.transcribe_audio(pm)
def self.media_file_url(pm)
# FIXME Ugly hack to get a usable URL in docker-compose development environment.
if pm.is_a?(TemporaryProjectMedia)
print("HELLO")
url = pm.url
else
url = (ENV['RAILS_ENV'] != 'development' ? pm.media.file.file.public_url : "#{CheckConfig.get('storage_endpoint')}/#{CheckConfig.get('storage_bucket')}/#{pm.media.file.file.path}")
Expand Down
11 changes: 8 additions & 3 deletions app/models/concerns/alegre_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,18 @@ def get_required_keys(project_media, field)
}
end

def get_parsed_cached_data_for_key(key)
value = Redis.new(REDIS_CONFIG).get(key)
Hash[YAML.load(value).collect{|kk,vv| [kk.to_i, vv]}] if value
end

def get_cached_data(required_keys)
redis = Redis.new(REDIS_CONFIG)
# For a given project media, we expect a set of keys to be set by the webhook callbacks sent from alegre back to check-api.
# For each callback response (which is set via #process_alegre_callback), we store the value as serialized YAML to persist
# the data such that symbolized keys return as symbols (as opposed to JSON, which loses the distinction). Here, in effect,
# we check to see if all the responses we expect from Alegre have been sent - downstream of this, we check to see if all
# responses are non-empty before proceeding to creating relationships.
Hash[required_keys.collect{|k,v| [k, (Hash[YAML.load(redis.get(v)).collect{|kk,vv| [kk.to_i, vv]}] rescue [])]}]
Hash[required_keys.collect{|k,v| [k, get_parsed_cached_data_for_key(v)]}]
end

def get_similar_items_v2_callback(project_media, field)
Expand Down Expand Up @@ -420,7 +424,7 @@ def relate_project_media_callback(project_media, field=nil)
end

def is_cached_data_not_good(cached_data)
cached_data.values.collect{|x| x.to_a.empty?}.include?(true)
cached_data.values.collect{|x| x.nil?}.include?(true)
end

def get_items_with_similar_media_v2(args={})
Expand All @@ -431,6 +435,7 @@ def get_items_with_similar_media_v2(args={})
type = args[:type]
if ['audio', 'image', 'video'].include?(type)
if project_media.nil?
print("hello")
project_media = TemporaryProjectMedia.new
project_media.url = media_url
project_media.id = Digest::MD5.hexdigest(project_media.url).to_i(16)
Expand Down
9 changes: 7 additions & 2 deletions app/models/concerns/smooch_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,21 @@ def save_message_later(message, app_id, request_type = 'default_requests', annot
queue = RequestStore.store[:smooch_bot_queue].to_s
queue = queue.blank? ? 'smooch_priority' : (mapping[queue] || 'smooch_priority')
type = (message['type'] == 'text' && !message['text'][/https?:\/\/[^\s]+/, 0].blank?) ? 'link' : message['type']
SmoochWorker.set(queue: queue).perform_in(1.second + interval.seconds, message.to_json, type, app_id, request_type, YAML.dump(annotated))
associated_id = annotated&.id
associated_class = annotated.class.name
SmoochWorker.set(queue: queue).perform_in(1.second + interval.seconds, message.to_json, type, app_id, request_type, associated_id, associated_class)
end

def default_archived_flag
team_id = self.config['team_id'].to_i
Bot::Alegre.team_has_alegre_bot_installed?(team_id) ? CheckArchivedFlags::FlagCodes::PENDING_SIMILARITY_ANALYSIS : CheckArchivedFlags::FlagCodes::NONE
end

def save_message(message_json, app_id, author = nil, request_type = 'default_requests', associated_obj = nil)
def save_message(message_json, app_id, author = nil, request_type = 'default_requests', associated_id = nil, associated_class = nil)
message = JSON.parse(message_json)
return if TiplineRequest.where(smooch_message_id: message['_id']).exists?
associated_obj = nil
associated_obj = associated_class.constantize.where(id: associated_id).last unless associated_id.nil?
self.get_installation(self.installation_setting_id_keys, app_id)
Team.current = Team.find self.config['team_id'].to_i
ApplicationRecord.transaction do
Expand Down
6 changes: 3 additions & 3 deletions app/models/login_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def send_successfull_login_notification(user)
activities = user.login_activities.where(success: true).last(2)
ip = activities.map(&:ip).uniq
if ip.count > 1
SecurityMailer.delay.notify(user, 'ip', self)
SecurityMailer.delay.notify(user.id, 'ip', self.id)
else
user_agent = activities.map(&:user_agent).uniq
SecurityMailer.delay.notify(user, 'device', self) if user_agent.count > 1
SecurityMailer.delay.notify(user.id, 'device', self.id) if user_agent.count > 1
end
end

Expand All @@ -55,7 +55,7 @@ def send_failed_login_notification(user)
failed_attempts = LoginActivity.where('identity = ? AND success = ? AND created_at > ?', self.identity, false, last_notification).count
end
if failed_attempts >= CheckConfig.get('failed_attempts', 4).to_i
SecurityMailer.delay.notify(user, 'failed', self)
SecurityMailer.delay.notify(user.id, 'failed', self.id)
user.set_failed_notifications_time = self.created_at
user.skip_check_ability = true
user.save!
Expand Down
Loading

0 comments on commit 2527878

Please sign in to comment.