From a778c26196568ef0468c7425d07338a27078e75c Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 4 May 2012 18:38:26 -0300 Subject: [PATCH] Refactor logic in the article toolbar --- app/models/article.rb | 8 ++++++++ app/views/content_viewer/_article_toolbar.rhtml | 76 ++++++++++++++++++++++++++++++++++++++++------------------------------------ 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 59e9e6d..4c27775 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -408,6 +408,14 @@ class Article < ActiveRecord::Base user && user.has_permission?('view_private_content', profile) end + alias :allow_delete? :allow_post_content? + alias :allow_spread? :allow_post_content? + alias :allow_edit? :allow_post_content? + + def allow_create?(user) + allow_post_content?(user) || allow_publish_content?(user) + end + def comments_updated ferret_update end diff --git a/app/views/content_viewer/_article_toolbar.rhtml b/app/views/content_viewer/_article_toolbar.rhtml index 3ce2224..339a745 100644 --- a/app/views/content_viewer/_article_toolbar.rhtml +++ b/app/views/content_viewer/_article_toolbar.rhtml @@ -1,42 +1,46 @@ -> +>
- <% if @page.allow_post_content?(user) || @page.allow_publish_content?(user) %> - <% if @page.allow_post_content?(user) %> - <%= link_to content_tag( 'span', label_for_edit_article(@page) ), - profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }), - :class => 'button with-text icon-edit' %> - <% if @page != profile.home_page && !@page.has_posts? %> - <%= link_to content_tag( 'span', _('Delete') ), - profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}), - :method => :post, - :class => 'button with-text icon-delete', - :confirm => delete_article_message(@page) %> - <% end %> - <% if !@page.folder? %> - <% if profile.kind_of?(Person) %> - <%= link_to content_tag( 'span', _('Spread this') ), - profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), - :class => 'button with-text icon-spread' %> - <% elsif profile.kind_of?(Community) && environment.portal_community %> - <%= link_to content_tag( 'span', _('Spread this') ), - profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }), - :class => 'button with-text icon-spread' %> - <% end %> - <% end %> - <% end %> - <% if !@page.gallery? %> - <%= link_to _('Add translation'), - profile.admin_url.merge(:controller => 'cms', :action => 'new', - :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)), - :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }), - :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> - <%= lightbox_remote_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.accept_uploads? %> - <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> + + <% if @page.allow_edit?(user) %> + <%= link_to content_tag( 'span', label_for_edit_article(@page) ), + profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }), + :class => 'button with-text icon-edit' %> + <% end %> + + <% if @page != profile.home_page && !@page.has_posts? && @page.allow_delete?(user) %> + <%= link_to content_tag( 'span', _('Delete') ), + profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}), + :method => :post, + :class => 'button with-text icon-delete', + :confirm => delete_article_message(@page) %> + <% end %> + + <% if !@page.folder? && @page.allow_spread?(user) %> + <% if profile.kind_of?(Person) %> + <%= link_to content_tag( 'span', _('Spread this') ), + profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), + :class => 'button with-text icon-spread' %> + <% elsif profile.kind_of?(Community) && environment.portal_community %> + <%= link_to content_tag( 'span', _('Spread this') ), + profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }), + :class => 'button with-text icon-spread' %> <% end %> + <% end %> + + <% if !@page.gallery? && @page.allow_create?(user) %> + <%= link_to _('Add translation'), + profile.admin_url.merge(:controller => 'cms', :action => 'new', + :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)), + :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }), + :class => @page.translatable? && !@page.native_translation.language.blank? && 'button with-text icon-locale' %> + <%= lightbox_remote_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.accept_uploads? && @page.allow_create?(user) %> + <%= 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?) %> + <% if !@page.allow_create?(user) && profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %> <%= link_to content_tag( 'span', _('Suggest an article') ), profile.admin_url.merge({ :controller => 'cms', :action => 'suggest_an_article'}), :id => 'suggest-article-link', :class => 'button with-text icon-new' %> <% end %> -- libgit2 0.21.2