diff --git a/app/models/environment.rb b/app/models/environment.rb index 482bb15..9c24f25 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -31,6 +31,7 @@ class Environment < ActiveRecord::Base 'disable_products_for_enterprises' => _('Disable products for enterprises'), 'disable_categories' => _('Disable categories'), 'disable_cms' => _('Disable CMS'), + 'disable_header_and_footer' => _('Disable header/footer editing by users'), } end diff --git a/app/models/profile.rb b/app/models/profile.rb index 326a2a5..9704f18 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -216,7 +216,7 @@ class Profile < ActiveRecord::Base def apply_template(template) copy_blocks_from(template) copy_articles_from(template) - self.update_attributes!(:custom_footer => template[:custom_footer], :custom_header => template[:custom_header]) + self.update_attributes!(:layout_template => template.layout_template, :custom_footer => template[:custom_footer], :custom_header => template[:custom_header]) end xss_terminate :only => [ :name, :nickname, :address, :contact_phone ] @@ -470,8 +470,12 @@ class Profile < ActiveRecord::Base footer = self[:custom_footer] || environment.custom_footer if footer %w[contact_person contact_email contact_phone location address economic_activity].each do |att| - if self.respond_to?(att) && footer.include?("{#{att}}") - footer = footer.gsub("{#{att}}", self.send(att).to_s) + if self.respond_to?(att) && footer.match(/\{[^{]*#{att}\}/) + if !self.send(att).nil? + footer = footer.gsub(/\{([^{]*)#{att}\}/, '\1' + self.send(att)) + else + footer = footer.gsub(/\{[^}]*#{att}\}/, '') + end end end footer diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 9ba5e9c..bfce2ac 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -78,9 +78,7 @@
- <% if !@page.accept_comments? %> - <%= _('This article does not accept comments')%> - <% else %> + <% if @page.accept_comments? %>

> <%= number_of_comments(@page) %>

diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml index 70274e3..63824ce 100644 --- a/app/views/profile_editor/index.rhtml +++ b/app/views/profile_editor/index.rhtml @@ -18,7 +18,7 @@ <%= file_manager_button(_('Edit Appearance'), 'icons-app/design-editor.png', :controller => 'themes', :action => 'index') %> - <%= file_manager_button(_('Edit Header and Footer'), 'icons-app/header-and-footer.png', :controller => 'profile_editor', :action => 'header_footer') %> + <%= 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? %> <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') unless environment.enabled?('disable_cms')%> diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 9f80269..cba9c8e 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -480,6 +480,33 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/profile_editor/header_footer" } end + should 'not display header/footer button to enterprises if the environment disabled it' do + env = Environment.default + env.enable('disable_header_and_footer') + env.save! + + enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test') + + u = create_user_with_permission('test_user', 'edit_profile', enterprise) + login_as('test_user') + + get :index, :profile => enterprise.identifier + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" } + end + + should 'display header/footer button to enterprises if the environment disabled it but user is admin' do + env = Environment.default + env.enable('disable_header_and_footer') + env.save! + + enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test') + + Person.any_instance.expects(:is_admin?).returns(true).at_least_once + + get :index, :profile => enterprise.identifier + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" } + end + should 'not list the manage products button if the environment disabled it' do env = Environment.default env.enable('disable_products_for_enterprises') diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 4729628..e0aad9c 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -775,8 +775,28 @@ class ProfileTest < Test::Unit::TestCase assert_equal 'my custom footer', Profile.new(:custom_footer => 'my custom footer').custom_footer end - should 'provide custom footer with variables' do - assert_equal 'Address: Address for test', Profile.new(:custom_footer => 'Address: {address}', :address => 'Address for test').custom_footer + should 'not replace variables on custom_footer if hasnt pattern' do + assert_equal 'address}', Profile.new(:custom_footer => 'address}', :address => 'Address for test').custom_footer + end + + should 'replace variables on custom_footer' do + assert_equal 'Address for test', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer + end + + should 'replace variables on custom_footer with title' do + assert_equal 'Address: Address for test', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer + end + + should 'replace variables on custom_footer when it is nil' do + assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer + end + + should 'replace variables in custom_footer when more than one' do + assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer + end + + should 'replace variables on custom_footer with title when it is nil' do + assert_equal '', Profile.new(:custom_footer => '{Address: address}').custom_footer end should 'provide environment header if profile header is blank' do @@ -901,7 +921,19 @@ class ProfileTest < Test::Unit::TestCase assert_equal 1, p.boxes[0].blocks.size end - should 'apply template' do + should 'copy layout template when applying template' do + template = Profile.create!(:name => 'test template', :identifier => 'test_template') + template.layout_template = 'leftbar' + template.save! + + p = Profile.create!(:name => 'test prof', :identifier => 'test_prof') + + p.apply_template(template) + + assert_equal 'leftbar', p.layout_template + end + + should 'copy blocks when applying template' do template = Profile.create!(:name => 'test template', :identifier => 'test_template') template.boxes.destroy_all template.boxes << Box.new @@ -970,6 +1002,20 @@ class ProfileTest < Test::Unit::TestCase assert_equal 'Profile address', p.custom_footer end + should 'copy homepage when applying template' do + template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address') + template.articles.destroy_all + a1 = template.articles.create(:name => 'some xyz article') + template.home_page = a1 + template.save! + + p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') + p.apply_template(template) + + assert_not_nil p.home_page + assert_equal 'some xyz article', Profile['test_profile'].home_page.name + end + TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/profile_themes' should 'have themes' do Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) -- libgit2 0.21.2