Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/brave rewards ui rebase2 #1162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
04ba6a6
Migration for SiteBanner
yachtcaptain23 Aug 10, 2018
4dfadcc
Include social links and donation amounts
yachtcaptain23 Aug 27, 2018
6b20c03
Brave Rewards Integration
yachtcaptain23 Jul 31, 2018
59e7d13
Remove commented code
yachtcaptain23 Sep 11, 2018
0f69b44
Fix broken headers for editing contact info
yachtcaptain23 Sep 13, 2018
5316d07
Test to make sure instant donation button is only there for whitelisted
yachtcaptain23 Sep 17, 2018
ed1c97a
Test for saving a site banner
yachtcaptain23 Sep 17, 2018
6979ddb
Use the latest chromedriver-helper to resolve travis install
yachtcaptain23 Sep 18, 2018
9dc5778
Update the channels json
yachtcaptain23 Sep 18, 2018
367975a
Add BRAVE_REWARDS_EMAIL_WHITELIST to base.yml for docker users
nvonpentz Sep 18, 2018
160467f
Fix instant donation modal
nvonpentz Sep 18, 2018
2a503f5
Merge pull request #7 from nvonpentz/brave-rewards/add-envar
yachtcaptain23 Sep 18, 2018
8cdc4f6
Merge pull request #8 from nvonpentz/brave-rewards/fix/instant-donati…
yachtcaptain23 Sep 18, 2018
6439374
Use S3 bucket specified by ENV
yachtcaptain23 Sep 18, 2018
f583149
Use Rails.application.secrets
yachtcaptain23 Sep 18, 2018
ca34e5c
Don't lock the ts-loader and brave-ui packages
yachtcaptain23 Sep 18, 2018
a91ea90
Pending Tests: Cannot upload image
yachtcaptain23 Sep 18, 2018
d199dc3
Disable fade as this prevents new uploads for background image
yachtcaptain23 Sep 18, 2018
556b0e7
Merge pull request #9 from yachtcaptain23/feature/url_s3_brave_rewards
yachtcaptain23 Sep 18, 2018
f8dc6b9
Test image upload and disallow files too large
yachtcaptain23 Sep 18, 2018
203b088
Don't hard lock brave-ui
yachtcaptain23 Sep 18, 2018
56e5910
Fixes social links. Improved testing to use fixtures.
yachtcaptain23 Sep 19, 2018
db7c46e
Merge pull request #10 from yachtcaptain23/feature/security_fixes_ins…
yachtcaptain23 Sep 19, 2018
6f668e1
Indicate editable content
dlipeles Sep 19, 2018
1a576f5
Revert "Indicate editable content"
dlipeles Sep 19, 2018
43c9811
Indicate editable content
dlipeles Sep 19, 2018
00ba18c
Merge pull request #11 from dlipeles/indicate-editable-content
yachtcaptain23 Sep 19, 2018
799bd93
Don't include unused locale
yachtcaptain23 Sep 19, 2018
66c4706
Remove deadcode
yachtcaptain23 Sep 19, 2018
26e4a12
Fixes background image effect
dlipeles Sep 19, 2018
68d8fb0
Merge pull request #12 from dlipeles/patch/image-effect
yachtcaptain23 Sep 19, 2018
b44b4bd
Editing mode to preview
dlipeles Sep 20, 2018
c6047b5
Merge pull request #14 from dlipeles/patch/editing-to-preview
yachtcaptain23 Sep 21, 2018
fa51e61
Merge branch 'staging' into feature/brave_rewards_ui_rebase2
yachtcaptain23 Sep 29, 2018
a135e81
Initial commit, rewards banner overhaul
dlipeles Sep 26, 2018
a91d37e
Add intro, social links update, cleanup controller
dlipeles Sep 27, 2018
3573733
Numerical values only for donations, fix bottom padding for rewards b…
dlipeles Sep 27, 2018
a346724
Image cropping / Retina support for logo
dlipeles Sep 28, 2018
1a01c39
Retina mobile support, automatic cropping
dlipeles Sep 28, 2018
cf30298
Fix image issues for local files
yachtcaptain23 Sep 29, 2018
4509679
Merge pull request #17 from yachtcaptain23/site-banner-overhaul-rebase
yachtcaptain23 Sep 29, 2018
410ff60
Restores modal to original size
dlipeles Oct 1, 2018
8561b00
Continue checking against uploads of large image sizes
yachtcaptain23 Oct 1, 2018
841b573
Merge pull request #18 from dlipeles/feature/rewards-banner
yachtcaptain23 Oct 1, 2018
1cf4841
Include mini_magick
yachtcaptain23 Sep 20, 2018
6d32826
Convert to single image size
yachtcaptain23 Sep 21, 2018
326f9eb
Initial commit for site banner resizing logic
yachtcaptain23 Sep 24, 2018
6692337
Fix background saving by limiting file size
yachtcaptain23 Sep 25, 2018
e82e3dc
Add tests for padding logo. Increased number of resizing loops
yachtcaptain23 Sep 25, 2018
419028e
Test to make sure hashing is always consistent
yachtcaptain23 Sep 26, 2018
ed19b8a
Improved padding calculation for image conversion.
yachtcaptain23 Sep 27, 2018
07d7abf
Handle cases of file sizes being too big
yachtcaptain23 Sep 27, 2018
de107af
Document file size limits for the site banner
yachtcaptain23 Sep 27, 2018
bef7467
Change resolution for publisher's logo to 240x240
yachtcaptain23 Sep 27, 2018
1e20f8f
Ignore .DS_STORE file
yachtcaptain23 Oct 1, 2018
2ca0dc6
Support upscaled image size
yachtcaptain23 Oct 1, 2018
821b892
Merge pull request #15 from yachtcaptain23/feature/resize_images
yachtcaptain23 Oct 1, 2018
2ad4fb4
Fixes modal expansion bug
dlipeles Oct 1, 2018
a1c0a28
Merge pull request #19 from dlipeles/feature/rewards-banner
yachtcaptain23 Oct 1, 2018
c52a014
Fix file size restriction and logo image restrictions
yachtcaptain23 Oct 1, 2018
59c9344
Merge pull request #20 from yachtcaptain23/bugfix/brave_rewards_file_…
yachtcaptain23 Oct 1, 2018
fc4ae8d
Fix extension to use image/jpg instead of image/jpeg
yachtcaptain23 Oct 1, 2018
6cdd5c4
Remove debug statement
yachtcaptain23 Oct 1, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}]
[
"env",
{
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}
],
"react"
],

"plugins": [
"syntax-dynamic-import",
"transform-object-rest-spread",
["transform-class-properties", { "spec": true }]
[
"transform-class-properties",
{
"spec": true
}
]
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ dump.rdb
yarn-error.log
.DS_Store

# Ignore assets stored in /storage
/storage

# Ignore Byebug command history file.
.byebug_history
/ssl/
Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ gem "attr_encrypted", "~> 3.1.0"
# Integration with Matomo Piwik
gem 'autometal-piwik', :require => 'piwik', git: "https://github.com/matomo-org/piwik-ruby-api.git", branch: "master"

# Use AWS gem for s3 uploads
gem 'aws-sdk-s3', require: false

gem "bootstrap", "~> 4.1.1"

# browser details
Expand Down Expand Up @@ -49,6 +52,9 @@ gem "nokogiri", "~> 1.8.4"
# Open Graph tag
gem "meta-tags"

# Image conversion library
gem 'mini_magick'

# Oauth client for google / youtube
gem "omniauth-google-oauth2", "~> 0.5.2"

Expand Down
21 changes: 20 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ GEM
encryptor (~> 3.0.0)
autoprefixer-rails (9.0.0)
execjs
aws-eventstream (1.0.1)
aws-partitions (1.104.0)
aws-sdk-core (3.27.0)
aws-eventstream (~> 1.0)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-kms (1.9.0)
aws-sdk-core (~> 3, >= 3.26.0)
aws-sigv4 (~> 1.0)
aws-sdk-s3 (1.19.0)
aws-sdk-core (~> 3, >= 3.26.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
aws-sigv4 (1.0.3)
bcrypt (3.1.12)
bindex (0.5.0)
bootstrap (4.1.3)
Expand Down Expand Up @@ -106,7 +121,7 @@ GEM
activesupport
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chromedriver-helper (1.2.0)
chromedriver-helper (2.0.1)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
chunky_png (1.3.10)
Expand Down Expand Up @@ -170,6 +185,7 @@ GEM
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jmespath (1.4.0)
json (2.1.0)
jsonapi-renderer (0.2.0)
jwt (1.5.6)
Expand All @@ -196,6 +212,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
mimemagic (0.3.2)
mini_magick (4.9.2)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
Expand Down Expand Up @@ -457,6 +474,7 @@ DEPENDENCIES
api-pagination
attr_encrypted (~> 3.1.0)
autometal-piwik!
aws-sdk-s3
bootstrap (~> 4.1.1)
brakeman
browser
Expand All @@ -476,6 +494,7 @@ DEPENDENCIES
listen (~> 3.0.5)
lograge (~> 0.4)
meta-tags
mini_magick
minitest-rails-capybara (~> 3.0.1)
mocha
newrelic_rpm (~> 3.16)
Expand Down
Binary file removed app/assets/images/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions app/assets/images/bg_bats.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/images/bg_hearts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/brave-lion@3x.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/camera@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/camera@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icn-donation-jar@1x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icn-donation-jar@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icn-donation-jar@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions app/assets/images/icn-editPhoto.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/san_francisco.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions app/assets/stylesheets/pages/home.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
.camera-background {
background-size: 60px 47px;
width: 60px;
height: 47px;
background-image: url(asset-path("camera@2x.png"));
background-color: transparent;
border-style: none;
}

#icn-donation-jar {
margin-bottom: 30px;
}

.brave-rewards-banner {
&--background {
&-label {
display: block;
margin-left: -4px;
margin-top: 5px;
font-size: 16px;
}

&-camera {
margin-left: 46%;
margin-top: -60px;
}
}
&--logo {
&-parent {
position: relative;
}

&-label {
display: block;
margin-left: -4px;
margin-top: 5px;
font-size: 16px;
}

&-no-attachment {
margin-left: 30%;
position: absolute;
}

&-camera {
margin-left: 30%;
margin-top: 30%;
position: absolute;
}
}
}

.nav {
display: block;

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/banners_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class BannersController < ApplicationController
def new
@publisher_id = current_publisher.id
end
end
105 changes: 105 additions & 0 deletions app/controllers/publishers/site_banners_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
class Publishers::SiteBannersController < ApplicationController
include ImageConversionHelper
before_action :authenticate_publisher!

MAX_IMAGE_SIZE = 10_000_000

def new
@site_banner = current_publisher.site_banner || SiteBanner.new
end

def create
site_banner = current_publisher.site_banner || SiteBanner.new
donation_amounts = JSON.parse(params[:donation_amounts])
site_banner.update(
publisher_id: current_publisher.id,
title: params[:title],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we verify these params anywhere?

donation_amounts: donation_amounts,
default_donation: donation_amounts.second,
social_links: params[:social_links].present? ? JSON.parse(params[:social_links]) : {},
description: params[:description]
)
head :ok
end

def fetch
site_banner = current_publisher.site_banner
data = JSON.parse(site_banner.to_json)
data[:backgroundImage] = current_publisher.site_banner.read_only_react_property[:backgroundUrl]
data[:logoImage] = current_publisher.site_banner.read_only_react_property[:logoUrl]
render(json: data.to_json)
end

def update_logo
if params[:image].length > MAX_IMAGE_SIZE
# (Albert Wang): We should consider supporting alerts. This might require a UI redesign
# alert[:error] = "File size too big!"
head :payload_too_large and return
end
site_banner = current_publisher.site_banner
update_image(attachment: site_banner.logo, attachment_type: SiteBanner::LOGO)
head :ok
end

def update_background_image
if params[:image].length > MAX_IMAGE_SIZE
# (Albert Wang): We should consider supporting alerts. This might require a UI redesign
# alert[:error] = "File size too big!"
head :payload_too_large and return
end
site_banner = current_publisher.site_banner
update_image(attachment: site_banner.background_image, attachment_type: SiteBanner::BACKGROUND)
head :ok
end

private

def update_image(attachment:, attachment_type:)
data_url = params[:image].split(',')[0]
if data_url.starts_with?("data:image/jpeg")
content_type = "image/jpeg"
extension = ".jpg"
elsif data_url.starts_with?("data:image/png")
content_type = "image/png"
extension = ".png"
elsif data_url.starts_with?("data:image/bmp")
content_type = "image/bmp"
extension = ".bmp"
else
LogException.perform(StandardError.new("Unknown image format:" + data_url), params: {})
return nil
end
filename = Time.now.to_s.gsub!(" ", "_").gsub!(":", "_") + current_publisher.id

temp_file = Tempfile.new([filename, extension])
File.open(temp_file.path, 'wb') do |f|
f.write(Base64.decode64(params[:image].split(',')[1]))
end

original_image_path = temp_file.path

resized_jpg_path = resize_to_dimensions_and_convert_to_jpg(
source_image_path: original_image_path,
attachment_type: attachment_type,
filename: filename
)

begin
padded_resized_jpg_path = add_padding_to_image(
source_image_path: resized_jpg_path,
attachment_type: attachment_type,
)
rescue OutsidePaddingRangeError
logger.error "Outside padding range"
LogException.perform(StandardError.new("File size too big for #{attachment_type}"), params: {publisher_id: current_publisher.id})
end

new_filename = generate_filename(source_image_path: padded_resized_jpg_path)

attachment.attach(
io: open(padded_resized_jpg_path),
filename: new_filename + ".jpg",
content_type: "image/jpg"
)
end
end
14 changes: 7 additions & 7 deletions app/controllers/publishers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ def update
end

respond_to do |format|
format.json {
if success
head :no_content
else
render(json: { errors: publisher.errors }, status: 400)
end
}
if success
format.json { head :no_content }
format.html { redirect_to home_publishers_path }
else
format.json { render(json: { errors: publisher.errors }, status: 400) }
format.html { render(status: 400) }
end
end
end

Expand Down
Loading