Commit 2b5371400158fa633d1b35fd366f63e9840ede09
1 parent
7326693e
Exists in
master
and in
23 other branches
Revert "Listing folder items"
This reverts commit d0f8d245c7304e20f86be76e84de59e62f30c889.
Showing
6 changed files
with
25 additions
and
93 deletions
Show diff stats
app/helpers/folder_helper.rb
| 1 | 1 | module FolderHelper |
| 2 | 2 | |
| 3 | - def list_articles(articles, user, recursive = false) | |
| 4 | - if !articles.blank? | |
| 5 | - content_tag( | |
| 6 | - 'table', | |
| 7 | - content_tag('tr', content_tag('th', _('Title')) + content_tag('th', _('Last update'))) + | |
| 8 | - articles.select { |item| item.display_to?(user)}.map {|item| display_article_in_listing(item, recursive, 0)}.join('') | |
| 9 | - ) | |
| 10 | - else | |
| 11 | - content_tag('em', _('(empty folder)')) | |
| 12 | - end | |
| 3 | + def list_articles(articles, recursive = false) | |
| 4 | + content_tag( | |
| 5 | + 'table', | |
| 6 | + content_tag('tr', content_tag('th', _('Title')) + content_tag('th', _('Last update'))) + | |
| 7 | + articles.select { |item| item.public? }.map {|item| display_article_in_listing(item, recursive, 0)}.join('') | |
| 8 | + ) | |
| 13 | 9 | end |
| 14 | 10 | |
| 15 | 11 | def display_article_in_listing(article, recursive = false, level = 0) | ... | ... |
app/models/folder.rb
| ... | ... | @@ -41,7 +41,7 @@ class Folder < Article |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | 43 | def folder |
| 44 | - content_tag('div', body) + tag('hr') | |
| 44 | + content_tag('div', body) + tag('hr') + (children.empty? ? content_tag('em', _('(empty folder)')) : list_articles(children)) | |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | 47 | def image_gallery | ... | ... |
app/views/content_viewer/view_page.rhtml
| ... | ... | @@ -85,9 +85,6 @@ |
| 85 | 85 | <% cache(@page.cache_key(params, user)) do %> |
| 86 | 86 | <div class="<%="article-body article-body-" + @page.css_class_name %>"> |
| 87 | 87 | <%= article_to_html(@page) %> |
| 88 | - <% if @page.folder? %> | |
| 89 | - <%= list_articles(@page.children, user)%> | |
| 90 | - <% end %> | |
| 91 | 88 | <br style="clear:both" /> |
| 92 | 89 | </div> <!-- end class="article-body" --> |
| 93 | 90 | <% end %> | ... | ... |
app/views/profile/sitemap.rhtml
test/unit/folder_helper_test.rb
| ... | ... | @@ -15,82 +15,4 @@ class FolderHelperTest < Test::Unit::TestCase |
| 15 | 15 | assert_equal 'icons-mime/unknown.png', icon_for_article(art2) |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | - should 'list all the folder\'s children to the owner' do | |
| 19 | - profile = create_user('Folder Owner').person | |
| 20 | - folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) | |
| 21 | - sub_folder = fast_create(Folder, {:name => 'Child Folder', :parent_id => folder.id, | |
| 22 | - :profile_id => profile.id}) | |
| 23 | - sub_blog = fast_create(Blog, {:name => 'Child Blog', :parent_id => folder.id, | |
| 24 | - :profile_id => profile.id}) | |
| 25 | - sub_article = fast_create(Article, {:name => 'Not Public Child Article', :parent_id => | |
| 26 | - folder.id, :profile_id => profile.id, :published => false}) | |
| 27 | - | |
| 28 | - result = folder.list_articles(folder.children, profile) | |
| 29 | - | |
| 30 | - assert_match 'Child Folder', result | |
| 31 | - assert_match 'Not Public Child Article', result | |
| 32 | - assert_match 'Child Blog', result | |
| 33 | - end | |
| 34 | - | |
| 35 | - should 'list the folder\'s children that are public to the user' do | |
| 36 | - profile = create_user('Folder Owner').person | |
| 37 | - profile2 = create_user('Folder Viwer').person | |
| 38 | - folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) | |
| 39 | - public_article = fast_create(Article, {:name => 'Public Article', :parent_id => | |
| 40 | - folder.id, :profile_id => profile.id, :published => true}) | |
| 41 | - not_public_article = fast_create(Article, {:name => 'Not Public Article', :parent_id => | |
| 42 | - folder.id, :profile_id => profile.id, :published => false}) | |
| 43 | - | |
| 44 | - result = folder.list_articles(folder.children, profile2) | |
| 45 | - | |
| 46 | - assert_match 'Public Article', result | |
| 47 | - assert_no_match /Not Public Article/, result | |
| 48 | - end | |
| 49 | - | |
| 50 | - should ' not list the folder\'s children to the user because the owner\'s profile is not public' do | |
| 51 | - profile = create_user('folder-owner').person | |
| 52 | - profile.public_profile = false | |
| 53 | - profile.save! | |
| 54 | - profile2 = create_user('Folder Viwer').person | |
| 55 | - folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) | |
| 56 | - article = fast_create(Article, {:name => 'Article', :parent_id => folder.id, :profile_id => profile.id}) | |
| 57 | - | |
| 58 | - result = folder.list_articles(folder.children, profile2) | |
| 59 | - | |
| 60 | - assert_no_match /Article/, result | |
| 61 | - end | |
| 62 | - | |
| 63 | - should ' not list the folder\'s children to the user because the owner\'s profile is not visible' do | |
| 64 | - profile = create_user('folder-owner').person | |
| 65 | - profile.visible = false | |
| 66 | - profile.save! | |
| 67 | - profile2 = create_user('Folder Viwer').person | |
| 68 | - folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) | |
| 69 | - article = fast_create(Article, {:name => 'Article', :parent_id => folder.id, :profile_id => profile.id}) | |
| 70 | - | |
| 71 | - result = folder.list_articles(folder.children, profile2) | |
| 72 | - | |
| 73 | - assert_no_match /Article/, result | |
| 74 | - end | |
| 75 | - | |
| 76 | - should 'list subitems as HTML content' do | |
| 77 | - profile = create_user('folder-owner').person | |
| 78 | - folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) | |
| 79 | - article = fast_create(Article, {:name => 'Article1', :parent_id => folder.id, :profile_id => profile.id}) | |
| 80 | - article = fast_create(Article, {:name => 'Article2', :parent_id => folder.id, :profile_id => profile.id}) | |
| 81 | - | |
| 82 | - result = folder.list_articles(folder.children, profile) | |
| 83 | - | |
| 84 | - assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article1/ | |
| 85 | - assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article2/ | |
| 86 | - end | |
| 87 | - | |
| 88 | - should 'explictly advise if empty' do | |
| 89 | - profile = create_user('folder-owner').person | |
| 90 | - folder = fast_create(Folder, {:name => 'Parent Folder', :profile_id => profile.id}) | |
| 91 | - result = folder.list_articles(folder.children, profile) | |
| 92 | - | |
| 93 | - assert_match '(empty folder)', result | |
| 94 | - end | |
| 95 | - | |
| 96 | 18 | end | ... | ... |
test/unit/folder_test.rb
| ... | ... | @@ -18,6 +18,23 @@ class FolderTest < ActiveSupport::TestCase |
| 18 | 18 | assert_not_equal Article.new.icon_name, Folder.new.icon_name |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | + should 'list subitems as HTML content' do | |
| 22 | + p = create_user('testuser').person | |
| 23 | + f = Folder.create!(:profile => p, :name => 'f') | |
| 24 | + f.children.create!(:profile => p, :name => 'onearticle') | |
| 25 | + f.children.create!(:profile => p, :name => 'otherarticle') | |
| 26 | + f.reload | |
| 27 | + | |
| 28 | + assert_tag_in_string f.to_html, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/onearticle(\?|$)/ } }, :content => /onearticle/ | |
| 29 | + assert_tag_in_string f.to_html, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/testuser\/f\/otherarticle(\?|$)/ } }, :content => /otherarticle/ | |
| 30 | + end | |
| 31 | + | |
| 32 | + should 'explictly advise if empty' do | |
| 33 | + p = create_user('testuser').person | |
| 34 | + f = Folder.create!(:profile => p, :name => 'f') | |
| 35 | + assert_tag_in_string f.to_html, :content => '(empty folder)' | |
| 36 | + end | |
| 37 | + | |
| 21 | 38 | should 'show text body in HTML content' do |
| 22 | 39 | p = create_user('testuser').person |
| 23 | 40 | f = Folder.create!(:name => 'f', :profile => p, :body => 'this-is-the-text') | ... | ... |