add Tag.active scope to deprecate tags without removing them
This commit is contained in:
parent
d75242f646
commit
95202f21b2
|
@ -5,7 +5,7 @@ class FiltersController < ApplicationController
|
|||
@cur_url = "/filters"
|
||||
@title = "Filtered Tags"
|
||||
|
||||
@tags = Tag.all_with_story_counts_for(@user)
|
||||
@tags = Tag.active.all_with_story_counts_for(@user)
|
||||
|
||||
if @user
|
||||
@filtered_tags = @user.tag_filter_tags.to_a
|
||||
|
@ -16,7 +16,8 @@ class FiltersController < ApplicationController
|
|||
|
||||
def update
|
||||
tags_param = params[:tags]
|
||||
new_tags = tags_param.blank? ? [] : Tag.where(:tag => tags_param).to_a
|
||||
new_tags = tags_param.blank? ? [] :
|
||||
Tag.active.where(:tag => tags_param).to_a
|
||||
new_tags.keep_if {|t| t.valid_for? @user }
|
||||
|
||||
if @user
|
||||
|
|
|
@ -149,6 +149,9 @@ class Story < ActiveRecord::Base
|
|||
if !t.tag.valid_for?(self.user)
|
||||
raise "#{self.user.username} does not have permission to use " <<
|
||||
"privileged tag #{t.tag.tag}"
|
||||
elsif t.tag.inactive? && !t.new_record?
|
||||
# stories can have inactive tags as long as they existed before
|
||||
raise "#{self.user.username} cannot add inactive tag #{t.tag.tag}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -336,7 +339,7 @@ class Story < ActiveRecord::Base
|
|||
|
||||
new_tag_names_a.each do |tag_name|
|
||||
if tag_name.to_s != "" && !self.tags.exists?(:tag => tag_name)
|
||||
if t = Tag.where(:tag => tag_name).first
|
||||
if t = Tag.active.where(:tag => tag_name).first
|
||||
# we can't lookup whether the user is allowed to use this tag yet
|
||||
# because we aren't assured to have a user_id by now; we'll do it in
|
||||
# the validation with check_tags
|
||||
|
|
|
@ -10,6 +10,8 @@ class Tag < ActiveRecord::Base
|
|||
user && user.is_moderator?? all : where(:privileged => false)
|
||||
end
|
||||
|
||||
scope :active, -> { where(:inactive => false) }
|
||||
|
||||
def to_param
|
||||
self.tag
|
||||
end
|
||||
|
@ -17,7 +19,7 @@ class Tag < ActiveRecord::Base
|
|||
def self.all_with_filtered_counts_for(user)
|
||||
counts = TagFilter.group(:tag_id).count
|
||||
|
||||
Tag.order(:tag).accessible_to(user).map{|t|
|
||||
Tag.active.order(:tag).accessible_to(user).map{|t|
|
||||
t.filtered_count = counts[t.id].to_i
|
||||
t
|
||||
}
|
||||
|
@ -26,7 +28,7 @@ class Tag < ActiveRecord::Base
|
|||
def self.all_with_story_counts_for(user)
|
||||
counts = Tagging.group(:tag_id).count
|
||||
|
||||
Tag.order(:tag).accessible_to(user).map{|t|
|
||||
Tag.active.order(:tag).accessible_to(user).map{|t|
|
||||
t.stories_count = counts[t.id].to_i
|
||||
t
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def most_common_story_tag
|
||||
Tag.joins(
|
||||
Tag.active.joins(
|
||||
:stories
|
||||
).where(
|
||||
:stories => { :user_id => self.id }
|
||||
|
|
5
db/migrate/20140221164400_inactive_tags.rb
Normal file
5
db/migrate/20140221164400_inactive_tags.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class InactiveTags < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :tags, :inactive, :boolean, :default => false
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20140219183804) do
|
||||
ActiveRecord::Schema.define(version: 20140221164400) do
|
||||
|
||||
create_table "comments", force: true do |t|
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -107,6 +107,7 @@ ActiveRecord::Schema.define(version: 20140219183804) do
|
|||
|
||||
add_index "stories", ["hotness"], name: "hotness_idx", using: :btree
|
||||
add_index "stories", ["is_expired", "is_moderated"], name: "is_idxes", using: :btree
|
||||
add_index "stories", ["short_id"], name: "short_id", unique: true, using: :btree
|
||||
add_index "stories", ["url"], name: "url", length: {"url"=>191}, using: :btree
|
||||
|
||||
create_table "tag_filters", force: true do |t|
|
||||
|
@ -130,6 +131,7 @@ ActiveRecord::Schema.define(version: 20140219183804) do
|
|||
t.string "description", limit: 100
|
||||
t.boolean "privileged", default: false
|
||||
t.boolean "is_media", default: false
|
||||
t.boolean "inactive", default: false
|
||||
end
|
||||
|
||||
add_index "tags", ["tag"], name: "tag", unique: true, using: :btree
|
||||
|
|
Loading…
Reference in a new issue