kuviz assets service to html assets service

pull/15595/head
Simon Martín 5 years ago
parent 9dbb1f4efa
commit 5d210a0fbf

@ -336,7 +336,7 @@ SPEC_HELPER_MIN_SPECS = \
spec/requests/carto/api/organization_assets_controller_spec.rb \
spec/lib/carto/assets/image_assets_service_spec.rb \
spec/lib/carto/assets/organization_image_assets_service_spec.rb \
spec/lib/carto/assets/kuviz_assets_service_spec.rb \
spec/lib/carto/assets/html_assets_service_spec.rb \
spec/lib/carto/storage_options/local_spec.rb \
spec/lib/carto/visualization_invalidation_service_spec.rb \
spec/lib/tasks/layers_rake_spec.rb \

@ -15,7 +15,7 @@ module Carto
def show
return app_password_protected if show_password?
@source = KuvizAssetsService.instance.read_source_data(@app.asset)
@source = HTMLAssetsService.instance.read_source_data(@app.asset)
add_cache_headers
render layout: false
rescue StandardError => e
@ -33,7 +33,7 @@ module Carto
return app_password_protected
end
@source = KuvizAssetsService.instance.read_source_data(@app.asset)
@source = HTMLAssetsService.instance.read_source_data(@app.asset)
add_cache_headers
render 'show', layout: false

@ -15,7 +15,7 @@ module Carto
def show
return kuviz_password_protected if show_password?
@source = KuvizAssetsService.instance.read_source_data(@kuviz.asset)
@source = HTMLAssetsService.instance.read_source_data(@kuviz.asset)
add_cache_headers
render layout: false
rescue StandardError => e
@ -33,7 +33,7 @@ module Carto
return kuviz_password_protected
end
@source = KuvizAssetsService.instance.read_source_data(@kuviz.asset)
@source = HTMLAssetsService.instance.read_source_data(@kuviz.asset)
add_cache_headers
render 'show', layout: false

@ -1,6 +1,6 @@
require_dependency 'carto/assets/image_assets_service'
require_dependency 'carto/assets/organization_image_assets_service'
require_dependency 'carto/assets/kuviz_assets_service'
require_dependency 'carto/assets/html_assets_service'
module Carto
class Asset < ActiveRecord::Base
@ -31,16 +31,16 @@ module Carto
end
def self.for_visualization(visualization:, resource:)
storage_info, url = KuvizAssetsService.instance.upload(visualization, resource)
storage_info, url = HTMLAssetsService.instance.upload(visualization, resource)
new(visualization: visualization,
public_url: url,
storage_info: storage_info,
kind: 'kuviz_asset')
kind: 'html_asset')
end
def update_visualization_resource(resource)
storage_info, url = KuvizAssetsService.instance.upload(visualization, resource)
storage_info, url = HTMLAssetsService.instance.upload(visualization, resource)
self.public_url = url
self.storage_info = storage_info
save

@ -348,10 +348,10 @@ defaults: &defaults
# bucket: "tests" # Required if 'aws.s3' config is present. Bucket must exist beforehand. If no 'aws.s3' config is present, organization assets will be stored locally and this line is not needed.
# max_size_in_bytes: 1048576 # Optional, default is 1 MB
# location: 'organization_assets' # Optional subdirectory for local assets, default is 'organization_assets'
# kuviz:
# html:
# bucket: "tests" # Required if 'aws.s3' config is present. Bucket must exist beforehand. If no 'aws.s3' config is present, kuviz assets will be stored locally and this line is not needed.
# max_size_in_bytes: 1048576 # Optional, default is 1 MB
# location: 'kuviz_assets' # Optional subdirectory for local assets, default is 'kuviz_assets'
# location: 'html_assets' # Optional subdirectory for local assets, default is 'html_assets'
app_assets:
asset_host: "//cartodb-libs.global.ssl.fastly.net/cartodbui"
avatars:

@ -3,7 +3,7 @@ require_dependency 'carto/assets/assets_service'
require 'singleton'
module Carto
class KuvizAssetsService < AssetsService
class HTMLAssetsService < AssetsService
include Singleton
EXTENSION = ".html".freeze
@ -14,7 +14,7 @@ module Carto
end
def fetch_file(resource)
temp_file = Tempfile.new(["kuviz_asset_#{Time.now.utc.to_i}", EXTENSION])
temp_file = Tempfile.new(["html_asset_#{Time.now.utc.to_i}", EXTENSION])
begin
read = IO.copy_stream(resource, temp_file, max_size_in_bytes + 1)
@ -37,18 +37,18 @@ module Carto
end
end
DEFAULT_LOCATION = 'kuviz_assets'.freeze
DEFAULT_LOCATION = 'html_assets'.freeze
def location
@location ||= Cartodb.get_config(:assets, 'kuviz', 'bucket') ||
Cartodb.get_config(:assets, 'kuviz', 'location') ||
@location ||= Cartodb.get_config(:assets, 'html', 'bucket') ||
Cartodb.get_config(:assets, 'html', 'location') ||
DEFAULT_LOCATION
end
def max_size_in_bytes
return @max_size_in_bytes if @max_size_in_bytes
configured = Cartodb.get_config(:assets, 'kuviz', 'max_size_in_bytes')
configured = Cartodb.get_config(:assets, 'html', 'max_size_in_bytes')
@max_size_in_bytes = configured || DEFAULT_MAX_SIZE_IN_BYTES
end

@ -1 +1 @@
Subproject commit 998402e531c903352f16003efc2f25ef5e094019
Subproject commit 076cacc6f1b30c84d949d8041b7649ece585456a

@ -208,7 +208,7 @@ spec/models/carto/snapshot_spec.rb
spec/models/carto/legend_spec.rb
spec/lib/tasks/data_observatory_rake_spec.rb
spec/lib/carto/mapcapped_visualization_updater_spec.rb
spec/lib/carto/assets/kuviz_assets_service_spec.rb
spec/lib/carto/assets/html_assets_service_spec.rb
services/importer/spec/unit/runner_spec.rb
services/importer/spec/unit/georeferencer_spec.rb
services/importer/spec/unit/connector_spec.rb
@ -343,4 +343,4 @@ services/datasources/spec/integration/csv_file_dumper_spec.rb
services/datasources/spec/acceptance/gdrive_spec.rb
services/datasources/spec/acceptance/dropbox_spec.rb
services/dataservices-metrics/spec/unit/service_usage_metrics_spec.rb
spec/requests/api/json/imports_controller_spec.rb
spec/requests/api/json/imports_controller_spec.rb

@ -3,24 +3,24 @@ require 'spec_helper_min'
require_relative '../../../../app/controllers/carto/controller_helper'
require_relative '../../../../lib/carto/configuration'
describe Carto::KuvizAssetsService do
describe Carto::HTMLAssetsService do
after(:all) do
FileUtils.rmtree(Carto::Conf.new.public_uploads_path + '/kuviz_assets')
FileUtils.rmtree(Carto::Conf.new.public_uploads_path + '/html_assets')
end
describe('#fetch_file') do
it 'rejects files that are too big' do
max_size = Carto::KuvizAssetsService.instance.max_size_in_bytes
max_size = Carto::HTMLAssetsService.instance.max_size_in_bytes
IO.stubs(:copy_stream).returns(max_size + 1)
expect {
Carto::KuvizAssetsService.instance.fetch_file(StringIO.new('test'))
Carto::HTMLAssetsService.instance.fetch_file(StringIO.new('test'))
}.to raise_error(Carto::UnprocesableEntityError, "resource is too big (> #{max_size} bytes)")
end
it 'create a file has html extension' do
temp_file = Carto::KuvizAssetsService.instance.fetch_file(StringIO.new('test'))
temp_file = Carto::HTMLAssetsService.instance.fetch_file(StringIO.new('test'))
temp_file.path.should end_with '.html'
end
end
@ -28,7 +28,7 @@ describe Carto::KuvizAssetsService do
describe('#upload') do
it 'uploads file and stores in the local system' do
visualization = FactoryGirl.create(:carto_visualization)
storage_info, url = Carto::KuvizAssetsService.instance.upload(visualization, StringIO.new('test'))
storage_info, url = Carto::HTMLAssetsService.instance.upload(visualization, StringIO.new('test'))
storage_info.present?.should be true
url.present?.should be true
end

@ -17,7 +17,7 @@ describe Carto::Api::Public::CustomVisualizationsController do
after(:all) do
@user.destroy
FileUtils.rmtree(Carto::Conf.new.public_uploads_path + '/kuviz_assets')
FileUtils.rmtree(Carto::Conf.new.public_uploads_path + '/html_assets')
end
describe '#index' do

@ -6,7 +6,7 @@ describe Carto::Kuviz::VisualizationsController do
include Warden::Test::Helpers
after(:all) do
FileUtils.rmtree(Carto::Conf.new.public_uploads_path + '/kuviz_assets')
FileUtils.rmtree(Carto::Conf.new.public_uploads_path + '/html_assets')
end
describe '#show' do

Loading…
Cancel
Save