diff --git a/app/models/environment.rb b/app/models/environment.rb
index 6fafaf8..af3280b 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -209,7 +209,7 @@ class Environment < ActiveRecord::Base
# sets the environment's terms of use.
def terms_of_use=(value)
- self.settings['terms_of_use'] = value
+ self.settings['terms_of_use'] = value.blank? ? nil : value
end
# returns true if this Environment has terms of use to be
diff --git a/app/views/admin_panel/index.rhtml b/app/views/admin_panel/index.rhtml
index 476f668..5fece44 100644
--- a/app/views/admin_panel/index.rhtml
+++ b/app/views/admin_panel/index.rhtml
@@ -13,4 +13,5 @@
<%= link_to _('Edit Templates'), :action => 'edit_templates' %> |
<%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %> |
<%= link_to _('Set Portal'), :action => 'set_portal_community' %> |
+ <%= link_to _('Terms of use'), :action => 'terms_of_use' %> |
diff --git a/app/views/admin_panel/terms_of_use.rhtml b/app/views/admin_panel/terms_of_use.rhtml
new file mode 100644
index 0000000..a814331
--- /dev/null
+++ b/app/views/admin_panel/terms_of_use.rhtml
@@ -0,0 +1,14 @@
+<%= _('Terms of use') %>
+
+<%= render :file => 'shared/tiny_mce' %>
+
+<% labelled_form_for :environment, @environment, :url => {:action => 'site_info'} do |f| %>
+
+ <%= f.text_area :terms_of_use, :cols => 40, :style => 'width: 90%' %>
+
+ <% button_bar do %>
+ <%= submit_button(:save, _('Save')) %>
+ <%= button(:cancel, _('Cancel'), :action => 'index') %>
+ <% end %>
+
+<% end %>
diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb
index 166959e..885715b 100644
--- a/test/functional/admin_panel_controller_test.rb
+++ b/test/functional/admin_panel_controller_test.rb
@@ -66,7 +66,12 @@ class AdminPanelControllerTest < Test::Unit::TestCase
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/message_for_disabled_enterprise' }
end
-
+
+ should 'link to define terms of use' do
+ get :index
+ assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/terms_of_use' }
+ end
+
should 'display form for editing site info' do
get :site_info
assert_template 'site_info'
@@ -79,6 +84,12 @@ class AdminPanelControllerTest < Test::Unit::TestCase
assert_tag :tag => 'textarea', :attributes => { :name => 'environment[message_for_disabled_enterprise]'}
end
+ should 'display form for editing terms of use' do
+ get :terms_of_use
+ assert_template 'terms_of_use'
+ assert_tag :tag => 'textarea', :attributes => { :name => 'environment[terms_of_use]'}
+ end
+
should 'save site description' do
post :site_info, :environment => { :description => "This is my new environment" }
assert_redirected_to :action => 'index'
@@ -93,6 +104,23 @@ class AdminPanelControllerTest < Test::Unit::TestCase
assert_equal "This enterprise is disabled", Environment.default.message_for_disabled_enterprise
end
+ should 'save content of terms of use' do
+ content = "This is my term of use"
+ post :site_info, :environment => { :terms_of_use => content }
+ assert_redirected_to :action => 'index'
+
+ assert_equal content, Environment.default.terms_of_use
+ assert Environment.default.has_terms_of_use?
+ end
+
+ should 'not save empty string as terms of use' do
+ content = ""
+ post :site_info, :environment => { :terms_of_use => content }
+ assert_redirected_to :action => 'index'
+
+ assert !Environment.default.has_terms_of_use?
+ end
+
should 'sanitize message for disabled enterprise with white_list' do
post :site_info, :environment => { :message_for_disabled_enterprise => "This is my new environment" }
assert_redirected_to :action => 'index'
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 8e7de4c..a6cff84 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -71,6 +71,16 @@ class EnvironmentTest < Test::Unit::TestCase
assert_equal 'To be part of this environment, you must accept the following terms: ...', Environment.find(id).terms_of_use
end
+ should "terms of use not be an empty string" do
+ v = Environment.new(:name => 'My test environment')
+ assert_nil v.terms_of_use
+ v.terms_of_use = ""
+ assert v.save
+ assert !v.has_terms_of_use?
+ id = v.id
+ assert_nil Environment.find(v.id).terms_of_use
+ end
+
def test_has_terms_of_use
v = Environment.new
assert !v.has_terms_of_use?
@@ -902,4 +912,17 @@ class EnvironmentTest < Test::Unit::TestCase
assert_match / Wellformed html code <\/h1>/, environment.message_for_disabled_enterprise
end
+ should "not crash when set nil as terms of use" do
+ v = Environment.new(:name => 'My test environment')
+ v.terms_of_use = nil
+ assert v.save!
+ end
+
+ should "terms of use not be an blank string" do
+ v = Environment.new(:name => 'My test environment')
+ v.terms_of_use = " "
+ assert v.save!
+ assert !v.has_terms_of_use?
+ end
+
end
--
libgit2 0.21.2