Commit 93e419f877687a13418241136bcd3ffe5b6cf983

Authored by Joenio Costa
2 parents 32b213c1 63f6c6c0
app/models/disabled_enterprise_message_block.rb
... ... @@ -9,7 +9,7 @@ class DisabledEnterpriseMessageBlock < Block
9 9 end
10 10  
11 11 def default_title
12   - _('Localization Map')
  12 + _('Message')
13 13 end
14 14  
15 15 def content
... ...
app/models/enterprise.rb
... ... @@ -37,6 +37,9 @@ class Enterprise < Organization
37 37 return if enabled
38 38 affiliate(owner, Profile::Roles.all_roles)
39 39 update_attribute(:enabled,true)
  40 + if environment.replace_enterprise_template_when_enable
  41 + apply_template(template)
  42 + end
40 43 save
41 44 end
42 45  
... ...
app/models/environment.rb
... ... @@ -386,6 +386,14 @@ class Environment < ActiveRecord::Base
386 386 end
387 387 end
388 388  
  389 + def replace_enterprise_template_when_enable
  390 + settings[:replace_enterprise_template_when_enable] || false
  391 + end
  392 +
  393 + def replace_enterprise_template_when_enable=(value)
  394 + settings[:replace_enterprise_template_when_enable] = value
  395 + end
  396 +
389 397 after_create :create_templates
390 398  
391 399 def create_templates
... ...
app/models/profile.rb
... ... @@ -471,11 +471,11 @@ class Profile < ActiveRecord::Base
471 471 if footer
472 472 %w[contact_person contact_email contact_phone location address economic_activity].each do |att|
473 473 if self.respond_to?(att) && footer.include?("{#{att}}")
474   - footer.gsub!("{#{att}}", self.send(att).to_s)
  474 + footer = footer.gsub("{#{att}}", self.send(att).to_s)
475 475 end
476 476 end
  477 + footer
477 478 end
478   - footer
479 479 end
480 480  
481 481 def theme
... ...
app/views/admin_panel/manage_templates.rhtml
1 1 <h1><%= _('Set Templates') %></h1>
2 2  
3 3 <% labelled_form_for(:environment, @environment, :url => {:action => 'set_template'}) do |f| %>
4   -<%= current_user.name %>
5 4 <p>
6 5 <label for='environment_person_template'><%= _('Person Template') %></label><br/>
7 6 <%= 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 @@
17 16 <%= f.select :enterprise_template, @enterprise_templates.map {|item| [ item.identifier, item.id]}, :selected => (environment.enterprise_template.nil? ? nil : environment.enterprise_template.id) %>
18 17 </p>
19 18  
20   - <p>
21   - <label for='environment_inactive_enterprise_template'><%= _('Inactive Enterprise Template') %></label><br/>
22   - <%= 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) %>
23   - </p>
24   -
25 19 <% button_bar do %>
26 20 <%= submit_button(:save, _('Save')) %>
27 21 <%= button(:cancel, _('Cancel'), :action => 'index') %>
... ...
app/views/content_viewer/view_page.rhtml
... ... @@ -58,7 +58,7 @@
58 58 </div>
59 59 <% end %>
60 60  
61   -<% if profile.enterprise? and !profile.enabled? %>
  61 +<% if profile.enterprise? and !profile.enabled? and !profile.blocks.select {|b| b.class == DisabledEnterpriseMessageBlock}.any? %>
62 62 <div id='profile-disabled'>
63 63 <%= environment.message_for_disabled_enterprise %>
64 64 </div>
... ...
app/views/profile/index.rhtml
1   -<% if profile.enterprise? and !profile.enabled? %>
  1 +<% if profile.enterprise? and !profile.enabled? and !profile.blocks.select {|b| b.class == DisabledEnterpriseMessageBlock}.any? %>
2 2 <div id='profile-disabled'>
3 3 <%= environment.message_for_disabled_enterprise %>
4 4 </div>
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -325,6 +325,16 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
325 325 assert_no_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise
326 326 end
327 327  
  328 + should 'not show message for disabled enterprise if there is a block for it' do
  329 + login_as(@profile.identifier)
  330 + ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
  331 + ent.boxes << Box.new
  332 + ent.boxes[0].blocks << DisabledEnterpriseMessageBlock.new
  333 + ent.save
  334 + get :view_page, :profile => ent.identifier, :page => []
  335 + assert_no_tag :tag => 'div', :attributes => {:id => 'article'}, :descendant => { :tag => 'div', :attributes => { :id => 'profile-disabled' }}
  336 + end
  337 +
328 338 should 'load the correct profile when using hosted domain' do
329 339 profile = create_user('mytestuser').person
330 340 profile.domains << Domain.create!(:name => 'micojones.net')
... ...
test/functional/profile_controller_test.rb
... ... @@ -243,6 +243,16 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
243 243 assert_no_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise
244 244 end
245 245  
  246 + should 'not show message for disabled enterprise if there is a block for it' do
  247 + login_as(@profile.identifier)
  248 + ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
  249 + ent.boxes << Box.new
  250 + ent.boxes[0].blocks << DisabledEnterpriseMessageBlock.new
  251 + ent.save
  252 + get :index, :profile => ent.identifier
  253 + assert_no_tag :tag => 'div', :attributes => {:class => 'blocks'}, :descendant => { :tag => 'div', :attributes => { :id => 'profile-disabled' }}
  254 + end
  255 +
246 256 should 'display "Products" link for enterprise' do
247 257 ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
248 258  
... ...
test/unit/enterprise_test.rb
... ... @@ -155,7 +155,47 @@ class EnterpriseTest &lt; Test::Unit::TestCase
155 155 assert_includes ent.members, p
156 156 end
157 157  
158   - should 'create EnterpriseActivation task when creating with enabled = false' do
  158 + should 'replace template if environment allows' do
  159 + template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false)
  160 + template.boxes.destroy_all
  161 + template.boxes << Box.new
  162 + template.boxes[0].blocks << Block.new
  163 + template.save!
  164 +
  165 + e = Environment.default
  166 + e.replace_enterprise_template_when_enable = true
  167 + e.enterprise_template = template
  168 + e.save!
  169 +
  170 + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
  171 +
  172 + p = create_user('test_user').person
  173 + ent.enable(p)
  174 + ent.reload
  175 + assert_equal 1, ent.boxes.size
  176 + assert_equal 1, ent.boxes[0].blocks.size
  177 + end
  178 +
  179 + should 'not replace template if environment doesnt allow' do
  180 + template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false)
  181 + template.boxes.destroy_all
  182 + template.boxes << Box.new
  183 + template.boxes[0].blocks << Block.new
  184 + template.save!
  185 +
  186 + e = Environment.default
  187 + e.enterprise_template = template
  188 + e.save!
  189 +
  190 + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
  191 +
  192 + p = create_user('test_user').person
  193 + ent.enable(p)
  194 + ent.reload
  195 + assert_equal 1, ent.boxes.size
  196 + assert_equal 1, ent.boxes[0].blocks.size
  197 + end
  198 + should 'create EnterpriseActivation task when creating with enabled = false' do
159 199 EnterpriseActivation.delete_all
160 200 ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
161 201 assert_equal [ent], EnterpriseActivation.find(:all).map(&:enterprise)
... ...
test/unit/environment_test.rb
... ... @@ -521,4 +521,15 @@ class EnvironmentTest &lt; Test::Unit::TestCase
521 521 assert_equal 20, env.enterprises.find_by_contents('test').total_entries
522 522 end
523 523  
  524 + should 'set replace_enterprise_template_when_enable on environment' do
  525 + e = Environment.new(:name => 'Enterprise test')
  526 + e.replace_enterprise_template_when_enable = true
  527 + e.save
  528 + assert_equal true, e.replace_enterprise_template_when_enable
  529 + end
  530 +
  531 + should 'not replace enterprise template when enable by default' do
  532 + assert_equal false, Environment.new.replace_enterprise_template_when_enable
  533 + end
  534 +
524 535 end
... ...
test/unit/profile_test.rb
... ... @@ -918,9 +918,6 @@ class ProfileTest &lt; Test::Unit::TestCase
918 918  
919 919 should 'copy articles when applying template' do
920 920 template = Profile.create!(:name => 'test template', :identifier => 'test_template')
921   - template.boxes.destroy_all
922   - template.boxes << Box.new
923   - template.boxes[0].blocks << Block.new
924 921 template.articles.create(:name => 'template article')
925 922 template.save!
926 923  
... ... @@ -948,6 +945,31 @@ class ProfileTest &lt; Test::Unit::TestCase
948 945 assert_not_nil p.articles.find_by_name('some article')
949 946 end
950 947  
  948 + should 'copy header when applying template' do
  949 + template = Profile.create!(:name => 'test template', :identifier => 'test_template')
  950 + template[:custom_header] = '{name}'
  951 + template.save!
  952 +
  953 + p = Profile.create!(:name => 'test prof', :identifier => 'test_prof')
  954 +
  955 + p.apply_template(template)
  956 +
  957 + assert_equal '{name}', p[:custom_header]
  958 + assert_equal 'test prof', p.custom_header
  959 + end
  960 +
  961 + should 'copy footer when applying template' do
  962 + template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address')
  963 + template[:custom_footer] = '{address}'
  964 + template.save!
  965 +
  966 + p = Profile.create!(:name => 'test prof', :identifier => 'test_prof', :address => 'Profile address')
  967 + p.apply_template(template)
  968 +
  969 + assert_equal '{address}', p[:custom_footer]
  970 + assert_equal 'Profile address', p.custom_footer
  971 + end
  972 +
951 973 TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/profile_themes'
952 974 should 'have themes' do
953 975 Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)
... ...