Commit 86e5a2dbf50446ecc306096f195edb34fc13c63e
Committed by
Daniela Feitosa
1 parent
236951da
Exists in
master
and in
29 other branches
Do not duplicate link "Upload files" on Enterprise's gallery
(ActionItem1932)
Showing
9 changed files
with
97 additions
and
5 deletions
Show diff stats
app/models/article.rb
@@ -505,6 +505,10 @@ class Article < ActiveRecord::Base | @@ -505,6 +505,10 @@ class Article < ActiveRecord::Base | ||
505 | false | 505 | false |
506 | end | 506 | end |
507 | 507 | ||
508 | + def accept_uploads? | ||
509 | + self.parent && self.parent.accept_uploads? | ||
510 | + end | ||
511 | + | ||
508 | private | 512 | private |
509 | 513 | ||
510 | def sanitize_tag_list | 514 | def sanitize_tag_list |
app/models/folder.rb
@@ -53,4 +53,9 @@ class Folder < Article | @@ -53,4 +53,9 @@ class Folder < Article | ||
53 | :foreign_key => 'parent_id', | 53 | :foreign_key => 'parent_id', |
54 | :order => 'articles.type, articles.name', | 54 | :order => 'articles.type, articles.name', |
55 | :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types] | 55 | :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types] |
56 | + | ||
57 | + def accept_uploads? | ||
58 | + !self.has_posts? || self.gallery? | ||
59 | + end | ||
60 | + | ||
56 | end | 61 | end |
app/views/content_viewer/view_page.rhtml
@@ -42,12 +42,9 @@ | @@ -42,12 +42,9 @@ | ||
42 | :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> | 42 | :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> |
43 | <%= 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)))) %> | 43 | <%= 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)))) %> |
44 | <% end %> | 44 | <% end %> |
45 | - <% if (@page.folder? && !@page.has_posts?) || (@page.parent && @page.parent.folder? && !@page.parent.has_posts?) %> | ||
46 | - <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> | ||
47 | - <% end %> | ||
48 | <% end %> | 45 | <% end %> |
49 | - <% if profile.kind_of?(Enterprise) && @page.gallery? %> | ||
50 | - <%= button('upload-file', _('Upload files'), :controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent)) %> | 46 | + <% if @page.accept_uploads? %> |
47 | + <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> | ||
51 | <% end %> | 48 | <% end %> |
52 | </div> | 49 | </div> |
53 | <% elsif profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %> | 50 | <% elsif profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %> |
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +Feature: upload files | ||
2 | + As a logged user | ||
3 | + I want to upload files | ||
4 | + | ||
5 | + Background: | ||
6 | + Given the following users | ||
7 | + | login | name | | ||
8 | + | joaosilva | Joao Silva | | ||
9 | + And I am logged in as "joaosilva" | ||
10 | + | ||
11 | + | ||
12 | + Scenario: provile links to upload files to community's gallery | ||
13 | + Given the following communities | ||
14 | + | identifier | name | owner | | ||
15 | + | sample-community | Sample Community | joaosilva | | ||
16 | + And the following galleries | ||
17 | + | owner | name | | ||
18 | + | sample-community | Gallery test | | ||
19 | + And I go to Sample Community's profile | ||
20 | + And I follow "0 pictures" | ||
21 | + And I should see "Upload files" | ||
22 | + | ||
23 | + Scenario: provile links to upload files to enterprise's gallery | ||
24 | + Given the following enterprises | ||
25 | + | identifier | name | owner | | ||
26 | + | sample-enterprise | Sample Enterprise | joaosilva | | ||
27 | + And the following galleries | ||
28 | + | owner | name | | ||
29 | + | sample-enterprise | Gallery test | | ||
30 | + And I go to Sample Enterprise's profile | ||
31 | + And I follow "0 pictures" | ||
32 | + And I should see "Upload files" | ||
33 | + | ||
34 | + Scenario: not provile links to upload files on blogs | ||
35 | + Given the following communities | ||
36 | + | identifier | name | owner | | ||
37 | + | sample-community | Sample Community | joaosilva | | ||
38 | + And the following blogs | ||
39 | + | owner | name | | ||
40 | + | sample-community | Blog test | | ||
41 | + And I go to Sample Community's blog | ||
42 | + And I should not see "Upload files" |
test/unit/article_test.rb
@@ -1474,4 +1474,28 @@ class ArticleTest < Test::Unit::TestCase | @@ -1474,4 +1474,28 @@ class ArticleTest < Test::Unit::TestCase | ||
1474 | end | 1474 | end |
1475 | end | 1475 | end |
1476 | 1476 | ||
1477 | + should 'accept uploads if parent accept uploads' do | ||
1478 | + folder = fast_create(Folder) | ||
1479 | + child = fast_create(UploadedFile, :parent_id => folder.id) | ||
1480 | + assert folder.accept_uploads? | ||
1481 | + assert child.accept_uploads? | ||
1482 | + end | ||
1483 | + | ||
1484 | + should 'not accept uploads if has no parent' do | ||
1485 | + child = fast_create(UploadedFile) | ||
1486 | + assert !child.accept_uploads? | ||
1487 | + end | ||
1488 | + | ||
1489 | + should 'not accept uploads if parent is a blog' do | ||
1490 | + folder = fast_create(Blog) | ||
1491 | + child = fast_create(UploadedFile, :parent_id => folder.id) | ||
1492 | + assert !child.accept_uploads? | ||
1493 | + end | ||
1494 | + | ||
1495 | + should 'not accept uploads if parent is a forum' do | ||
1496 | + folder = fast_create(Forum) | ||
1497 | + child = fast_create(UploadedFile, :parent_id => folder.id) | ||
1498 | + assert !child.accept_uploads? | ||
1499 | + end | ||
1500 | + | ||
1477 | end | 1501 | end |
test/unit/blog_test.rb
@@ -206,4 +206,9 @@ class BlogTest < ActiveSupport::TestCase | @@ -206,4 +206,9 @@ class BlogTest < ActiveSupport::TestCase | ||
206 | assert_includes blog.posts, article | 206 | assert_includes blog.posts, article |
207 | end | 207 | end |
208 | 208 | ||
209 | + should 'not accept uploads' do | ||
210 | + folder = fast_create(Blog) | ||
211 | + assert !folder.accept_uploads? | ||
212 | + end | ||
213 | + | ||
209 | end | 214 | end |
test/unit/folder_test.rb
@@ -140,4 +140,9 @@ class FolderTest < ActiveSupport::TestCase | @@ -140,4 +140,9 @@ class FolderTest < ActiveSupport::TestCase | ||
140 | assert folder.errors.on(:parent) | 140 | assert folder.errors.on(:parent) |
141 | end | 141 | end |
142 | 142 | ||
143 | + should 'accept uploads' do | ||
144 | + folder = fast_create(Folder) | ||
145 | + assert folder.accept_uploads? | ||
146 | + end | ||
147 | + | ||
143 | end | 148 | end |
test/unit/forum_test.rb
@@ -104,4 +104,9 @@ class ForumTest < ActiveSupport::TestCase | @@ -104,4 +104,9 @@ class ForumTest < ActiveSupport::TestCase | ||
104 | assert Forum.new.has_posts? | 104 | assert Forum.new.has_posts? |
105 | end | 105 | end |
106 | 106 | ||
107 | + should 'not accept uploads' do | ||
108 | + folder = fast_create(Forum) | ||
109 | + assert !folder.accept_uploads? | ||
110 | + end | ||
111 | + | ||
107 | end | 112 | end |
test/unit/gallery_test.rb
@@ -141,4 +141,9 @@ class GalleryTest < ActiveSupport::TestCase | @@ -141,4 +141,9 @@ class GalleryTest < ActiveSupport::TestCase | ||
141 | assert_no_match /[<>]/, gallery.body | 141 | assert_no_match /[<>]/, gallery.body |
142 | end | 142 | end |
143 | 143 | ||
144 | + should 'accept uploads' do | ||
145 | + folder = fast_create(Gallery) | ||
146 | + assert folder.accept_uploads? | ||
147 | + end | ||
148 | + | ||
144 | end | 149 | end |