From 86e5a2dbf50446ecc306096f195edb34fc13c63e Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Tue, 15 Mar 2011 20:21:59 -0300 Subject: [PATCH] Do not duplicate link "Upload files" on Enterprise's gallery --- app/models/article.rb | 4 ++++ app/models/folder.rb | 5 +++++ app/views/content_viewer/view_page.rhtml | 7 ++----- features/upload_files.feature | 42 ++++++++++++++++++++++++++++++++++++++++++ test/unit/article_test.rb | 24 ++++++++++++++++++++++++ test/unit/blog_test.rb | 5 +++++ test/unit/folder_test.rb | 5 +++++ test/unit/forum_test.rb | 5 +++++ test/unit/gallery_test.rb | 5 +++++ 9 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 features/upload_files.feature diff --git a/app/models/article.rb b/app/models/article.rb index c086adf..94d5fef 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -505,6 +505,10 @@ class Article < ActiveRecord::Base false end + def accept_uploads? + self.parent && self.parent.accept_uploads? + end + private def sanitize_tag_list diff --git a/app/models/folder.rb b/app/models/folder.rb index 704e608..2d4b573 100644 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -53,4 +53,9 @@ class Folder < Article :foreign_key => 'parent_id', :order => 'articles.type, articles.name', :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types] + + def accept_uploads? + !self.has_posts? || self.gallery? + end + end diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 2a44cce..31fb4ac 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -42,12 +42,9 @@ :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> <%= lightbox_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) %> <% end %> - <% if (@page.folder? && !@page.has_posts?) || (@page.parent && @page.parent.folder? && !@page.parent.has_posts?) %> - <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> - <% end %> <% end %> - <% if profile.kind_of?(Enterprise) && @page.gallery? %> - <%= button('upload-file', _('Upload files'), :controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent)) %> + <% if @page.accept_uploads? %> + <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> <% end %> <% elsif profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %> diff --git a/features/upload_files.feature b/features/upload_files.feature new file mode 100644 index 0000000..c7c68f2 --- /dev/null +++ b/features/upload_files.feature @@ -0,0 +1,42 @@ +Feature: upload files + As a logged user + I want to upload files + + Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + And I am logged in as "joaosilva" + + + Scenario: provile links to upload files to community's gallery + Given the following communities + | identifier | name | owner | + | sample-community | Sample Community | joaosilva | + And the following galleries + | owner | name | + | sample-community | Gallery test | + And I go to Sample Community's profile + And I follow "0 pictures" + And I should see "Upload files" + + Scenario: provile links to upload files to enterprise's gallery + Given the following enterprises + | identifier | name | owner | + | sample-enterprise | Sample Enterprise | joaosilva | + And the following galleries + | owner | name | + | sample-enterprise | Gallery test | + And I go to Sample Enterprise's profile + And I follow "0 pictures" + And I should see "Upload files" + + Scenario: not provile links to upload files on blogs + Given the following communities + | identifier | name | owner | + | sample-community | Sample Community | joaosilva | + And the following blogs + | owner | name | + | sample-community | Blog test | + And I go to Sample Community's blog + And I should not see "Upload files" diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index e5b2611..4a21bfc 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1474,4 +1474,28 @@ class ArticleTest < Test::Unit::TestCase end end + should 'accept uploads if parent accept uploads' do + folder = fast_create(Folder) + child = fast_create(UploadedFile, :parent_id => folder.id) + assert folder.accept_uploads? + assert child.accept_uploads? + end + + should 'not accept uploads if has no parent' do + child = fast_create(UploadedFile) + assert !child.accept_uploads? + end + + should 'not accept uploads if parent is a blog' do + folder = fast_create(Blog) + child = fast_create(UploadedFile, :parent_id => folder.id) + assert !child.accept_uploads? + end + + should 'not accept uploads if parent is a forum' do + folder = fast_create(Forum) + child = fast_create(UploadedFile, :parent_id => folder.id) + assert !child.accept_uploads? + end + end diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index 61e492f..fab6738 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -206,4 +206,9 @@ class BlogTest < ActiveSupport::TestCase assert_includes blog.posts, article end + should 'not accept uploads' do + folder = fast_create(Blog) + assert !folder.accept_uploads? + end + end diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb index 96e36e3..4ba2513 100644 --- a/test/unit/folder_test.rb +++ b/test/unit/folder_test.rb @@ -140,4 +140,9 @@ class FolderTest < ActiveSupport::TestCase assert folder.errors.on(:parent) end + should 'accept uploads' do + folder = fast_create(Folder) + assert folder.accept_uploads? + end + end diff --git a/test/unit/forum_test.rb b/test/unit/forum_test.rb index 9a6f55c..ff3fc25 100644 --- a/test/unit/forum_test.rb +++ b/test/unit/forum_test.rb @@ -104,4 +104,9 @@ class ForumTest < ActiveSupport::TestCase assert Forum.new.has_posts? end + should 'not accept uploads' do + folder = fast_create(Forum) + assert !folder.accept_uploads? + end + end diff --git a/test/unit/gallery_test.rb b/test/unit/gallery_test.rb index 0fed6eb..2963fea 100644 --- a/test/unit/gallery_test.rb +++ b/test/unit/gallery_test.rb @@ -141,4 +141,9 @@ class GalleryTest < ActiveSupport::TestCase assert_no_match /[<>]/, gallery.body end + should 'accept uploads' do + folder = fast_create(Gallery) + assert folder.accept_uploads? + end + end -- libgit2 0.21.2