pull/15489/head
Gonzalo Riestra 5 years ago
parent 10d7fb1cc1
commit b1e7d72e5b

@ -6,5 +6,6 @@ module Carto
belongs_to :user, class_name: Carto::User
belongs_to :user_table, class_name: Carto::UserTable, foreign_key: :table_id, primary_key: :table_id
validates :name, presence: true
end
end

@ -442,7 +442,7 @@ class Table
end
def after_destroy
Tag.filter(user_id: user_id, table_id: id).delete
Carto::Tag.where(user_id: user_id, table_id: id).each(&:destroy)
remove_table_from_stats
cache.del geometry_types_key
@ -1469,10 +1469,10 @@ class Table
def manage_tags
if @user_table[:tags].blank?
Tag.filter(:user_id => user_id, :table_id => id).delete
Carto::Tag.where(user_id: user_id, table_id: id).each(&:destroy)
else
tag_names = @user_table.tags.split(',')
table_tags = Tag.filter(:user_id => user_id, :table_id => id).all
table_tags = Carto::Tag.where(user_id: user_id, table_id: id).all
unless table_tags.empty?
# Remove tags that are not in the new names list
table_tags.each do |tag|
@ -1485,7 +1485,7 @@ class Table
end
# Create the new tags in the this table
tag_names.each do |new_tag_name|
new_tag = Tag.new :name => new_tag_name
new_tag = Carto::Tag.new(name: new_tag_name)
new_tag.user_id = user_id
new_tag.table_id = id
new_tag.save

@ -1,12 +0,0 @@
# This class currently doesn't serve any purpose except pure data storage
class Tag < Sequel::Model
# Ignore mass-asigment on not allowed columns
self.strict_param_setting = false
set_allowed_columns(:name)
def validate
super
errors.add(:name, "can't be blank") if name.blank?
end
end

@ -794,26 +794,6 @@ class User < Sequel::Model
end)))
end
# List all public visualization tags of the user
def tags(exclude_shared = false, type = Carto::Visualization::TYPE_DERIVED)
require_relative './visualization/tags'
options = {}
options[:exclude_shared] = true if exclude_shared
CartoDB::Visualization::Tags.new(self, options).names({
type: type,
privacy: Carto::Visualization::PRIVACY_PUBLIC
})
end #tags
# List all public map tags of the user
def map_tags
require_relative './visualization/tags'
CartoDB::Visualization::Tags.new(self).names({
type: Carto::Visualization::TYPE_CANONICAL,
privacy: Carto::Visualization::PRIVACY_PUBLIC
})
end #map_tags
def tables
::UserTable.filter(:user_id => self.id).order(:id).reverse
end

@ -17,7 +17,7 @@ module CartoDB
if filter.empty?
return []
else
Tag.fetch(%Q{
Carto::Tag.find_by_sql(%Q{
SELECT DISTINCT (unnest(tags)) as name
FROM visualizations
WHERE #{shared_entities_sql_filter(params)}
@ -29,7 +29,7 @@ module CartoDB
).map{ |tag| tag.name}
end
else
Tag.fetch(%Q{
Carto::Tag.find_by_sql(%Q{
SELECT DISTINCT (unnest(tags)) as name
FROM visualizations
WHERE user_id = ?
@ -49,7 +49,7 @@ module CartoDB
if filter.empty?
return []
else
Tag.fetch(%Q{
Carto::Tag.find_by_sql(%Q{
WITH tags as (
SELECT unnest(tags) as name
FROM visualizations
@ -66,7 +66,7 @@ module CartoDB
).all.map(&:values)
end
else
Tag.fetch(%Q{
Carto::Tag.find_by_sql(%Q{
WITH tags as (
SELECT unnest(tags) as name
FROM visualizations

@ -707,7 +707,7 @@ describe Table do
it "should update denormalized counters" do
@user.reload
Tag.count.should == 0
Carto::Tag.count.should == 0
UserTable.count == 0
end
@ -732,31 +732,31 @@ describe Table do
delete_user_data @user
table = create_table :user_id => @user.id, :tags => "tag 1, tag 2,tag 3, tag 3"
Tag.count.should == 3
Carto::Tag.count.should == 3
tag1 = Tag[:name => 'tag 1']
tag1 = Carto::Tag.where(name: 'tag 1').first
tag1.user_id.should == @user.id
tag1.table_id.should == table.id
tag2 = Tag[:name => 'tag 2']
tag2 = Carto::Tag.where(name: 'tag 2').first
tag2.user_id.should == @user.id
tag2.table_id.should == table.id
tag3 = Tag[:name => 'tag 3']
tag3 = Carto::Tag.where(name: 'tag 3').first
tag3.user_id.should == @user.id
tag3.table_id.should == table.id
table.tags = "tag 1"
table.save_changes
Tag.count.should == 1
tag1 = Tag[:name => 'tag 1']
Carto::Tag.count.should == 1
tag1 = Carto::Tag.where(name: 'tag 1').first
tag1.user_id.should == @user.id
tag1.table_id.should == table.id
table.tags = " "
table.save_changes
Tag.count.should == 0
Carto::Tag.count.should == 0
end
it "can add a column of a CartoDB::TYPE type" do

@ -18,7 +18,7 @@ module CartoDB
else
attributes.delete(:table_id)
end
Tag.new(attributes)
Carto::Tag.new(attributes)
tag.user_id = user_id
tag.table_id = table_id
tag

Loading…
Cancel
Save