Skip to content

Commit

Permalink
Merge pull request #2002 from brave-intl/user-funds-only-front-end
Browse files Browse the repository at this point in the history
Improve User Funds Only front end
  • Loading branch information
Cory McDonald authored Jul 2, 2019
2 parents e939987 + 2713195 commit de7d77d
Show file tree
Hide file tree
Showing 27 changed files with 325 additions and 235 deletions.
4 changes: 2 additions & 2 deletions app/assets/stylesheets/admin/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/* Position tooltip above the element */
[data-tooltip]:before {
position: absolute;
bottom: 150%;
bottom: 100%;
left: 50%;
margin-bottom: 5px;
margin-left: -80px;
Expand All @@ -36,7 +36,7 @@
/* Triangle hack to make tooltip look like a speech bubble */
[data-tooltip]:after {
position: absolute;
bottom: 150%;
bottom: 100%;
left: 50%;
margin-left: -5px;
width: 0;
Expand Down
5 changes: 1 addition & 4 deletions app/assets/stylesheets/pages/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,14 @@
}

&-alert {
width: 60%;

#promo-panel-alert {
font-size: 14px;
font-weight: 600;
color: #006192;
padding: 30px 30px 35px 70px;
margin-right: 20px;
background-color: white;
background-color: rgba(255, 255, 255, 0.6);
text-align: left;
opacity: 0.5;
border-radius: 10px;
background-image: url(asset-path("icn-info.png"));
background-position: center left 15px;
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/publishers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def show
@publisher = Publisher.find(params[:id])
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard" }).to_json
@potential_referral_payment = @publisher.most_recent_potential_referral_payment
@referral_owner_status = Promo::Client.new.owner_state.find(id: params[:id])
@current_user = current_user
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/promo_registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create

if @publisher_has_verified_channel
if @publisher.channels.where(verified: true).count > 5
RegisterPublisherForPromoJob.perform_later(publisher: @publisher)
Promo::RegisterPublisherForPromoJob.perform_later(publisher: @publisher)
redirect_to home_publishers_path, notice: t("promo.activated.please_wait")
else
Promo::PublisherChannelsRegistrar.new(publisher: @publisher).perform
Expand Down
21 changes: 17 additions & 4 deletions app/helpers/publishers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ def publisher_overall_bat_balance(publisher)
balance = I18n.t("helpers.publisher.balance_unavailable")
sentry_catcher do
publisher = publisher.become_subclass
amount = publisher.wallet&.overall_balance&.amount_bat
amount = publisher.balance if publisher.partner?

if publisher.partner?
amount = publisher.balance
elsif publisher.only_user_funds?
amount = publisher.wallet&.contribution_balance&.amount_bat
else
amount = publisher.wallet&.overall_balance&.amount_bat
end

balance = '%.2f' % amount if amount.present?
end

Expand All @@ -51,8 +58,14 @@ def publisher_converted_overall_balance(publisher)
return if publisher.default_currency == "BAT" || publisher.default_currency.blank?

publisher = publisher&.become_subclass
balance = publisher.wallet&.overall_balance&.amount_default_currency
balance = publisher.balance_in_currency if publisher.partner?

if publisher.partner?
balance = publisher.balance_in_currency
elsif publisher.only_user_funds?
balance = publisher.wallet&.contribution_balance&.amount_default_currency
else
balance = publisher.wallet&.overall_balance&.amount_default_currency
end

if balance.present?
I18n.t("helpers.publisher.balance_pending_approximate",
Expand Down
15 changes: 15 additions & 0 deletions app/jobs/promo/register_channel_for_promo_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Registers a single channel for a promo immediately after verification
module Promo
class RegisterChannelForPromoJob < ApplicationJob
include PromosHelper
queue_as :default

def perform(channel:)
if Promo::PublisherChannelsRegistrar.new(publisher: channel.publisher).perform
PromoMailer.new_channel_registered_2018q1(channel.publisher, channel).deliver_later
else
Rails.logger.warn("Failed to register newly verified channel #{channel} with promo server")
end
end
end
end
19 changes: 19 additions & 0 deletions app/jobs/promo/register_publisher_for_promo_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Used to register a publisher with > 5 channels async
module Promo
class RegisterPublisherForPromoJob < ApplicationJob
include PromosHelper
queue_as :default

def perform(publisher:)
return unless publisher.promo_enabled_2018q1
Rails.logger.info("Registering publisher #{publisher.id} for promo async.")

if Promo::PublisherChannelsRegistrar.new(publisher: publisher).perform
promo_enabled_channels = publisher.channels.joins(:promo_registration)
PromoMailer.promo_activated_2018q1_verified(publisher, promo_enabled_channels).deliver
else
Rails.logger.warn("Failed to register publisher #{publisher.id} with promo server async.")
end
end
end
end
22 changes: 22 additions & 0 deletions app/jobs/promo/update_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Registers a single channel for a promo immediately after verification
module Promo
class UpdateStatus < ApplicationJob
queue_as :default

def perform(id:, status:)
client = Promo::Client.new

# Remove previous states, this prevents from any unique index constraints from being violated
states = client.owner_state.find(id: id)
states.each do |state|
client.owner_state.destroy(id: id, state: state)
end

if status == PublisherStatusUpdate::SUSPENDED
client.owner_state.create(id: id, state: Promo::Models::OwnerState::State::SUSPEND)
elsif status == PublisherStatusUpdate::ONLY_USER_FUNDS
client.owner_state.create(id: id, state: Promo::Models::OwnerState::State::NO_UGP)
end
end
end
end
13 changes: 0 additions & 13 deletions app/jobs/register_channel_for_promo_job.rb

This file was deleted.

17 changes: 0 additions & 17 deletions app/jobs/register_publisher_for_promo_job.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def clear_verified_at_if_necessary
end

def register_channel_for_promo
RegisterChannelForPromoJob.new.perform(channel: self)
Promo::RegisterChannelForPromoJob.new.perform(channel: self)
end

def notify_slack
Expand Down
16 changes: 16 additions & 0 deletions app/models/publisher_status_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class PublisherStatusUpdate < ApplicationRecord

ALL_STATUSES = [CREATED, ONBOARDING, ACTIVE, SUSPENDED, LOCKED, NO_GRANTS, DELETED, HOLD, ONLY_USER_FUNDS].freeze

USER_SELECTABLE = [ACTIVE, SUSPENDED, NO_GRANTS, 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",
Expand All @@ -30,6 +32,20 @@ class PublisherStatusUpdate < ApplicationRecord

validates :publisher_id, presence: true

# After a user creates a new status then we should check to see the previous staus and call backing server
after_create :update_services, if: :should_update?

# Queues a job to call the promo server to update the owner state for the publisher based on the status
#
# @return [nil]
def update_services
Promo::UpdateStatus.perform_later(id: publisher_id, status: status)
end

def should_update?
[ACTIVE, SUSPENDED, ONLY_USER_FUNDS].include?(status)
end

def to_s
status
end
Expand Down
10 changes: 8 additions & 2 deletions app/services/base_api_client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class BaseApiClient < BaseService
private
# Make a GET request.
#
# path - [String] the path relative to the endpoint
Expand Down Expand Up @@ -47,13 +48,18 @@ def delete(path, options = {})
request(:delete, path, form: options)
end

private

def api_base_uri
raise "specify me"
end

def perform_offline?
false
end

def request(method, path, payload = {})
# Mock out the request
return Struct.new(:body).new("{}") if perform_offline?

@connection.send(method) do |req|
req.url [api_base_uri, path].join('')
req.headers["Authorization"] = api_authorization_header
Expand Down
2 changes: 1 addition & 1 deletion app/services/channels/contest_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def perform
suspended: @channel.publisher.suspended?
)

raise SuspendedPublisherError if @channel.publisher.suspended?
raise SuspendedPublisherError if @channel.publisher.suspended? || @channel.publisher.only_user_funds?

ActiveRecord::Base.transaction do
@contested_by.verified = false
Expand Down
2 changes: 1 addition & 1 deletion app/services/payout_report_publisher_includer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(payout_report:, publisher:, should_send_notifications:)
end

def perform
return if !@publisher.has_verified_channel? || @publisher.locked? || @publisher.excluded_from_payout? || @publisher.no_grants? || @publisher.hold?
return if !@publisher.has_verified_channel? || @publisher.locked? || @publisher.excluded_from_payout? || @publisher.hold?

publisher_has_unsettled_balance = false
create_uphold_card_for_default_currency_if_needed
Expand Down
4 changes: 2 additions & 2 deletions app/services/promo/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def owner_state

private

def perform_offline
true
def perform_offline?
Rails.application.secrets[:api_promo_base_uri].blank?
end

def api_base_uri
Expand Down
2 changes: 1 addition & 1 deletion app/services/promo/models/owner_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create(id:, state:)
# Removes the state for the specified owner
#
# @param [String] id The publisher id
# @state [Promo::Models::OwnerState::State] state The state to remove from the owner.
# @param [Promo::Models::OwnerState::State] state The state to remove from the owner.
#
# @return [true] if destroy was a success
def destroy(id:, state:)
Expand Down
90 changes: 49 additions & 41 deletions app/views/admin/publishers/publisher_status_updates/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,60 @@


h5.admin-header Change current status for #{@publisher.name}
- if @publisher.suspended?
.my-3
p.alert.alert-warning
= "If you are planning on unsuspending this user please provide evidence and justification for your actions. "
br
br
= "If you believe this user is a potential outlier please contact the appropriate group and alert them."
- else
.my-3
p.alert.alert-warning
= "If you are planning on suspending this user please provide evidence and justification for your actions. This may come in the form of excel, git, or a reasonable explaination of the users misdeeds."
br
br
= "Please view more information about the publisher guidelines here."
br
= link_to "https://community.brave.com/t/a-note-to-publishers/48733", "https://community.brave.com/t/a-note-to-publishers/48733"

= form_for(@publisher, url: admin_publisher_publisher_status_updates_path(@publisher.id), method: :create) do |f|
.form-group
= label_tag(:status_label, "Status")
= select_tag(:publisher_status, options_for_select(PublisherStatusUpdate::ALL_STATUSES, @publisher.last_status_update), class: "form-control")
- if @publisher.only_user_funds?
p.alert.alert-warning
= "This user has been placed into an #{@publisher.last_status_update} status. Once a user has been placed into this status it is not possible to remove."
br
br
= "If you believe this was a mistake please contact the appropriate product owners and engage the engineering team."

.form-group
= label_tag(:note_label, "Include a note: ")
= text_area_tag(:note, '', class: 'form-control', rows: 5, required: true)
.form-group
label
= check_box_tag("send_email", true)
= " Send email (suspended & hold only)"
= f.submit("Update Status", class: 'btn btn-primary')
- else
- if @publisher.suspended?
.my-3
p.alert.alert-warning
= "If you are planning on unsuspending this user please provide evidence and justification for your actions. "
br
br
= "If you believe this user is a potential outlier please contact the appropriate group and alert them."
- else
.my-3
p.alert.alert-warning
= "If you are planning on suspending this user please provide evidence and justification for your actions. This may come in the form of excel, git, or a reasonable explaination of the users misdeeds."
br
br
= "Please view more information about the publisher guidelines here."
br
= link_to "https://community.brave.com/t/a-note-to-publishers/48733", "https://community.brave.com/t/a-note-to-publishers/48733"
= form_for(@publisher, url: admin_publisher_publisher_status_updates_path(@publisher.id), method: :create) do |f|
.form-group
= label_tag(:status_label, "Status")
= select_tag(:publisher_status, options_for_select(PublisherStatusUpdate::USER_SELECTABLE, @publisher.last_status_update), class: "form-control")

.form-group
= label_tag(:note_label, "Include a note: ")
= text_area_tag(:note, '', class: 'form-control', rows: 5, required: true)
.form-group
label
= check_box_tag("send_email", true)
= " 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|

.legend.my-5
h2.mb-0 Legend
table.table
thead
tr
td
span class=status_badge_class(description.first)
= description.first
td= description.second
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

Expand Down
Loading

0 comments on commit de7d77d

Please sign in to comment.