diff --git a/app/models/disabled_enterprise_message_block.rb b/app/models/disabled_enterprise_message_block.rb
index 5069602..ba0e353 100644
--- a/app/models/disabled_enterprise_message_block.rb
+++ b/app/models/disabled_enterprise_message_block.rb
@@ -9,7 +9,7 @@ class DisabledEnterpriseMessageBlock < Block
end
def default_title
- _('Localization Map')
+ _('Message')
end
def content
diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb
index 283845d..9418ce0 100644
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -37,6 +37,9 @@ class Enterprise < Organization
return if enabled
affiliate(owner, Profile::Roles.all_roles)
update_attribute(:enabled,true)
+ if environment.replace_enterprise_template_when_enable
+ apply_template(template)
+ end
save
end
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 35d27c1..04cb677 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -386,6 +386,14 @@ class Environment < ActiveRecord::Base
end
end
+ def replace_enterprise_template_when_enable
+ settings[:replace_enterprise_template_when_enable] || false
+ end
+
+ def replace_enterprise_template_when_enable=(value)
+ settings[:replace_enterprise_template_when_enable] = value
+ end
+
after_create :create_templates
def create_templates
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 4fdb3d6..326a2a5 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -471,11 +471,11 @@ class Profile < ActiveRecord::Base
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.gsub!("{#{att}}", self.send(att).to_s)
+ footer = footer.gsub("{#{att}}", self.send(att).to_s)
end
end
+ footer
end
- footer
end
def theme
diff --git a/app/views/admin_panel/manage_templates.rhtml b/app/views/admin_panel/manage_templates.rhtml
index 0abcd52..e7f801e 100644
--- a/app/views/admin_panel/manage_templates.rhtml
+++ b/app/views/admin_panel/manage_templates.rhtml
@@ -1,7 +1,6 @@
<%= _('Set Templates') %>
<% labelled_form_for(:environment, @environment, :url => {:action => 'set_template'}) do |f| %>
-<%= current_user.name %>
<%= f.select :person_template, @person_templates.map {|item| [ item.identifier, item.id]}, :selected => (environment.person_template.nil? ? nil : environment.person_template.id) %>
@@ -17,11 +16,6 @@
<%= f.select :enterprise_template, @enterprise_templates.map {|item| [ item.identifier, item.id]}, :selected => (environment.enterprise_template.nil? ? nil : environment.enterprise_template.id) %>
-
-
- <%= f.select :inactive_enterprise_template, @enterprise_templates.map {|item| [ item.identifier, item.id]}, :selected => (environment.inactive_enterprise_template.nil? ? nil : environment.inactive_enterprise_template.id) %>
-
-
<% button_bar do %>
<%= submit_button(:save, _('Save')) %>
<%= button(:cancel, _('Cancel'), :action => 'index') %>
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml
index 98aa2e3..b556ad5 100644
--- a/app/views/content_viewer/view_page.rhtml
+++ b/app/views/content_viewer/view_page.rhtml
@@ -58,7 +58,7 @@
<% end %>
-<% if profile.enterprise? and !profile.enabled? %>
+<% if profile.enterprise? and !profile.enabled? and !profile.blocks.select {|b| b.class == DisabledEnterpriseMessageBlock}.any? %>
<%= environment.message_for_disabled_enterprise %>
diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml
index 0c1cbe3..8edbbb1 100644
--- a/app/views/profile/index.rhtml
+++ b/app/views/profile/index.rhtml
@@ -1,4 +1,4 @@
-<% if profile.enterprise? and !profile.enabled? %>
+<% if profile.enterprise? and !profile.enabled? and !profile.blocks.select {|b| b.class == DisabledEnterpriseMessageBlock}.any? %>
<%= environment.message_for_disabled_enterprise %>
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index fd09507..f8f5b4a 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -325,6 +325,16 @@ class ContentViewerControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise
end
+ should 'not show message for disabled enterprise if there is a block for it' do
+ login_as(@profile.identifier)
+ ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
+ ent.boxes << Box.new
+ ent.boxes[0].blocks << DisabledEnterpriseMessageBlock.new
+ ent.save
+ get :view_page, :profile => ent.identifier, :page => []
+ assert_no_tag :tag => 'div', :attributes => {:id => 'article'}, :descendant => { :tag => 'div', :attributes => { :id => 'profile-disabled' }}
+ end
+
should 'load the correct profile when using hosted domain' do
profile = create_user('mytestuser').person
profile.domains << Domain.create!(:name => 'micojones.net')
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 9f77075..d54b86b 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -243,6 +243,16 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise
end
+ should 'not show message for disabled enterprise if there is a block for it' do
+ login_as(@profile.identifier)
+ ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
+ ent.boxes << Box.new
+ ent.boxes[0].blocks << DisabledEnterpriseMessageBlock.new
+ ent.save
+ get :index, :profile => ent.identifier
+ assert_no_tag :tag => 'div', :attributes => {:class => 'blocks'}, :descendant => { :tag => 'div', :attributes => { :id => 'profile-disabled' }}
+ end
+
should 'display "Products" link for enterprise' do
ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb
index 4e13433..6809f36 100644
--- a/test/unit/enterprise_test.rb
+++ b/test/unit/enterprise_test.rb
@@ -155,7 +155,47 @@ class EnterpriseTest < Test::Unit::TestCase
assert_includes ent.members, p
end
- should 'create EnterpriseActivation task when creating with enabled = false' do
+ should 'replace template if environment allows' do
+ template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false)
+ template.boxes.destroy_all
+ template.boxes << Box.new
+ template.boxes[0].blocks << Block.new
+ template.save!
+
+ e = Environment.default
+ e.replace_enterprise_template_when_enable = true
+ e.enterprise_template = template
+ e.save!
+
+ ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
+
+ p = create_user('test_user').person
+ ent.enable(p)
+ ent.reload
+ assert_equal 1, ent.boxes.size
+ assert_equal 1, ent.boxes[0].blocks.size
+ end
+
+ should 'not replace template if environment doesnt allow' do
+ template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false)
+ template.boxes.destroy_all
+ template.boxes << Box.new
+ template.boxes[0].blocks << Block.new
+ template.save!
+
+ e = Environment.default
+ e.enterprise_template = template
+ e.save!
+
+ ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
+
+ p = create_user('test_user').person
+ ent.enable(p)
+ ent.reload
+ assert_equal 1, ent.boxes.size
+ assert_equal 1, ent.boxes[0].blocks.size
+ end
+ should 'create EnterpriseActivation task when creating with enabled = false' do
EnterpriseActivation.delete_all
ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
assert_equal [ent], EnterpriseActivation.find(:all).map(&:enterprise)
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 85daa0b..6ae758e 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -521,4 +521,15 @@ class EnvironmentTest < Test::Unit::TestCase
assert_equal 20, env.enterprises.find_by_contents('test').total_entries
end
+ should 'set replace_enterprise_template_when_enable on environment' do
+ e = Environment.new(:name => 'Enterprise test')
+ e.replace_enterprise_template_when_enable = true
+ e.save
+ assert_equal true, e.replace_enterprise_template_when_enable
+ end
+
+ should 'not replace enterprise template when enable by default' do
+ assert_equal false, Environment.new.replace_enterprise_template_when_enable
+ end
+
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 3593d5f..4729628 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -918,9 +918,6 @@ class ProfileTest < Test::Unit::TestCase
should 'copy articles when applying template' do
template = Profile.create!(:name => 'test template', :identifier => 'test_template')
- template.boxes.destroy_all
- template.boxes << Box.new
- template.boxes[0].blocks << Block.new
template.articles.create(:name => 'template article')
template.save!
@@ -948,6 +945,31 @@ class ProfileTest < Test::Unit::TestCase
assert_not_nil p.articles.find_by_name('some article')
end
+ should 'copy header when applying template' do
+ template = Profile.create!(:name => 'test template', :identifier => 'test_template')
+ template[:custom_header] = '{name}'
+ template.save!
+
+ p = Profile.create!(:name => 'test prof', :identifier => 'test_prof')
+
+ p.apply_template(template)
+
+ assert_equal '{name}', p[:custom_header]
+ assert_equal 'test prof', p.custom_header
+ end
+
+ should 'copy footer when applying template' do
+ template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address')
+ template[:custom_footer] = '{address}'
+ template.save!
+
+ p = Profile.create!(:name => 'test prof', :identifier => 'test_prof', :address => 'Profile address')
+ p.apply_template(template)
+
+ assert_equal '{address}', p[:custom_footer]
+ assert_equal 'Profile address', p.custom_footer
+ 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