From 48b54944f22c20a4e6bdcffc0e56cd226a76c851 Mon Sep 17 00:00:00 2001 From: Cory McDonald Date: Wed, 19 Jun 2019 13:38:28 -0500 Subject: [PATCH 1/4] Updated Terms of Service (#1978) * Email TOS * Fix travis yet again * Create an order --- .travis.yml | 2 +- app/mailers/publisher_mailer.rb | 7 ++ .../publisher_mailer/update_to_tos.html.slim | 3 + config/locales/en.yml | 67 +++++++++++++++++++ lib/tasks/email_tos_update.rake | 19 ++++++ .../previews/publisher_mailer_preview.rb | 4 ++ 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 app/views/publisher_mailer/update_to_tos.html.slim create mode 100644 lib/tasks/email_tos_update.rake diff --git a/.travis.yml b/.travis.yml index a1b05c9242..5f6bcdf1fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: - yarn install - yarn audit - yarn lint - - bin/rails test + - bundle exec rails test - yarn test - bundle exec brakeman - bundle exec rubocop diff --git a/app/mailers/publisher_mailer.rb b/app/mailers/publisher_mailer.rb index df853967ac..8b7027dbf8 100644 --- a/app/mailers/publisher_mailer.rb +++ b/app/mailers/publisher_mailer.rb @@ -341,6 +341,13 @@ def email_user_on_hold(publisher) ) end + def update_to_tos(publisher) + @publisher = publisher + mail( + to: @publisher.email || @publisher.pending_email, + subject: default_i18n_subject + ) + end private diff --git a/app/views/publisher_mailer/update_to_tos.html.slim b/app/views/publisher_mailer/update_to_tos.html.slim new file mode 100644 index 0000000000..110b79fcc6 --- /dev/null +++ b/app/views/publisher_mailer/update_to_tos.html.slim @@ -0,0 +1,3 @@ +p.salutation= t "publisher_mailer.shared.salutation", name: @publisher.name + +p== t(".body", link: ENV["CALENDLY_LINK"], month: Date.today.strftime("%B")) diff --git a/config/locales/en.yml b/config/locales/en.yml index 0132b6e212..e553911486 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -274,6 +274,73 @@ en: Thank you.

The Brave Rewards | Creator team + update_to_tos: + subject: Updates to the Brave Rewards Terms of Service for Creators + body: > +

+ We know it’s not glamorous or exciting, but we’ve made some changes to the Brave Rewards Terms of Service. We'd love for you to take a look so that you can see the whole updated document. But just to make things a little easier, here’s a quick summary of all the recent changes. +

+ In June: + + + + + + + + + + + + + +
+ We made it clear we would not send BAT belonging to Brave (including UGP grants and referral payments) to anyone who encourages or engages in violence. +
+ We explained how UGP grants work in the terms for publishers, where it was previously only in the user terms. +
+ We noted that we are the judge of what is and isn’t the prohibited conduct described in §8. +
+
+ In April: + + + + + +
+ We launched Brave Ads! Now there are terms for advertisers, and the terms for publishers reflects that. +
+
+ In March: + + + + + + + + + + + + + +
+ We made it possible for people aged 16 and up to use Brave Rewards with a parent’s permission. +
+ We rewrote §4, which explains how contributions work. Contributions essentially didn’t change, we just described them better. +
+ We also made some formatting changes which you might not notice, but we think makes the whole thing easier to read. +
+ +

This is only a summary. It doesn’t describe everything that changed. You should read the actual real policy.

+ +

+ Thanks for being a Brave Rewards Creator, +
+ The Brave Rewards Team +

login_email: subject: Log in to Brave Rewards body_html: | diff --git a/lib/tasks/email_tos_update.rake b/lib/tasks/email_tos_update.rake new file mode 100644 index 0000000000..63b192c858 --- /dev/null +++ b/lib/tasks/email_tos_update.rake @@ -0,0 +1,19 @@ +namespace :email do + task :tos_update => :environment do + puts "Emailing #{Publisher.count} users" + + Publisher.order(:id).find_each.with_index do |user, index| + begin + PublisherMailer.update_to_tos(user).deliver_now + print '.' if index % 1000 == 0 + rescue + # Let's rescue all exceptions + print "X" + Rails.logger.info "[#{Time.now.iso8601}] Could not send terms and conditions for [#{user.id}]" + end + end + + puts + puts "✨ Done" + end +end diff --git a/test/mailers/previews/publisher_mailer_preview.rb b/test/mailers/previews/publisher_mailer_preview.rb index 928dadbb15..302866d477 100644 --- a/test/mailers/previews/publisher_mailer_preview.rb +++ b/test/mailers/previews/publisher_mailer_preview.rb @@ -87,4 +87,8 @@ def tagged_in_note def email_user_on_hold PublisherMailer.email_user_on_hold(Publisher.first) end + + def update_to_tos + PublisherMailer.update_to_tos(Publisher.first) + end end From fdce4797bd68500f28a06c1c0d12e777d69a2b4b Mon Sep 17 00:00:00 2001 From: Cory McDonald Date: Wed, 19 Jun 2019 14:08:20 -0500 Subject: [PATCH 2/4] Add in some optional parameters (#1979) --- lib/tasks/email_tos_update.rake | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/tasks/email_tos_update.rake b/lib/tasks/email_tos_update.rake index 63b192c858..89a675ce8c 100644 --- a/lib/tasks/email_tos_update.rake +++ b/lib/tasks/email_tos_update.rake @@ -1,19 +1,27 @@ namespace :email do - task :tos_update => :environment do - puts "Emailing #{Publisher.count} users" + task :tos_update, [:id ] => :environment do |t, args| - Publisher.order(:id).find_each.with_index do |user, index| + publisher = Publisher + if args[:id].present? + publisher = publisher.where("id >= ?", args[:id]) + end + + puts "Emailing #{publisher.count} users" + publisher.order(id: :desc).find_each.with_index do |user, index| begin PublisherMailer.update_to_tos(user).deliver_now print '.' if index % 1000 == 0 - rescue - # Let's rescue all exceptions - print "X" - Rails.logger.info "[#{Time.now.iso8601}] Could not send terms and conditions for [#{user.id}]" + rescue => ex + puts + puts "Rescued from exception: #{ex.message}" + puts "Could not send email to #{user.id} - Restart the job by running the following" + puts + puts " rake email:tos_update[\"#{user.id}\"]" + break end end puts - puts "✨ Done" + puts "Done" end end From 43c0374f701dc6117efa602eeb76cb5e6dcad5ea Mon Sep 17 00:00:00 2001 From: Cory McDonald Date: Wed, 19 Jun 2019 16:43:15 -0500 Subject: [PATCH 3/4] Remove unused mailers (#1975) * Remove unused mailers * Delete file --- app/mailers/publisher_mailer.rb | 17 ----------------- .../uphold_account_changed.html.slim | 9 --------- config/locales/en.yml | 4 ---- .../previews/publisher_mailer_preview.rb | 3 --- test/mailers/publisher_mailer_test.rb | 13 ------------- 5 files changed, 46 deletions(-) delete mode 100644 app/views/publisher_mailer/uphold_account_changed.html.slim diff --git a/app/mailers/publisher_mailer.rb b/app/mailers/publisher_mailer.rb index 8b7027dbf8..4c88da14cd 100644 --- a/app/mailers/publisher_mailer.rb +++ b/app/mailers/publisher_mailer.rb @@ -121,14 +121,6 @@ def notify_email_change(publisher) ) end - def uphold_account_changed(publisher) - @publisher = publisher - mail( - to: @publisher.email, - subject: default_i18n_subject - ) - end - def uphold_kyc_incomplete(publisher) @publisher = publisher mail( @@ -145,15 +137,6 @@ def uphold_member_restricted(publisher) ) end - def statement_ready(publisher_statement) - @publisher_statement = publisher_statement - @publisher = publisher_statement.publisher - mail( - to: @publisher.email, - subject: default_i18n_subject - ) - end - def suspend_publisher(publisher) @publisher = publisher mail( diff --git a/app/views/publisher_mailer/uphold_account_changed.html.slim b/app/views/publisher_mailer/uphold_account_changed.html.slim deleted file mode 100644 index 9016e3273e..0000000000 --- a/app/views/publisher_mailer/uphold_account_changed.html.slim +++ /dev/null @@ -1,9 +0,0 @@ -/ Sent as soon as a publisher fills out the first step. -- content_for(:title) do - h3= t ".title" - -p.salutation= t "publisher_mailer.shared.salutation", name: @publisher.name || name_from_email(@publisher.email) - -p= t ".body" - -.notice= t "shared.support_note_html" diff --git a/config/locales/en.yml b/config/locales/en.yml index e553911486..271fda039e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -365,10 +365,6 @@ en: body_html: We have noticed some unusual or suspicious contributions to your Brave Rewards account. As a result we have temporarily frozen payments made to your account.

Suspicious contributions can include unreasonably large contributions for small channels and/or contribution that solely originate from the user growth pool.

Please contact us at support+publishers@basicattentiontoken.org. closing_html: Thank you.
The Brave Rewards Team contact_support: If you did not make this change yourself, please contact support ASAP - uphold_account_changed: - subject: Your Brave Rewards Uphold account has been updated - title: Publisher Uphold account changed - body: This email confirms your Uphold account through Brave Rewards has been updated. uphold_kyc_incomplete: subject: Please verify your Uphold identity body_html: | diff --git a/test/mailers/previews/publisher_mailer_preview.rb b/test/mailers/previews/publisher_mailer_preview.rb index 302866d477..156069bef3 100644 --- a/test/mailers/previews/publisher_mailer_preview.rb +++ b/test/mailers/previews/publisher_mailer_preview.rb @@ -24,9 +24,6 @@ def verification_done PublisherMailer.verification_done(Channel.first) end - def uphold_account_changed - PublisherMailer.uphold_account_changed(Publisher.first) - end def wallet_not_connected PublisherMailer.wallet_not_connected(Publisher.first) diff --git a/test/mailers/publisher_mailer_test.rb b/test/mailers/publisher_mailer_test.rb index 254e5313a3..cfa5281863 100644 --- a/test/mailers/publisher_mailer_test.rb +++ b/test/mailers/publisher_mailer_test.rb @@ -10,19 +10,6 @@ class PublisherMailerTest < ActionMailer::TestCase Rails.application.secrets[:api_eyeshade_offline] = @prev_eyeshade_offline end - test "uphold_account_changed" do - publisher = publishers(:default) - email = PublisherMailer.uphold_account_changed(publisher) - - # # Send the email, then test that it got queued - assert_emails 1 do - email.deliver_now - end - - assert_equal ['brave-publishers@localhost.local'], email.from - assert_equal [publisher.email], email.to - end - test "wallet_not_connected" do publisher = publishers(:uphold_connected) email = PublisherMailer.wallet_not_connected(publisher) From 77839b9a6e8aeb762ddb1961e7b43d08fe696b1f Mon Sep 17 00:00:00 2001 From: Cory McDonald Date: Wed, 19 Jun 2019 17:09:02 -0500 Subject: [PATCH 4/4] Create "only user funds" state (#1973) --- app/assets/stylesheets/pages/home.scss | 34 ++++++----- .../publisher_status_updates_controller.rb | 4 ++ app/helpers/admin/publishers_helper.rb | 5 +- .../components/TopNav/TopNavStyle.ts | 5 ++ app/jobs/delete_publisher_channel_job.rb | 19 +----- .../include_publisher_in_payout_report_job.rb | 4 +- app/models/channel.rb | 2 +- app/models/promo_registration.rb | 6 ++ app/models/publisher.rb | 4 ++ app/models/publisher_status_update.rb | 15 ++++- .../promo/publisher_channels_registrar.rb | 37 ++++++----- .../publisher_status_updates/index.html.slim | 16 +++++ app/views/publishers/home.html.slim | 2 +- .../site_channels_controller_test.rb | 61 +++++++++++++++++++ test/fixtures/publisher_status_updates.yml | 4 ++ test/fixtures/publishers.yml | 6 ++ test/tasks/launch_promo_test.rb | 4 +- 17 files changed, 171 insertions(+), 57 deletions(-) diff --git a/app/assets/stylesheets/pages/home.scss b/app/assets/stylesheets/pages/home.scss index e870f76968..e4ed2e583e 100644 --- a/app/assets/stylesheets/pages/home.scss +++ b/app/assets/stylesheets/pages/home.scss @@ -66,7 +66,6 @@ } @include media-breakpoint-down(md) { - .title, .btn { display: none; @@ -120,7 +119,7 @@ &-header { color: #326183; - letter-spacing: .5px; + letter-spacing: 0.5px; } .promo-flex-col { @@ -172,7 +171,7 @@ font-weight: 600; padding: 0 8px 0 0; font-size: 24px; - color: #FFF; + color: #fff; } } @@ -283,7 +282,7 @@ .referral-link-copy-button { background: $braveBrand; - color: $braveText-2; + color: white; height: 100%; border-radius: 0px 4px 4px 0px; cursor: pointer; @@ -317,7 +316,6 @@ } @include media-breakpoint-down(sm) { - .referral-link-button { &-mobile { display: table-cell; @@ -495,7 +493,6 @@ } &.uphold-timeout { - .status-summary .action, #uphold_dashboard, #uphold_connect, @@ -507,7 +504,6 @@ &.uphold-complete, &.uphold-processing { - .status-summary .action .connect-uphold, #uphold_connect { display: none; @@ -515,7 +511,6 @@ } &.uphold-processing { - #uphold_dashboard, #last_settlement, .statements-available { @@ -555,7 +550,6 @@ &.uphold-reauthorization-needed, &.uphold-unconnected { - .status-summary .action .disconnect-uphold, .reconnect-instructions { display: none; @@ -563,7 +557,6 @@ } &.uphold-restricted { - .status-summary .action .connect-uphold, .reconnect-instructions { display: none; @@ -684,7 +677,7 @@ padding: 32px; &:hover { - background: rgba(255, 255, 255, .8); + background: rgba(255, 255, 255, 0.8); text-decoration: none; } } @@ -739,7 +732,8 @@ font-size: 14px; padding: 3px 0 3px 115px; margin-right: 10px; - background: url(asset-path("channel-progress.png")) no-repeat center left; + background: url(asset-path("channel-progress.png")) no-repeat center + left; } } } @@ -747,7 +741,8 @@ &.channel-failed { .channel-status { display: flex; - background: url(asset-path("icn-warning@1x.png")) no-repeat top left / 24px 24px; + background: url(asset-path("icn-warning@1x.png")) no-repeat top left / + 24px 24px; padding: 0 0 12px 38px; font-weight: bold; @@ -1014,7 +1009,7 @@ .modal-container--modal-identifier--choose-channel-type { max-width: 685px; - &>div { + & > div { width: 100%; background-image: url(asset-path("choose-channel/header.jpg")); background-repeat: no-repeat; @@ -1151,10 +1146,17 @@ margin: 0 0 24px; } -p, body, h1, h2, h3, h4, h5, h6 { +p, +body, +h1, +h2, +h3, +h4, +h5, +h6 { color: $braveText-2; } #cancel_edit_contact { padding: 8px; -} \ No newline at end of file +} diff --git a/app/controllers/admin/publishers/publisher_status_updates_controller.rb b/app/controllers/admin/publishers/publisher_status_updates_controller.rb index 57569eccb3..147e23891d 100644 --- a/app/controllers/admin/publishers/publisher_status_updates_controller.rb +++ b/app/controllers/admin/publishers/publisher_status_updates_controller.rb @@ -20,6 +20,10 @@ def create end end + if @publisher.only_user_funds? + flash[:alert] = "FYI: The promo registrations have not been destroyed for this user - however they will not see their promotions" + end + flash[:notice] = "Updated publisher's status to #{@publisher.inferred_status}" redirect_to admin_publisher_path(id: @publisher.id) end diff --git a/app/helpers/admin/publishers_helper.rb b/app/helpers/admin/publishers_helper.rb index 366419baba..5f065abfc9 100644 --- a/app/helpers/admin/publishers_helper.rb +++ b/app/helpers/admin/publishers_helper.rb @@ -10,11 +10,12 @@ def publisher_status(publisher) def status_badge_class(status) label = case status - when PublisherStatusUpdate::SUSPENDED + when PublisherStatusUpdate::SUSPENDED, PublisherStatusUpdate::ONLY_USER_FUNDS + "badge-danger" "badge-danger" when PublisherStatusUpdate::LOCKED "badge-warning" - when PublisherStatusUpdate::NO_GRANTS + when PublisherStatusUpdate::NO_GRANTS, PublisherStatusUpdate::HOLD "badge-dark" when PublisherStatusUpdate::ACTIVE "badge-success" diff --git a/app/javascript/views/admin/components/userNavbar/components/TopNav/TopNavStyle.ts b/app/javascript/views/admin/components/userNavbar/components/TopNav/TopNavStyle.ts index 002dc94571..64d13a509d 100644 --- a/app/javascript/views/admin/components/userNavbar/components/TopNav/TopNavStyle.ts +++ b/app/javascript/views/admin/components/userNavbar/components/TopNav/TopNavStyle.ts @@ -110,6 +110,11 @@ export const Status = styled.div` ` background-color: #CB2431; `} + ${(props: Partial) => + props.status === "only_user_funds" && + ` + background-color: #CB2431; + `} ${(props: Partial) => props.status === "locked" && ` diff --git a/app/jobs/delete_publisher_channel_job.rb b/app/jobs/delete_publisher_channel_job.rb index 8e2112e87f..ed3e793a29 100644 --- a/app/jobs/delete_publisher_channel_job.rb +++ b/app/jobs/delete_publisher_channel_job.rb @@ -17,23 +17,6 @@ def perform(channel_id:) channel_is_verified = @channel.verified? - if should_update_promo_server - referral_code = @channel.promo_registration.referral_code - end - - success = @channel.destroy! - - # Update Eyeshade and Promo - if success && channel_is_verified && should_update_promo_server - Promo::ChannelOwnerUpdater.new(referral_code: referral_code).perform - end - - success - end - - private - - def should_update_promo_server - @channel.promo_registration.present? + @channel.destroy! end end diff --git a/app/jobs/include_publisher_in_payout_report_job.rb b/app/jobs/include_publisher_in_payout_report_job.rb index ba870c2c0d..6f577147d5 100644 --- a/app/jobs/include_publisher_in_payout_report_job.rb +++ b/app/jobs/include_publisher_in_payout_report_job.rb @@ -1,12 +1,12 @@ class IncludePublisherInPayoutReportJob < ApplicationJob queue_as :scheduler - + def perform(payout_report_id:, publisher_id:, should_send_notifications:) # If payout_report_id is not present, we only want to send notifications # not create payments if payout_report_id.present? - payout_report = PayoutReport.find(payout_report_id) + payout_report = PayoutReport.find(payout_report_id) else payout_report = nil end diff --git a/app/models/channel.rb b/app/models/channel.rb index 90724a3cc3..bef52b46bf 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -365,7 +365,7 @@ def most_recent_potential_payment def should_register_channel_for_promo promo_running = Rails.application.secrets[:active_promo_id].present? # Could use PromosHelper#active_promo_id publisher_enabled_promo = publisher.promo_enabled_2018q1? - promo_running && publisher_enabled_promo && saved_change_to_verified? && verified + promo_running && publisher_enabled_promo && saved_change_to_verified? && verified && !publisher.only_user_funds? end def clear_verified_at_if_necessary diff --git a/app/models/promo_registration.rb b/app/models/promo_registration.rb index 1d947141a7..51ee2ac6b2 100644 --- a/app/models/promo_registration.rb +++ b/app/models/promo_registration.rb @@ -42,6 +42,12 @@ class PromoRegistration < ApplicationRecord scope :channels_only, -> { where(kind: CHANNEL) } scope :has_stats, -> { where.not(stats: "[]") } + before_destroy :delete_from_promo_server + + def delete_from_promo_server + Promo::ChannelOwnerUpdater.new(referral_code: referral_code).perform + end + # Parses the events associated with a promo registration and returns # the aggregate totals for each event type def aggregate_stats diff --git a/app/models/publisher.rb b/app/models/publisher.rb index d469891f87..7ebd4896c1 100644 --- a/app/models/publisher.rb +++ b/app/models/publisher.rb @@ -225,6 +225,10 @@ def hold? last_status_update&.status == PublisherStatusUpdate::HOLD end + def only_user_funds? + last_status_update&.status == PublisherStatusUpdate::ONLY_USER_FUNDS + end + def locked? last_status_update&.status == PublisherStatusUpdate::LOCKED end diff --git a/app/models/publisher_status_update.rb b/app/models/publisher_status_update.rb index 4f7e3a3420..99646cbfc0 100644 --- a/app/models/publisher_status_update.rb +++ b/app/models/publisher_status_update.rb @@ -7,8 +7,21 @@ class PublisherStatusUpdate < ApplicationRecord DELETED = 'deleted'.freeze NO_GRANTS = 'no_grants'.freeze HOLD = 'hold'.freeze + ONLY_USER_FUNDS = 'only_user_funds'.freeze - ALL_STATUSES = [CREATED, ONBOARDING, ACTIVE, SUSPENDED, LOCKED, NO_GRANTS, DELETED, HOLD].freeze + ALL_STATUSES = [CREATED, ONBOARDING, ACTIVE, SUSPENDED, LOCKED, NO_GRANTS, DELETED, HOLD, ONLY_USER_FUNDS].freeze + + DESCRIPTIONS = { + CREATED => "User has signed up but not signed in.", + ONBOARDING => "User has signed in but not completed entering their information", + ACTIVE => "User is an active publisher. User can perform normal account operations.", + SUSPENDED => "Account has been placed under review.", + ONLY_USER_FUNDS => "User will not receive any Brave funds. Only funds that will be sent are user funded.", + LOCKED => "User has removed 2-FA but still needs to wait until a month has passed to receive payout.", + NO_GRANTS => "User can receive user funded tips and use the referral promotion system.", + HOLD => "User's payment is held awaiting additional information and interview on how they obtained referrals and contributions.", + DELETED => "user has been deleted from the publishers system.", + }.freeze belongs_to :publisher belongs_to :publisher_note diff --git a/app/services/promo/publisher_channels_registrar.rb b/app/services/promo/publisher_channels_registrar.rb index 2ee2839c38..1bac211bf0 100644 --- a/app/services/promo/publisher_channels_registrar.rb +++ b/app/services/promo/publisher_channels_registrar.rb @@ -13,6 +13,8 @@ def perform next unless should_register_channel?(channel) result = register_channel(channel) + next if result.nil? + referral_code = result[:referral_code] should_update_promo_server = result[:should_update_promo_server] @@ -36,6 +38,9 @@ def perform Raven.capture_exception("Promo::PublisherChannelsRegistrar #perform error: #{e}") end end + rescue Faraday::Error::ClientError => e + # When the owner is "no-ugp" the promo server will return 409. + nil end def register_channel(channel) @@ -51,23 +56,27 @@ def register_channel(channel) referral_code: JSON.parse(response.body)["referral_code"], should_update_promo_server: false } + rescue Faraday::Error::ClientError => e + change_ownership(channel) rescue Faraday::Error => e - if e.response[:status] == 409 - Rails.logger.warn("Promo::PublisherChannelsRegistrar #register_channel returned 409, channel already registered. Using Promo::RegistrationGetter to get the referral_code.") + require "sentry-raven" + Rails.logger.error("Promo::PublisherChannelsRegistrar #register_channel error: #{e}") + Raven.capture_exception("Promo::PublisherChannelsRegistrar #register_channel error: #{e}") + nil + end - # Get the referral code - registration = Promo::RegistrationGetter.new(publisher: @publisher, channel: channel).perform + def change_ownership(channel) + Rails.logger.warn("Promo::PublisherChannelsRegistrar #register_channel returned 409, channel already registered. Using Promo::RegistrationGetter to get the referral_code.") - { - referral_code: registration["referral_code"], - should_update_promo_server: registration["owner_id"] != @publisher.id ? true : false - } - else - require "sentry-raven" - Rails.logger.error("Promo::PublisherChannelsRegistrar #register_channel error: #{e}") - Raven.capture_exception("Promo::PublisherChannelsRegistrar #register_channel error: #{e}") - nil - end + # Get the referral code + registration = Promo::RegistrationGetter.new(publisher: @publisher, channel: channel).perform + + { + referral_code: registration["referral_code"], + should_update_promo_server: registration["owner_id"] != @publisher.id ? true : false + } + rescue Faraday::Error::ClientError => e + nil end def register_channel_offline diff --git a/app/views/admin/publishers/publisher_status_updates/index.html.slim b/app/views/admin/publishers/publisher_status_updates/index.html.slim index 49a8b5b06e..063451178d 100644 --- a/app/views/admin/publishers/publisher_status_updates/index.html.slim +++ b/app/views/admin/publishers/publisher_status_updates/index.html.slim @@ -33,6 +33,22 @@ h5.admin-header Change current status for #{@publisher.name} = " Send email (suspended & hold only)" = f.submit("Update Status", class: 'btn btn-primary') + +.legend.my-5 + h2.mb-0 Legend + table.table + thead + tr + th Status + th Description + tbody + - PublisherStatusUpdate::DESCRIPTIONS.each do |description| + tr + td + span class=status_badge_class(description.first) + = description.first + td= description.second + hr h5.admin-header Status history diff --git a/app/views/publishers/home.html.slim b/app/views/publishers/home.html.slim index 12a3c0c1d3..25cdae9474 100644 --- a/app/views/publishers/home.html.slim +++ b/app/views/publishers/home.html.slim @@ -203,7 +203,7 @@ script type="text/html" id="confirm_default_currency_modal_wrapper" .channel-panel--intro-body = channel_type(channel).upcase - if channel.verified? - - if current_publisher.promo_status(promo_running?) == :active && channel.promo_enabled? + - if current_publisher.promo_status(promo_running?) == :active && channel.promo_enabled? && !current_publisher.only_user_funds? .channel--promo-info-container = link_to("", tweet_url(channel.promo_registration.referral_code), target: :_blank, class: "promo-share-button promo-share-button-twitter") = link_to("", facebook_url(channel.promo_registration.referral_code), target: :_blank, class: "promo-share-button promo-share-button-facebook") diff --git a/test/controllers/site_channels_controller_test.rb b/test/controllers/site_channels_controller_test.rb index 1fb38a1e43..3b917a54ad 100644 --- a/test/controllers/site_channels_controller_test.rb +++ b/test/controllers/site_channels_controller_test.rb @@ -211,6 +211,67 @@ class SiteChannelsControllerTest < ActionDispatch::IntegrationTest end end + test 'when a channel is created a promotion is registered' do + prev_host_inspector_offline = Rails.application.secrets[:host_inspector_offline] + begin + Rails.application.secrets[:host_inspector_offline] = true + publisher = publishers(:promo_enabled) + + sign_in publishers(:promo_enabled) + + create_params = { + channel: { + details_attributes: { + brave_publisher_id_unnormalized: "new_site_54634.org" + } + } + } + + assert_difference('publisher.channels.count') do + post site_channels_url, params: create_params + end + + new_channel = publisher.channels.order(created_at: :asc).last + + # Triggering an update to test if the promo was created + assert_enqueued_with(job: ActionMailer::DeliveryJob) do + new_channel.update(verified: true) + end + ensure + Rails.application.secrets[:host_inspector_offline] = prev_host_inspector_offline + end + end + + test "when user only is in status 'only user funds' we do not register for promos" do + prev_host_inspector_offline = Rails.application.secrets[:host_inspector_offline] + begin + Rails.application.secrets[:host_inspector_offline] = true + publisher = publishers(:promo_enabled_but_only_user_funds) + + sign_in publishers(:promo_enabled_but_only_user_funds) + + create_params = { + channel: { + details_attributes: { + brave_publisher_id_unnormalized: "new_site_54634.org" + } + } + } + + assert_difference('publisher.channels.count') do + post site_channels_url, params: create_params + end + + new_channel = publisher.channels.order(created_at: :asc).last + + # Triggering an update to test if the promo was created + assert_no_enqueued_jobs do + new_channel.update(verified: true) + end + ensure + Rails.application.secrets[:host_inspector_offline] = prev_host_inspector_offline + end + end test "two different publishers can have the same unverifed site channel" do prev_host_inspector_offline = Rails.application.secrets[:host_inspector_offline] begin diff --git a/test/fixtures/publisher_status_updates.yml b/test/fixtures/publisher_status_updates.yml index ce53f4110e..e7bd030d4f 100644 --- a/test/fixtures/publisher_status_updates.yml +++ b/test/fixtures/publisher_status_updates.yml @@ -39,3 +39,7 @@ suspended_partner: partner: publisher_id: ade27753-2327-40dc-a1f8-06d3339f08cf status: "active" + +only_user_funds: + publisher: promo_enabled_but_only_user_funds + status: "only_user_funds" diff --git a/test/fixtures/publishers.yml b/test/fixtures/publishers.yml index cde1a963e1..22b20b14ae 100644 --- a/test/fixtures/publishers.yml +++ b/test/fixtures/publishers.yml @@ -246,6 +246,12 @@ locked_out_verifier: promo_enabled: email: "enabled@promo.org" name: "peter promo" + promo_enabled_2018q1: true + +promo_enabled_but_only_user_funds: + email: "only user funds@promo.org" + name: "peter promo" + promo_enabled_2018q1: true potentially_paid: email: "priscilla@potentiallypaid.org" diff --git a/test/tasks/launch_promo_test.rb b/test/tasks/launch_promo_test.rb index 2518d6068e..8aaa314271 100644 --- a/test/tasks/launch_promo_test.rb +++ b/test/tasks/launch_promo_test.rb @@ -9,8 +9,8 @@ class LaunchPromoTest < ActiveJob::TestCase end test "generates a promo token and sends email to each publisher" do - assert_difference("Publisher.where.not(promo_token_2018q1: nil).count", Publisher.where.not(email: nil).count) do - assert_enqueued_jobs(Publisher.where.not(email: nil).count) do + assert_difference("Publisher.where.not(promo_token_2018q1: nil).count", Publisher.where.not(email: nil, promo_enabled_2018q1: true).count) do + assert_enqueued_jobs(Publisher.where.not(email: nil, promo_enabled_2018q1: true).count) do Rake::Task["promo:launch_promo"].invoke Rake::Task["promo:launch_promo"].reenable end