Commit bc41167f71d7fd32912bfe5feaa50dadad90f3dc

Authored by Daniela Feitosa
1 parent 8b70dd75

ActionItem856: enhancing presentation of enterprises

  * Adding feature to edit header/footer to environment and test
  * adding regexp to replace values on footer
  * removing message of no comments if there's no comment
  * fixing bug.. When applying template, didn't copy the homepage
app/models/environment.rb
@@ -31,6 +31,7 @@ class Environment < ActiveRecord::Base @@ -31,6 +31,7 @@ class Environment < ActiveRecord::Base
31 'disable_products_for_enterprises' => _('Disable products for enterprises'), 31 'disable_products_for_enterprises' => _('Disable products for enterprises'),
32 'disable_categories' => _('Disable categories'), 32 'disable_categories' => _('Disable categories'),
33 'disable_cms' => _('Disable CMS'), 33 'disable_cms' => _('Disable CMS'),
  34 + 'disable_header_and_footer' => _('Disable header/footer editing by users'),
34 } 35 }
35 end 36 end
36 37
app/models/profile.rb
@@ -216,7 +216,7 @@ class Profile < ActiveRecord::Base @@ -216,7 +216,7 @@ class Profile < ActiveRecord::Base
216 def apply_template(template) 216 def apply_template(template)
217 copy_blocks_from(template) 217 copy_blocks_from(template)
218 copy_articles_from(template) 218 copy_articles_from(template)
219 - self.update_attributes!(:custom_footer => template[:custom_footer], :custom_header => template[:custom_header]) 219 + self.update_attributes!(:layout_template => template.layout_template, :custom_footer => template[:custom_footer], :custom_header => template[:custom_header])
220 end 220 end
221 221
222 xss_terminate :only => [ :name, :nickname, :address, :contact_phone ] 222 xss_terminate :only => [ :name, :nickname, :address, :contact_phone ]
@@ -470,8 +470,12 @@ class Profile < ActiveRecord::Base @@ -470,8 +470,12 @@ class Profile < ActiveRecord::Base
470 footer = self[:custom_footer] || environment.custom_footer 470 footer = self[:custom_footer] || environment.custom_footer
471 if footer 471 if footer
472 %w[contact_person contact_email contact_phone location address economic_activity].each do |att| 472 %w[contact_person contact_email contact_phone location address economic_activity].each do |att|
473 - if self.respond_to?(att) && footer.include?("{#{att}}")  
474 - footer = footer.gsub("{#{att}}", self.send(att).to_s) 473 + if self.respond_to?(att) && footer.match(/\{[^{]*#{att}\}/)
  474 + if !self.send(att).nil?
  475 + footer = footer.gsub(/\{([^{]*)#{att}\}/, '\1' + self.send(att))
  476 + else
  477 + footer = footer.gsub(/\{[^}]*#{att}\}/, '')
  478 + end
475 end 479 end
476 end 480 end
477 footer 481 footer
app/views/content_viewer/view_page.rhtml
@@ -78,9 +78,7 @@ @@ -78,9 +78,7 @@
78 78
79 79
80 <div class="comments"> 80 <div class="comments">
81 - <% if !@page.accept_comments? %>  
82 - <i class="do-not-comment"><%= _('This article does not accept comments')%></i>  
83 - <% else %> 81 + <% if @page.accept_comments? %>
84 <h3 <%= 'class="no-comments-yet"' if @comments.size == 0 %>> 82 <h3 <%= 'class="no-comments-yet"' if @comments.size == 0 %>>
85 <%= number_of_comments(@page) %> 83 <%= number_of_comments(@page) %>
86 </h3> 84 </h3>
app/views/profile_editor/index.rhtml
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 18
19 <%= file_manager_button(_('Edit Appearance'), 'icons-app/design-editor.png', :controller => 'themes', :action => 'index') %> 19 <%= file_manager_button(_('Edit Appearance'), 'icons-app/design-editor.png', :controller => 'themes', :action => 'index') %>
20 20
21 - <%= file_manager_button(_('Edit Header and Footer'), 'icons-app/header-and-footer.png', :controller => 'profile_editor', :action => 'header_footer') %> 21 + <%= file_manager_button(_('Edit Header and Footer'), 'icons-app/header-and-footer.png', :controller => 'profile_editor', :action => 'header_footer') unless profile.enterprise? && environment.enabled?('disable_header_and_footer') && !user.is_admin? %>
22 22
23 <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') unless environment.enabled?('disable_cms')%> 23 <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') unless environment.enabled?('disable_cms')%>
24 24
test/functional/profile_editor_controller_test.rb
@@ -480,6 +480,33 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -480,6 +480,33 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
480 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/profile_editor/header_footer" } 480 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/profile_editor/header_footer" }
481 end 481 end
482 482
  483 + should 'not display header/footer button to enterprises if the environment disabled it' do
  484 + env = Environment.default
  485 + env.enable('disable_header_and_footer')
  486 + env.save!
  487 +
  488 + enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test')
  489 +
  490 + u = create_user_with_permission('test_user', 'edit_profile', enterprise)
  491 + login_as('test_user')
  492 +
  493 + get :index, :profile => enterprise.identifier
  494 + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" }
  495 + end
  496 +
  497 + should 'display header/footer button to enterprises if the environment disabled it but user is admin' do
  498 + env = Environment.default
  499 + env.enable('disable_header_and_footer')
  500 + env.save!
  501 +
  502 + enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test')
  503 +
  504 + Person.any_instance.expects(:is_admin?).returns(true).at_least_once
  505 +
  506 + get :index, :profile => enterprise.identifier
  507 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" }
  508 + end
  509 +
483 should 'not list the manage products button if the environment disabled it' do 510 should 'not list the manage products button if the environment disabled it' do
484 env = Environment.default 511 env = Environment.default
485 env.enable('disable_products_for_enterprises') 512 env.enable('disable_products_for_enterprises')
test/unit/profile_test.rb
@@ -775,8 +775,28 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -775,8 +775,28 @@ class ProfileTest &lt; Test::Unit::TestCase
775 assert_equal 'my custom footer', Profile.new(:custom_footer => 'my custom footer').custom_footer 775 assert_equal 'my custom footer', Profile.new(:custom_footer => 'my custom footer').custom_footer
776 end 776 end
777 777
778 - should 'provide custom footer with variables' do  
779 - assert_equal 'Address: Address for test', Profile.new(:custom_footer => 'Address: {address}', :address => 'Address for test').custom_footer 778 + should 'not replace variables on custom_footer if hasnt pattern' do
  779 + assert_equal 'address}', Profile.new(:custom_footer => 'address}', :address => 'Address for test').custom_footer
  780 + end
  781 +
  782 + should 'replace variables on custom_footer' do
  783 + assert_equal 'Address for test', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer
  784 + end
  785 +
  786 + should 'replace variables on custom_footer with title' do
  787 + assert_equal 'Address: Address for test', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer
  788 + end
  789 +
  790 + should 'replace variables on custom_footer when it is nil' do
  791 + assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer
  792 + end
  793 +
  794 + should 'replace variables in custom_footer when more than one' do
  795 + assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer
  796 + end
  797 +
  798 + should 'replace variables on custom_footer with title when it is nil' do
  799 + assert_equal '', Profile.new(:custom_footer => '{Address: address}').custom_footer
780 end 800 end
781 801
782 should 'provide environment header if profile header is blank' do 802 should 'provide environment header if profile header is blank' do
@@ -901,7 +921,19 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -901,7 +921,19 @@ class ProfileTest &lt; Test::Unit::TestCase
901 assert_equal 1, p.boxes[0].blocks.size 921 assert_equal 1, p.boxes[0].blocks.size
902 end 922 end
903 923
904 - should 'apply template' do 924 + should 'copy layout template when applying template' do
  925 + template = Profile.create!(:name => 'test template', :identifier => 'test_template')
  926 + template.layout_template = 'leftbar'
  927 + template.save!
  928 +
  929 + p = Profile.create!(:name => 'test prof', :identifier => 'test_prof')
  930 +
  931 + p.apply_template(template)
  932 +
  933 + assert_equal 'leftbar', p.layout_template
  934 + end
  935 +
  936 + should 'copy blocks when applying template' do
905 template = Profile.create!(:name => 'test template', :identifier => 'test_template') 937 template = Profile.create!(:name => 'test template', :identifier => 'test_template')
906 template.boxes.destroy_all 938 template.boxes.destroy_all
907 template.boxes << Box.new 939 template.boxes << Box.new
@@ -970,6 +1002,20 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -970,6 +1002,20 @@ class ProfileTest &lt; Test::Unit::TestCase
970 assert_equal 'Profile address', p.custom_footer 1002 assert_equal 'Profile address', p.custom_footer
971 end 1003 end
972 1004
  1005 + should 'copy homepage when applying template' do
  1006 + template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address')
  1007 + template.articles.destroy_all
  1008 + a1 = template.articles.create(:name => 'some xyz article')
  1009 + template.home_page = a1
  1010 + template.save!
  1011 +
  1012 + p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile')
  1013 + p.apply_template(template)
  1014 +
  1015 + assert_not_nil p.home_page
  1016 + assert_equal 'some xyz article', Profile['test_profile'].home_page.name
  1017 + end
  1018 +
973 TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/profile_themes' 1019 TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/profile_themes'
974 should 'have themes' do 1020 should 'have themes' do
975 Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) 1021 Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)