Commit d229379459bce7a1d63ae51e7ebe65abdf385ef9
Committed by
Antonio Terceiro
1 parent
7ad15774
Exists in
master
and in
28 other branches
ActionItem1065: restricted articles to environment
in the search for tagged articles the results limits to the current environment's articles
Showing
3 changed files
with
25 additions
and
1 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -227,7 +227,7 @@ class SearchController < PublicController | @@ -227,7 +227,7 @@ class SearchController < PublicController | ||
227 | 227 | ||
228 | def tag | 228 | def tag |
229 | @tag = environment.tags.find_by_name(params[:tag]) | 229 | @tag = environment.tags.find_by_name(params[:tag]) |
230 | - @tagged = @tag.taggings.map(&:taggable) | 230 | + @tagged = environment.articles.find_tagged_with(@tag) |
231 | end | 231 | end |
232 | 232 | ||
233 | ####################################################### | 233 | ####################################################### |
app/models/article.rb
@@ -276,6 +276,10 @@ class Article < ActiveRecord::Base | @@ -276,6 +276,10 @@ class Article < ActiveRecord::Base | ||
276 | $1 | 276 | $1 |
277 | end | 277 | end |
278 | 278 | ||
279 | + def self.find_tagged_with(tag) | ||
280 | + self.find(:all, :include => :taggings, :conditions => ['taggings.tag_id = ?', tag.id]) | ||
281 | + end | ||
282 | + | ||
279 | private | 283 | private |
280 | 284 | ||
281 | def sanitize_tag_list | 285 | def sanitize_tag_list |
test/unit/article_test.rb
@@ -721,4 +721,24 @@ class ArticleTest < Test::Unit::TestCase | @@ -721,4 +721,24 @@ class ArticleTest < Test::Unit::TestCase | ||
721 | assert !a.highlighted | 721 | assert !a.highlighted |
722 | end | 722 | end |
723 | 723 | ||
724 | + should 'get tagged with tag' do | ||
725 | + a = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') | ||
726 | + t = a.tags[0] | ||
727 | + as = Article.find_tagged_with(t) | ||
728 | + | ||
729 | + assert_includes as, a | ||
730 | + end | ||
731 | + | ||
732 | + should 'not get tagged with tag from other environment' do | ||
733 | + a1 = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') | ||
734 | + e = Environment.create!(:name => 'other env') | ||
735 | + p = create_user('other_user', :environment => e).person | ||
736 | + a2 = Article.create!(:name => 'Published at', :profile => p, :tag_list => 'bli') | ||
737 | + t = a2.tags[0] | ||
738 | + as = e.articles.find_tagged_with(t) | ||
739 | + | ||
740 | + assert_includes as, a2 | ||
741 | + assert_not_includes as, a1 | ||
742 | + end | ||
743 | + | ||
724 | end | 744 | end |