Skip to content

Commit

Permalink
Merge pull request #1933 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-05-31
  • Loading branch information
Cory McDonald authored May 31, 2019
2 parents 8396777 + 70db5ce commit 2b1837e
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ gem "rails", "~> 5.2.3"
gem "recaptcha", "~> 3.3", require: "recaptcha/rails"

# Cache with Redis
gem 'redis', '~> 4.0.1'
gem 'redis', '~> 4.1.2'

# Generate QR codes for TOTP 2fa
gem "rqrcode", "~> 0.10"
Expand Down
44 changes: 22 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ GEM
ast (2.4.0)
attr_encrypted (3.1.0)
encryptor (~> 3.0.0)
autoprefixer-rails (9.5.1)
autoprefixer-rails (9.5.1.1)
execjs
aws-eventstream (1.0.3)
aws-partitions (1.158.0)
aws-sdk-core (3.49.0)
aws-partitions (1.170.0)
aws-sdk-core (3.54.1)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.18.0)
aws-sdk-core (~> 3, >= 3.48.2)
aws-sdk-kms (1.21.0)
aws-sdk-core (~> 3, >= 3.53.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.36.1)
aws-sdk-core (~> 3, >= 3.48.2)
aws-sdk-s3 (1.41.0)
aws-sdk-core (~> 3, >= 3.53.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.1.0)
aws-eventstream (~> 1.0, >= 1.0.2)
bcrypt (3.1.12)
Expand All @@ -106,7 +106,7 @@ GEM
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0)
brakeman (4.5.0)
brakeman (4.5.1)
browser (2.5.3)
builder (3.2.3)
bundler-audit (0.6.1)
Expand Down Expand Up @@ -162,15 +162,15 @@ GEM
execjs (2.7.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
ffi (1.10.0)
ffi (1.11.1)
font-awesome-rails (4.7.0.5)
railties (>= 3.2, < 6.1)
fugit (1.2.1)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
hashdiff (0.3.9)
hashdiff (0.4.0)
hashie (3.6.0)
highline (2.0.2)
htmlentities (4.3.4)
Expand All @@ -196,11 +196,11 @@ GEM
jmespath (1.4.0)
json (2.2.0)
jsonapi-renderer (0.2.0)
jwt (2.1.0)
jwt (2.2.1)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
lograge (0.11.0)
lograge (0.11.1)
actionpack (>= 4)
activesupport (>= 4)
railties (>= 4)
Expand Down Expand Up @@ -243,7 +243,7 @@ GEM
msgpack (1.2.10)
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
multipart-post (2.1.1)
mustermann (1.0.3)
netrc (0.11.0)
newrelic_rpm (3.18.1.330)
Expand Down Expand Up @@ -357,7 +357,7 @@ GEM
ffi (~> 1.0)
recaptcha (3.4.0)
json
redis (4.0.3)
redis (4.1.2)
request_store (1.4.1)
rack (>= 1.4)
responders (2.4.1)
Expand All @@ -383,9 +383,9 @@ GEM
rubocop-rspec (~> 1.30.0)
rubocop-rspec (1.30.0)
rubocop (>= 0.58.0)
ruby-progressbar (1.10.0)
ruby-progressbar (1.10.1)
ruby_http_client (3.3.0)
rubyzip (1.2.2)
rubyzip (1.2.3)
rufus-scheduler (3.6.0)
fugit (~> 1.1, >= 1.1.6)
safe_yaml (1.0.5)
Expand All @@ -409,7 +409,7 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (3.142.0)
selenium-webdriver (3.142.3)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
sendgrid-ruby (5.3.0)
Expand Down Expand Up @@ -470,8 +470,8 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
unicode-display_width (1.5.0)
vcr (4.0.0)
unicode-display_width (1.6.0)
vcr (5.0.0)
warden (1.2.8)
rack (>= 2.0.6)
web-console (3.7.0)
Expand All @@ -483,7 +483,7 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
webpacker (4.0.2)
webpacker (4.0.6)
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
Expand Down Expand Up @@ -555,7 +555,7 @@ DEPENDENCIES
rails-controller-testing
railties (~> 5.2.3)
recaptcha (~> 3.3)
redis (~> 4.0.1)
redis (~> 4.1.2)
rotp (~> 3.3)
rqrcode (~> 0.10)
rubocop-airbnb
Expand Down
21 changes: 19 additions & 2 deletions app/jobs/cache_browser_channels_json_job.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
class CacheBrowserChannelsJsonJob < ApplicationJob
queue_as :heavy

MAX_RETRY = 10

def perform
channels_json = JsonBuilders::ChannelsJsonBuilder.new.build
result = Rails.cache.write('browser_channels_json', channels_json)
Rails.logger.info("CacheBrowserChannelsJsonJob updated the cached browser channels json. Result: #{result}")
retry_count = 0
result = nil

loop do
result = Rails.cache.write('browser_channels_json', channels_json)
break if result || retry_count > MAX_RETRY

retry_count += 1
Rails.logger.info("CacheBrowserChannelsJsonJob could not write to Redis result: #{result}. Retrying: #{retry_count}/#{MAX_RETRY}")
end

if result
Rails.logger.info("CacheBrowserChannelsJsonJob updated the cached browser channels json.")
else
SlackMessenger.new(message: "🚨 CacheBrowserChannelsJsonJob could not update the channels JSON. @publishers-team 🚨")
Rails.logger.info("CacheBrowserChannelsJsonJob could not update the channels JSON.")
end
end
end
25 changes: 25 additions & 0 deletions app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Channel < ApplicationRecord
validate :verified_duplicate_channels_must_be_contested, if: -> { verified? }

after_save :register_channel_for_promo, if: :should_register_channel_for_promo
after_save :notify_slack, if: :saved_change_to_verified?

before_save :clear_verified_at_if_necessary

before_destroy :preserve_contested_by_channels
Expand Down Expand Up @@ -328,6 +330,29 @@ def register_channel_for_promo
RegisterChannelForPromoJob.new.perform(channel: self)
end

def notify_slack
return unless verified?
emoji =
case details_type
when "SiteChannelDetails"
"🌐"
when "TwitchChannelDetails"
"👾"
when "YoutubeChannelDetails"
"📺"
when "VimeoChannelDetails"
"🎥"
when "TwitterChannelDetails"
"🐦"
else
""
end

SlackMessenger.new(
message: "#{emoji} *#{details.publication_title}* verified by owner #{publisher.owner_identifier}; id=#{details.channel_identifier}; url=#{details.url}"
).perform
end

def site_channel_details_brave_publisher_id_unique_for_publisher
duplicate_unverified_channels = publisher.channels.visible_site_channels.
where(site_channel_details: { brave_publisher_id: details.brave_publisher_id }).
Expand Down
23 changes: 0 additions & 23 deletions app/services/publisher_unverified_calculator.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/services/site_channel_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def contested_channel(brave_publisher_id)

def verified_channel_post_verify
MailerServices::VerificationDoneEmailer.new(verified_channel: channel).perform
SlackMessenger.new(message: "*#{channel.publication_title}* verified by owner #{channel.publisher.owner_identifier}; id=#{channel.details.channel_identifier}").perform
end

def verify_site_channel
Expand Down
4 changes: 2 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
config.cache_store = :redis_cache_store, {
url: Rails.application.secrets[:redis_url],
connect_timeout: 30, # Defaults to 20 seconds
read_timeout: 10, # Defaults to 1 second
write_timeout: 60, # Defaults to 1 second
read_timeout: 5, # Defaults to 1 second
write_timeout: 10, # Defaults to 1 second

error_handler: -> (method:, returning:, exception:) {
# Report errors to Sentry as warnings
Expand Down
4 changes: 2 additions & 2 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
config.cache_store = :redis_cache_store, {
url: Rails.application.secrets[:redis_url],
connect_timeout: 30, # Defaults to 20 seconds
read_timeout: 10, # Defaults to 1 second
write_timeout: 60, # Defaults to 1 second
read_timeout: 5, # Defaults to 1 second
write_timeout: 10, # Defaults to 1 second

error_handler: -> (method:, returning:, exception:) {
# Report errors to Sentry as warnings
Expand Down
15 changes: 0 additions & 15 deletions lib/tasks/publisher_inventory.rake

This file was deleted.

59 changes: 0 additions & 59 deletions test/services/publisher_unverified_calculator_test.rb

This file was deleted.

0 comments on commit 2b1837e

Please sign in to comment.