-
Notifications
You must be signed in to change notification settings - Fork 41
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
yachtcaptain23
merged 63 commits into
brave-intl:staging
from
yachtcaptain23:feature/brave_rewards_ui_rebase2
Oct 4, 2018
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
04ba6a6
Migration for SiteBanner
yachtcaptain23 4dfadcc
Include social links and donation amounts
yachtcaptain23 6b20c03
Brave Rewards Integration
yachtcaptain23 59e7d13
Remove commented code
yachtcaptain23 0f69b44
Fix broken headers for editing contact info
yachtcaptain23 5316d07
Test to make sure instant donation button is only there for whitelisted
yachtcaptain23 ed1c97a
Test for saving a site banner
yachtcaptain23 6979ddb
Use the latest chromedriver-helper to resolve travis install
yachtcaptain23 9dc5778
Update the channels json
yachtcaptain23 367975a
Add BRAVE_REWARDS_EMAIL_WHITELIST to base.yml for docker users
nvonpentz 160467f
Fix instant donation modal
nvonpentz 2a503f5
Merge pull request #7 from nvonpentz/brave-rewards/add-envar
yachtcaptain23 8cdc4f6
Merge pull request #8 from nvonpentz/brave-rewards/fix/instant-donati…
yachtcaptain23 6439374
Use S3 bucket specified by ENV
yachtcaptain23 f583149
Use Rails.application.secrets
yachtcaptain23 ca34e5c
Don't lock the ts-loader and brave-ui packages
yachtcaptain23 a91ea90
Pending Tests: Cannot upload image
yachtcaptain23 d199dc3
Disable fade as this prevents new uploads for background image
yachtcaptain23 556b0e7
Merge pull request #9 from yachtcaptain23/feature/url_s3_brave_rewards
yachtcaptain23 f8dc6b9
Test image upload and disallow files too large
yachtcaptain23 203b088
Don't hard lock brave-ui
yachtcaptain23 56e5910
Fixes social links. Improved testing to use fixtures.
yachtcaptain23 db7c46e
Merge pull request #10 from yachtcaptain23/feature/security_fixes_ins…
yachtcaptain23 6f668e1
Indicate editable content
dlipeles 1a576f5
Revert "Indicate editable content"
dlipeles 43c9811
Indicate editable content
dlipeles 00ba18c
Merge pull request #11 from dlipeles/indicate-editable-content
yachtcaptain23 799bd93
Don't include unused locale
yachtcaptain23 66c4706
Remove deadcode
yachtcaptain23 26e4a12
Fixes background image effect
dlipeles 68d8fb0
Merge pull request #12 from dlipeles/patch/image-effect
yachtcaptain23 b44b4bd
Editing mode to preview
dlipeles c6047b5
Merge pull request #14 from dlipeles/patch/editing-to-preview
yachtcaptain23 fa51e61
Merge branch 'staging' into feature/brave_rewards_ui_rebase2
yachtcaptain23 a135e81
Initial commit, rewards banner overhaul
dlipeles a91d37e
Add intro, social links update, cleanup controller
dlipeles 3573733
Numerical values only for donations, fix bottom padding for rewards b…
dlipeles a346724
Image cropping / Retina support for logo
dlipeles 1a01c39
Retina mobile support, automatic cropping
dlipeles cf30298
Fix image issues for local files
yachtcaptain23 4509679
Merge pull request #17 from yachtcaptain23/site-banner-overhaul-rebase
yachtcaptain23 410ff60
Restores modal to original size
dlipeles 8561b00
Continue checking against uploads of large image sizes
yachtcaptain23 841b573
Merge pull request #18 from dlipeles/feature/rewards-banner
yachtcaptain23 1cf4841
Include mini_magick
yachtcaptain23 6d32826
Convert to single image size
yachtcaptain23 326f9eb
Initial commit for site banner resizing logic
yachtcaptain23 6692337
Fix background saving by limiting file size
yachtcaptain23 e82e3dc
Add tests for padding logo. Increased number of resizing loops
yachtcaptain23 419028e
Test to make sure hashing is always consistent
yachtcaptain23 ed19b8a
Improved padding calculation for image conversion.
yachtcaptain23 07d7abf
Handle cases of file sizes being too big
yachtcaptain23 de107af
Document file size limits for the site banner
yachtcaptain23 bef7467
Change resolution for publisher's logo to 240x240
yachtcaptain23 1e20f8f
Ignore .DS_STORE file
yachtcaptain23 2ca0dc6
Support upscaled image size
yachtcaptain23 821b892
Merge pull request #15 from yachtcaptain23/feature/resize_images
yachtcaptain23 2ad4fb4
Fixes modal expansion bug
dlipeles a1c0a28
Merge pull request #19 from dlipeles/feature/rewards-banner
yachtcaptain23 c52a014
Fix file size restriction and logo image restrictions
yachtcaptain23 59c9344
Merge pull request #20 from yachtcaptain23/bugfix/brave_rewards_file_…
yachtcaptain23 fc4ae8d
Fix extension to use image/jpg instead of image/jpeg
yachtcaptain23 6cdd5c4
Remove debug statement
yachtcaptain23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?