From 941acfdc4cc256a19aadfaa63e36d6dfa90c2639 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Fri, 2 Oct 2009 18:55:07 -0300 Subject: [PATCH] ActionItem1221: allowing publisher to add new content --- app/models/article.rb | 6 +++++- app/views/content_viewer/view_page.rhtml | 12 ++++++++---- test/functional/content_viewer_controller_test.rb | 11 +++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 3a31ec8..af25c87 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -217,7 +217,11 @@ class Article < ActiveRecord::Base end def allow_post_content?(user = nil) - user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile) && (user == self.creator)) + user && (user.has_permission?('post_content', profile) || allow_publish_content?(user) && (user == self.creator)) + end + + def allow_publish_content?(user = nil) + user && user.has_permission?('publish_content', profile) end def comments_updated diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 35425a8..d92541b 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -23,8 +23,8 @@
<%= article_title(@page, :no_link => true) %> - <% if @page.allow_post_content?(user) %> -
+
+ <% if @page.allow_post_content?(user) %> <% unless @page.blog? %> <%= link_to content_tag( 'span', label_for_edit_article(@page) ), profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }), @@ -41,6 +41,10 @@ profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), :class => 'button with-text icon-spread' %> <% end %> + <% end %> + <% end %> + <% if @page.allow_post_content?(user) || @page.allow_publish_content?(user) %> + <% if !(profile.kind_of?(Enterprise) && environment.enabled?('disable_cms')) %> <% if !@page.display_as_gallery? %> <%= 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 %> @@ -51,8 +55,8 @@ <% if profile.kind_of?(Enterprise) && @page.display_as_gallery? %> <%= button('upload-file', _('Upload files'), :controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent)) %> <% end %> -
- <% end %> + <% end %> +
<% if !@page.tags.empty? %> diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index a4505b4..5af6cff 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -862,4 +862,15 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_template 'view_page' end + should 'display link to new_article if profile is publisher' do + c = Community.create!(:name => 'test_com') + u = create_user_with_permission('test_user', 'publish_content', c) + login_as u.identifier + a = c.articles.create!(:name => 'test-article', :last_changed_by => profile, :published => true) + + get :view_page, :profile => c.identifier, :page => a.explode_path + + assert_tag :tag => 'a', :content => 'New article' + end + end -- libgit2 0.21.2