Skip to content

Commit

Permalink
Merge pull request #1918 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-05-29
  • Loading branch information
Cory McDonald authored May 29, 2019
2 parents 1406e66 + 1339c0a commit 2db717b
Show file tree
Hide file tree
Showing 48 changed files with 1,012 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ AllCops:
- app/models/**/*
- app/controllers/publishers_controller.rb
- app/controllers/publishers/registrations_controller.rb
- app/controllers/admin/publisher_notes_controller.rb
- app/controllers/admin/publishers_controller.rb
- app/controllers/admin/publishers/publisher_status_updates_controller.rb
Exclude:
- bin/**/*
- db/**/*
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/admin/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

// Admin pages
@import "pages/**/*";
@import "tooltip";
51 changes: 51 additions & 0 deletions app/assets/stylesheets/admin/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,54 @@ a.logo span {
border: 1px solid #eee;
color: #ddd;
}

.user-avatar {
margin: 4px;
width: 42px;
height: 42px;
border: solid 1px rgba(0, 0, 0, 0.2);
border-radius: 50%;
overflow: hidden;

svg {
width: 40px;
height: 40px;
opacity: 0.8;
filter: brightness(5) grayscale(1)
drop-shadow(0px 0px 1px rgba(0, 0, 0, 0.3));
}
}

.user-avatar-dropdown {
border: solid 1px rgba(0, 0, 0, 0.2);
border-radius: 50%;
display: inline-block;
overflow: hidden;
height: 27px;
width: 27px;
margin-right: 8px;

img {
width: 25px;
height: 25px;
opacity: 0.8;
filter: brightness(5) grayscale(1)
drop-shadow(0px 0px 1px rgba(0, 0, 0, 0.3));
}
}

// Overwrite the dropdown
.tribute-container {
border-radius: 5px;
box-shadow: 0 12px 16px rgba(0, 0, 0, 0.3);
background: white;
border: 1px solid #999;
}

.tribute-container ul {
background: white !important;
margin-top: 0 !important;
}
.tribute-container li {
border-bottom: 1px solid #e9e9e9;
}
56 changes: 56 additions & 0 deletions app/assets/stylesheets/admin/tooltip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Taken from https://chrisbracco.com/a-simple-css-tooltip/

/* Add this attribute to the element that needs a tooltip */
[data-tooltip] {
position: relative;
z-index: 2;
cursor: pointer;
}

/* Hide the tooltip content by default */
[data-tooltip]:before,
[data-tooltip]:after {
visibility: hidden;
opacity: 0;
pointer-events: none;
}

/* Position tooltip above the element */
[data-tooltip]:before {
position: absolute;
bottom: 150%;
left: 50%;
margin-bottom: 5px;
margin-left: -80px;
padding: 7px;
width: 180px;
border-radius: 3px;
background-color: hsla(0, 0%, 20%, 0.9);
color: #fff;
content: attr(data-tooltip);
text-align: center;
font-size: 14px;
line-height: 1.2;
}

/* Triangle hack to make tooltip look like a speech bubble */
[data-tooltip]:after {
position: absolute;
bottom: 150%;
left: 50%;
margin-left: -5px;
width: 0;
border-top: 5px solid hsla(0, 0%, 20%, 0.9);
border-right: 5px solid transparent;
border-left: 5px solid transparent;
content: " ";
font-size: 0;
line-height: 0;
}

/* Show tooltip content on hover */
[data-tooltip]:hover:before,
[data-tooltip]:hover:after {
visibility: visible;
opacity: 1;
}
52 changes: 42 additions & 10 deletions app/assets/stylesheets/mailer.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'colors';
@import "colors";
body,
.header,
.content,
Expand Down Expand Up @@ -70,13 +70,13 @@ p {
padding: 12px 0;
display: table;
.btn-primary {
color: #FFFFFF;
text-decoration: none;
text-align: center;
border-radius: 30px;
height: 30px;
background-color: $primaryAccent;
padding: 12px 24px;
color: #ffffff;
text-decoration: none;
text-align: center;
border-radius: 30px;
height: 30px;
background-color: $primaryAccent;
padding: 12px 24px;
}
}
.promo--referral-link-container {
Expand Down Expand Up @@ -116,8 +116,6 @@ p {
}
}
}


}
}

Expand Down Expand Up @@ -151,3 +149,37 @@ p {
width: 24px;
}
}

.user-avatar {
margin: 4px;
width: 30px;
height: 30px;
border: solid 1px rgba(0, 0, 0, 0.2);
border-radius: 50%;
overflow: hidden;

svg {
width: 30px;
height: 30px;
opacity: 0.8;
filter: brightness(5) grayscale(1)
drop-shadow(0px 0px 1px rgba(0, 0, 0, 0.3));
}
}

.d-flex {
display: flex;
}
.mr-2 {
margin-right: 0.5rem;
}

.my-2 {
margin-bottom: 0.5rem !important;
margin-top: 0.5rem !important;
}

.mx-2 {
margin-left: 0.5rem !important;
margin-right: 0.5rem !important;
}
79 changes: 79 additions & 0 deletions app/controllers/admin/publisher_notes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

module Admin
class PublisherNotesController < AdminController
before_action :authorize, except: :create

EMAIL = "@brave.com"

def create
publisher = Publisher.find(params[:publisher_id])

note = PublisherNote.new(
publisher: publisher,
created_by: current_user,
note: note_params[:note],
)
note.thread_id = note_params[:thread_id] if note_params[:thread_id].present?

if note.save
email_tagged_users(note)

if note_params[:thread_id].present?
created_by = note.thread.created_by
if current_user != created_by && note.note.exclude?("@" + created_by.email.sub(EMAIL, ''))
InternalMailer.tagged_in_note(
tagged_user: note.thread.created_by,
note: note
).deliver_later
end
end

redirect_to(admin_publisher_path(publisher.id))
else
redirect_to admin_publisher_path(publisher.id), flash: { alert: note.errors.full_messages.join(',') }
end
end

def update
if @note.update(note_params)
email_tagged_users(@note)

redirect_to admin_publisher_path(id: params[:publisher_id]), flash: { success: "Successfully updated comment" }
else
redirect_to admin_publisher_path(id: params[:publisher_id]), flash: { alert: @note.errors.full_messages.join(',') }
end
end

def destroy
publisher = @note.publisher
if @note.comments.any?
redirect_to admin_publisher_path(publisher), flash: { alert: "Can't delete a note that has comments." }
else
@note.destroy

redirect_to admin_publisher_path(publisher)
end
end

private

def email_tagged_users(publisher_note)
publisher_note.note.scan(/\@(\w*)/).uniq.each do |mention|
# Some reason the regex likes to put an array inside array
mention = mention[0]
publisher = Publisher.where("email LIKE ?", mention + EMAIL).first
InternalMailer.tagged_in_note(tagged_user: publisher, note: publisher_note).deliver_later if publisher.present?
end
end

def authorize
@note = PublisherNote.find(params[:id])
raise unless @note.created_by == current_user
end

def note_params
params.require(:publisher_note).permit(:note, :thread_id)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
class Admin::Publishers::PublisherStatusUpdatesController < Admin::PublishersController
def index
get_publisher
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard"}).to_json
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard" }).to_json
@publisher_status_updates = @publisher.status_updates
end

def create
@publisher.status_updates.create(status: params[:publisher_status])
if params[:note].present?
@publisher.notes.create(note: params[:note], created_by_id: current_publisher.id)
end
note = @publisher.notes.create(note: params[:note], created_by_id: current_publisher.id)
@publisher.status_updates.create(status: params[:publisher_status], publisher_note: note)
@publisher.reload

# TODO: Send emails for other manual status updates, and send email without creating a status update
Expand Down
26 changes: 18 additions & 8 deletions app/controllers/admin/publishers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,38 @@ def index
@publishers = @publishers.where(search_sql, search_query: search_query)
end

@publishers = @publishers.suspended if params[:suspended].present?
if params[:status].present? && PublisherStatusUpdate::ALL_STATUSES.include?(params[:status])
# Effectively sanitizes the users input
method = PublisherStatusUpdate::ALL_STATUSES.detect { |x| x == params[:status] }
@publishers = @publishers.send(method)
end

if params[:role].present?
@publishers = @publishers.where(role: params[:role])
end

if params[:two_factor_authentication_removal].present?
@publishers = @publishers.joins(:two_factor_authentication_removal).distinct
end
@publishers = @publishers.where.not(email: nil).or(@publishers.where.not(pending_email: nil)) # Don't include deleted users
@publishers = @publishers.group(:id).paginate(page: params[:page])

respond_to do |format|
format.json { render json: @publishers.to_json({ methods: :avatar_color }) }
format.html {}
end
end

def show
@publisher = Publisher.find(params[:id])
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard"}).to_json
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard" }).to_json
@potential_referral_payment = @publisher.most_recent_potential_referral_payment
@note = PublisherNote.new
@current_user = current_user
end

def edit
@publisher = Publisher.find(params[:id])
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard"}).to_json
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard" }).to_json
end

def update
Expand Down Expand Up @@ -96,10 +110,6 @@ def get_publisher
@publisher = Publisher.find(params[:publisher_id] || params[:id])
end

def publisher_create_note_params
params.require(:publisher_note).permit(:publisher, :note)
end

def admin_approval_channel_params
params.require(:channel_id)
end
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/api/v1/stats/publishers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ def channel_uphold_and_email_verified_signups_per_day
render(json: fill_in_blank_dates(result).to_json, status: 200)
end

def channel_and_kyc_uphold_and_email_verified_signups_per_day
sql =
"""
select p.created_at::date, count(*)
from (
select distinct publishers.*
from publishers
inner join channels
on channels.publisher_id = publishers.id and channels.verified = true
inner join uphold_connections
on uphold_connections.publisher_id = publishers.id
where role = 'publisher'
and uphold_connections.uphold_verified = true
and uphold_connections.is_member = true
and email is not null
) as p
group by p.created_at::date
order by p.created_at::date
"""
result = ActiveRecord::Base.connection.execute(sql).values
render(json: fill_in_blank_dates(result).to_json, status: 200)
end

def totals
if params[:up_to_date].present?
up_to_date = Date.parse(params[:up_to_date])
Expand Down
Loading

0 comments on commit 2db717b

Please sign in to comment.