|
|
|
@ -81,7 +81,23 @@ class Api::Json::TablesController < Api::ApplicationController
|
|
|
|
|
def update
|
|
|
|
|
warnings = []
|
|
|
|
|
|
|
|
|
|
@table.set_all(params)
|
|
|
|
|
# Perform name validations
|
|
|
|
|
# TODO move this to the model!
|
|
|
|
|
unless params[:name].nil?
|
|
|
|
|
if params[:name].downcase != @table.name
|
|
|
|
|
owner = User.select(:id,:database_name,:crypted_password,:quota_in_bytes,:username, :private_tables_enabled, :table_quota).filter(:id => current_user.id).first
|
|
|
|
|
if params[:name] =~ /^[0-9_]/
|
|
|
|
|
raise "Table names can't start with numbers or dashes."
|
|
|
|
|
elsif owner.tables.filter(:name.like(/^#{params[:name]}/)).select_map(:name).include?(params[:name].downcase)
|
|
|
|
|
raise "Table '#{params[:name].downcase}' already exists."
|
|
|
|
|
else
|
|
|
|
|
@table.set_all(:name => params[:name].downcase)
|
|
|
|
|
@table.save(:name)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@table.set_except(params, :name)
|
|
|
|
|
if params.keys.include?("latitude_column") && params.keys.include?("longitude_column")
|
|
|
|
|
latitude_column = params[:latitude_column] == "nil" ? nil : params[:latitude_column].try(:to_sym)
|
|
|
|
|
longitude_column = params[:longitude_column] == "nil" ? nil : params[:longitude_column].try(:to_sym)
|
|
|
|
@ -94,18 +110,6 @@ class Api::Json::TablesController < Api::ApplicationController
|
|
|
|
|
from user_tables
|
|
|
|
|
where id=?",@table.id).first
|
|
|
|
|
|
|
|
|
|
# wont allow users to set a table to same name, sends error
|
|
|
|
|
unless params[:name].blank?
|
|
|
|
|
if params[:name].downcase != @table.name
|
|
|
|
|
owner = User.select(:id,:database_name,:crypted_password,:quota_in_bytes,:username, :private_tables_enabled, :table_quota).filter(:id => current_user.id).first
|
|
|
|
|
if params[:name][0].match(/[^0-9]/).nil?
|
|
|
|
|
warnings << "Table names can't start with a number."
|
|
|
|
|
elsif owner.tables.filter(:name.like(/^#{params[:name]}/)).select_map(:name).include?(params[:name].downcase)
|
|
|
|
|
#raise "Table name already exists"
|
|
|
|
|
warnings << "Table '#{params[:name].downcase}' already existed"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render_jsonp(@table.public_values.merge(warnings: warnings))
|
|
|
|
|
else
|
|
|
|
|
render_jsonp({ :errors => @table.errors.full_messages}, 400)
|
|
|
|
|