diff --git a/app/models/tag.rb b/app/models/tag.rb
index fe4e5c5..c8f5456 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -1,10 +1,19 @@
class Tag < ActiveRecord::Base
attr_accessor :filtered_count
- def self.all_with_filtered_counts
+ # Scope to determine what tags a user can see
+ scope :accessible_to, ->(user) do
+ if user.is_admin?
+ all
+ else
+ where(:private => false)
+ end
+ end
+
+ def self.all_with_filtered_counts(user)
counts = TagFilter.count(:group => "tag_id")
- Tag.order(:tag).all.map{|t|
+ Tag.order(:tag).accessible_to(user).map{|t|
t.filtered_count = counts[t.id].to_i
t
}
diff --git a/app/views/filters/index.html.erb b/app/views/filters/index.html.erb
index 44f2b74..8f9c587 100644
--- a/app/views/filters/index.html.erb
+++ b/app/views/filters/index.html.erb
@@ -15,7 +15,7 @@
Tag |
Description |
- <% Tag.all(:order => :tag).each do |tag| %>
+ <% Tag.order(:tag).accessible_to(@user).each do |tag| %>
"required",
:style => "line-height: 2.3em;" %>
<%= f.select "tags_a", options_for_select(
- Tag.all_with_filtered_counts.map{|t|
+ Tag.all_with_filtered_counts(@user).map{|t|
[ "#{t.tag} - #{t.description}", t.tag, { "data-html" => raw("") +
t.tag + raw(" - ") + t.description.to_s +
(t.filtered_count == 0 ? "" :
diff --git a/db/migrate/20120919195401_private_tags.rb b/db/migrate/20120919195401_private_tags.rb
new file mode 100644
index 0000000..8352cc1
--- /dev/null
+++ b/db/migrate/20120919195401_private_tags.rb
@@ -0,0 +1,15 @@
+class PrivateTags < ActiveRecord::Migration
+ def up
+ add_column :tags, :private, :boolean, :default => false
+
+ # All existing tags should be public by default
+ Tag.all.each do |t|
+ t.private = false
+ t.save
+ end
+ end
+
+ def down
+ remove_column :tags, :private
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 00a5690..6797a05 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120918152116) do
+ActiveRecord::Schema.define(:version => 20120919195401) do
create_table "comments", :force => true do |t|
t.datetime "created_at", :null => false
@@ -115,6 +115,7 @@ ActiveRecord::Schema.define(:version => 20120918152116) do
t.string "tag", :limit => 25, :default => "", :null => false
t.string "description", :limit => 100
t.boolean "filtered_by_default", :default => false
+ t.boolean "private", :default => false
end
add_index "tags", ["tag"], :name => "tag", :unique => true
|