From b1e7d72e5bf0efad091df78d1e5f3732532077d9 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Mon, 17 Feb 2020 17:53:10 +0100 Subject: [PATCH] remove Tag --- app/models/carto/tag.rb | 1 + app/models/table.rb | 8 ++++---- app/models/tag.rb | 12 ------------ app/models/user.rb | 20 -------------------- app/models/visualization/tags.rb | 8 ++++---- spec/models/table_spec.rb | 16 ++++++++-------- spec/support/factories/tags.rb | 2 +- 7 files changed, 18 insertions(+), 49 deletions(-) delete mode 100644 app/models/tag.rb diff --git a/app/models/carto/tag.rb b/app/models/carto/tag.rb index fb463d8e8b..bff549276f 100644 --- a/app/models/carto/tag.rb +++ b/app/models/carto/tag.rb @@ -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 diff --git a/app/models/table.rb b/app/models/table.rb index 13a54558d6..388addc48d 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb deleted file mode 100644 index 2dcb1ccb5a..0000000000 --- a/app/models/tag.rb +++ /dev/null @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index fdc9000780..29563bc7aa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/visualization/tags.rb b/app/models/visualization/tags.rb index fbf6d6f1e4..8dba0a4420 100644 --- a/app/models/visualization/tags.rb +++ b/app/models/visualization/tags.rb @@ -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 diff --git a/spec/models/table_spec.rb b/spec/models/table_spec.rb index 9cf76d4f1c..2471407060 100644 --- a/spec/models/table_spec.rb +++ b/spec/models/table_spec.rb @@ -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 diff --git a/spec/support/factories/tags.rb b/spec/support/factories/tags.rb index b03dddb8b4..5f3b5788a2 100644 --- a/spec/support/factories/tags.rb +++ b/spec/support/factories/tags.rb @@ -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