Commit 941acfdc4cc256a19aadfaa63e36d6dfa90c2639

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 5aee489a

ActionItem1221: allowing publisher to add new content

app/models/article.rb
@@ -217,7 +217,11 @@ class Article < ActiveRecord::Base @@ -217,7 +217,11 @@ class Article < ActiveRecord::Base
217 end 217 end
218 218
219 def allow_post_content?(user = nil) 219 def allow_post_content?(user = nil)
220 - user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile) && (user == self.creator)) 220 + user && (user.has_permission?('post_content', profile) || allow_publish_content?(user) && (user == self.creator))
  221 + end
  222 +
  223 + def allow_publish_content?(user = nil)
  224 + user && user.has_permission?('publish_content', profile)
221 end 225 end
222 226
223 def comments_updated 227 def comments_updated
app/views/content_viewer/view_page.rhtml
@@ -23,8 +23,8 @@ @@ -23,8 +23,8 @@
23 23
24 <div> 24 <div>
25 <%= article_title(@page, :no_link => true) %> 25 <%= article_title(@page, :no_link => true) %>
26 - <% if @page.allow_post_content?(user) %>  
27 - <div id="article-actions"> 26 + <div id="article-actions">
  27 + <% if @page.allow_post_content?(user) %>
28 <% unless @page.blog? %> 28 <% unless @page.blog? %>
29 <%= link_to content_tag( 'span', label_for_edit_article(@page) ), 29 <%= link_to content_tag( 'span', label_for_edit_article(@page) ),
30 profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }), 30 profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }),
@@ -41,6 +41,10 @@ @@ -41,6 +41,10 @@
41 profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), 41 profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }),
42 :class => 'button with-text icon-spread' %> 42 :class => 'button with-text icon-spread' %>
43 <% end %> 43 <% end %>
  44 + <% end %>
  45 + <% end %>
  46 + <% if @page.allow_post_content?(user) || @page.allow_publish_content?(user) %>
  47 + <% if !(profile.kind_of?(Enterprise) && environment.enabled?('disable_cms')) %>
44 <% if !@page.display_as_gallery? %> 48 <% if !@page.display_as_gallery? %>
45 <%= 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)))) %> 49 <%= 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)))) %>
46 <% end %> 50 <% end %>
@@ -51,8 +55,8 @@ @@ -51,8 +55,8 @@
51 <% if profile.kind_of?(Enterprise) && @page.display_as_gallery? %> 55 <% if profile.kind_of?(Enterprise) && @page.display_as_gallery? %>
52 <%= button('upload-file', _('Upload files'), :controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent)) %> 56 <%= button('upload-file', _('Upload files'), :controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent)) %>
53 <% end %> 57 <% end %>
54 - </div>  
55 - <% end %> 58 + <% end %>
  59 + </div>
56 </div> 60 </div>
57 61
58 <% if !@page.tags.empty? %> 62 <% if !@page.tags.empty? %>
test/functional/content_viewer_controller_test.rb
@@ -862,4 +862,15 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase @@ -862,4 +862,15 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
862 assert_template 'view_page' 862 assert_template 'view_page'
863 end 863 end
864 864
  865 + should 'display link to new_article if profile is publisher' do
  866 + c = Community.create!(:name => 'test_com')
  867 + u = create_user_with_permission('test_user', 'publish_content', c)
  868 + login_as u.identifier
  869 + a = c.articles.create!(:name => 'test-article', :last_changed_by => profile, :published => true)
  870 +
  871 + get :view_page, :profile => c.identifier, :page => a.explode_path
  872 +
  873 + assert_tag :tag => 'a', :content => 'New article'
  874 + end
  875 +
865 end 876 end