Skip to content

Commit

Permalink
Create "only user funds" state (#1973)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory McDonald authored Jun 19, 2019
1 parent 43c0374 commit 77839b9
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 57 deletions.
34 changes: 18 additions & 16 deletions app/assets/stylesheets/pages/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
}

@include media-breakpoint-down(md) {

.title,
.btn {
display: none;
Expand Down Expand Up @@ -120,7 +119,7 @@

&-header {
color: #326183;
letter-spacing: .5px;
letter-spacing: 0.5px;
}

.promo-flex-col {
Expand Down Expand Up @@ -172,7 +171,7 @@
font-weight: 600;
padding: 0 8px 0 0;
font-size: 24px;
color: #FFF;
color: #fff;
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -317,7 +316,6 @@
}

@include media-breakpoint-down(sm) {

.referral-link-button {
&-mobile {
display: table-cell;
Expand Down Expand Up @@ -495,7 +493,6 @@
}

&.uphold-timeout {

.status-summary .action,
#uphold_dashboard,
#uphold_connect,
Expand All @@ -507,15 +504,13 @@

&.uphold-complete,
&.uphold-processing {

.status-summary .action .connect-uphold,
#uphold_connect {
display: none;
}
}

&.uphold-processing {

#uphold_dashboard,
#last_settlement,
.statements-available {
Expand Down Expand Up @@ -555,15 +550,13 @@

&.uphold-reauthorization-needed,
&.uphold-unconnected {

.status-summary .action .disconnect-uphold,
.reconnect-instructions {
display: none;
}
}

&.uphold-restricted {

.status-summary .action .connect-uphold,
.reconnect-instructions {
display: none;
Expand Down Expand Up @@ -684,7 +677,7 @@
padding: 32px;

&:hover {
background: rgba(255, 255, 255, .8);
background: rgba(255, 255, 255, 0.8);
text-decoration: none;
}
}
Expand Down Expand Up @@ -739,15 +732,17 @@
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;
}
}
}

&.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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/admin/publishers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export const Status = styled.div`
`
background-color: #CB2431;
`}
${(props: Partial<IStatusProps>) =>
props.status === "only_user_funds" &&
`
background-color: #CB2431;
`}
${(props: Partial<IStatusProps>) =>
props.status === "locked" &&
`
Expand Down
19 changes: 1 addition & 18 deletions app/jobs/delete_publisher_channel_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/jobs/include_publisher_in_payout_report_job.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/models/promo_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion app/models/publisher_status_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 23 additions & 14 deletions app/services/promo/publisher_channels_registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/publishers/home.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 77839b9

Please sign in to comment.