CDB-2891 Another Table to Vis collection load change + removed unneeded Table methods

pull/567/head
Kartones 10 years ago
parent cf626a9933
commit ece96d8686

1
.gitignore vendored

@ -47,3 +47,4 @@ lib/build/dist
lib/build/node_modules
lib/build/grunt-aws.json
lib/build/app_config.js
rubygems

@ -28,8 +28,21 @@ class Admin::TablesController < ApplicationController
end
def public
@table = nil
@subdomain = CartoDB.extract_subdomain(request)
@table = Table.find_by_id_subdomain(@subdomain, params[:id])
viewed_user = User.find(:username => @subdomain)
if viewed_user
table = Table.where(id: params[:id]).first
unless table.nil?
vis = CartoDB::Visualization::Collection.new.fetch(
user_id: viewed_user.id,
map_id: table.map_id,
type: CartoDB::Visualization::Member::CANONICAL_TYPE
).first
@table = vis.table unless vis.nil?
end
end
# Has quite strange checks to see if a user can access a public table
if @table.blank? || @table.private? || ((current_user && current_user.id != @table.user_id) && @table.private?)

@ -71,9 +71,16 @@ class Api::Json::VisualizationsController < Api::ApplicationController
current_user, source, name_candidate
).copy
elsif params[:tables]
tables = params[:tables].map do |table_name|
::Table.find_by_name_subdomain(CartoDB.extract_subdomain(request), table_name)
end
viewed_user = User.find(:username => CartoDB.extract_subdomain(request))
tables = params[:tables].map { |table_name|
if viewed_user
Visualization::Collection.new.fetch(
name: table_name,
user_id: viewed_user.id,
type: CartoDB::Visualization::Member::CANONICAL_TYPE
).map { |vis| vis.table }
end
}.flatten
blender = Visualization::TableBlender.new(current_user, tables)
map = blender.blend
member = Visualization::Member.new(

@ -1150,20 +1150,6 @@ class Table < Sequel::Model(:user_tables)
table
end
def self.find_by_name_subdomain(subdomain, table_name)
user = User.find(:username => subdomain)
if user
Table.where(:name => table_name, :user_id => user.id).first
end
end
def self.find_by_id_subdomain(subdomain, table_id)
user = User.find(:username => subdomain)
if user
Table.where(:id => table_id, :user_id => user.id).first
end
end
def oid
@oid ||= owner.in_database["SELECT '#{qualified_table_name}'::regclass::oid"].first[:oid]
end

@ -1811,33 +1811,6 @@ describe Table do
Table.find_by_identifier(666, table.name)
}.should raise_error
end
it "should be able to be found from username and id" do
delete_user_data @user
data_import = DataImport.create( :user_id => @user.id,
:table_name => 'esp_adm1',
:data_source => '/../db/fake_data/with_cartodb_id.csv' )
data_import.run_import!
table = Table[data_import.table_id]
table.should_not be_nil, "Import failure: #{data_import.log}"
new_table = Table.find_by_id_subdomain(@user.username, table.id)
new_table.id.should == table.id
end
it "should not be able to be found from blank subdomain and id" do
delete_user_data @user
data_import = DataImport.create( :user_id => @user.id,
:table_name => 'esp_adm1',
:data_source => '/../db/fake_data/with_cartodb_id.csv' )
data_import.run_import!
table = Table[data_import.table_id]
table.should_not be_nil, "Import failure: #{data_import.log}"
new_table = Table.find_by_id_subdomain(nil, table.id)
new_table.should == nil
end
end
describe '#has_index?' do

Loading…
Cancel
Save