Commit fcd6492a16aa5c39aa8834f9cfbd812844bcb757
Committed by
Joenio Costa
1 parent
830bbafe
Exists in
master
and in
28 other branches
Adding the possibility to manage the user terms of use by a graphic interface
(ActionItem1502)
Showing
5 changed files
with
68 additions
and
2 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -209,7 +209,7 @@ class Environment < ActiveRecord::Base |
209 | 209 | |
210 | 210 | # sets the environment's terms of use. |
211 | 211 | def terms_of_use=(value) |
212 | - self.settings['terms_of_use'] = value | |
212 | + self.settings['terms_of_use'] = value.blank? ? nil : value | |
213 | 213 | end |
214 | 214 | |
215 | 215 | # returns <tt>true</tt> if this Environment has terms of use to be | ... | ... |
app/views/admin_panel/index.rhtml
... | ... | @@ -13,4 +13,5 @@ |
13 | 13 | <tr><td><%= link_to _('Edit Templates'), :action => 'edit_templates' %></td></tr> |
14 | 14 | <tr><td><%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr> |
15 | 15 | <tr><td><%= link_to _('Set Portal'), :action => 'set_portal_community' %></td></tr> |
16 | + <tr><td><%= link_to _('Terms of use'), :action => 'terms_of_use' %></td></tr> | |
16 | 17 | </table> | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +<h2><%= _('Terms of use') %></h2> | |
2 | + | |
3 | +<%= render :file => 'shared/tiny_mce' %> | |
4 | + | |
5 | +<% labelled_form_for :environment, @environment, :url => {:action => 'site_info'} do |f| %> | |
6 | + | |
7 | + <%= f.text_area :terms_of_use, :cols => 40, :style => 'width: 90%' %> | |
8 | + | |
9 | + <% button_bar do %> | |
10 | + <%= submit_button(:save, _('Save')) %> | |
11 | + <%= button(:cancel, _('Cancel'), :action => 'index') %> | |
12 | + <% end %> | |
13 | + | |
14 | +<% end %> | ... | ... |
test/functional/admin_panel_controller_test.rb
... | ... | @@ -66,7 +66,12 @@ class AdminPanelControllerTest < Test::Unit::TestCase |
66 | 66 | get :index |
67 | 67 | assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/message_for_disabled_enterprise' } |
68 | 68 | end |
69 | - | |
69 | + | |
70 | + should 'link to define terms of use' do | |
71 | + get :index | |
72 | + assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/terms_of_use' } | |
73 | + end | |
74 | + | |
70 | 75 | should 'display form for editing site info' do |
71 | 76 | get :site_info |
72 | 77 | assert_template 'site_info' |
... | ... | @@ -79,6 +84,12 @@ class AdminPanelControllerTest < Test::Unit::TestCase |
79 | 84 | assert_tag :tag => 'textarea', :attributes => { :name => 'environment[message_for_disabled_enterprise]'} |
80 | 85 | end |
81 | 86 | |
87 | + should 'display form for editing terms of use' do | |
88 | + get :terms_of_use | |
89 | + assert_template 'terms_of_use' | |
90 | + assert_tag :tag => 'textarea', :attributes => { :name => 'environment[terms_of_use]'} | |
91 | + end | |
92 | + | |
82 | 93 | should 'save site description' do |
83 | 94 | post :site_info, :environment => { :description => "This is my new environment" } |
84 | 95 | assert_redirected_to :action => 'index' |
... | ... | @@ -93,6 +104,23 @@ class AdminPanelControllerTest < Test::Unit::TestCase |
93 | 104 | assert_equal "This enterprise is disabled", Environment.default.message_for_disabled_enterprise |
94 | 105 | end |
95 | 106 | |
107 | + should 'save content of terms of use' do | |
108 | + content = "This is my term of use" | |
109 | + post :site_info, :environment => { :terms_of_use => content } | |
110 | + assert_redirected_to :action => 'index' | |
111 | + | |
112 | + assert_equal content, Environment.default.terms_of_use | |
113 | + assert Environment.default.has_terms_of_use? | |
114 | + end | |
115 | + | |
116 | + should 'not save empty string as terms of use' do | |
117 | + content = "" | |
118 | + post :site_info, :environment => { :terms_of_use => content } | |
119 | + assert_redirected_to :action => 'index' | |
120 | + | |
121 | + assert !Environment.default.has_terms_of_use? | |
122 | + end | |
123 | + | |
96 | 124 | should 'sanitize message for disabled enterprise with white_list' do |
97 | 125 | post :site_info, :environment => { :message_for_disabled_enterprise => "This <strong>is</strong> <script>alert('alow')</script>my new environment" } |
98 | 126 | assert_redirected_to :action => 'index' | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -71,6 +71,16 @@ class EnvironmentTest < Test::Unit::TestCase |
71 | 71 | assert_equal 'To be part of this environment, you must accept the following terms: ...', Environment.find(id).terms_of_use |
72 | 72 | end |
73 | 73 | |
74 | + should "terms of use not be an empty string" do | |
75 | + v = Environment.new(:name => 'My test environment') | |
76 | + assert_nil v.terms_of_use | |
77 | + v.terms_of_use = "" | |
78 | + assert v.save | |
79 | + assert !v.has_terms_of_use? | |
80 | + id = v.id | |
81 | + assert_nil Environment.find(v.id).terms_of_use | |
82 | + end | |
83 | + | |
74 | 84 | def test_has_terms_of_use |
75 | 85 | v = Environment.new |
76 | 86 | assert !v.has_terms_of_use? |
... | ... | @@ -902,4 +912,17 @@ class EnvironmentTest < Test::Unit::TestCase |
902 | 912 | assert_match /<!-- .* --> <h1> Wellformed html code <\/h1>/, environment.message_for_disabled_enterprise |
903 | 913 | end |
904 | 914 | |
915 | + should "not crash when set nil as terms of use" do | |
916 | + v = Environment.new(:name => 'My test environment') | |
917 | + v.terms_of_use = nil | |
918 | + assert v.save! | |
919 | + end | |
920 | + | |
921 | + should "terms of use not be an blank string" do | |
922 | + v = Environment.new(:name => 'My test environment') | |
923 | + v.terms_of_use = " " | |
924 | + assert v.save! | |
925 | + assert !v.has_terms_of_use? | |
926 | + end | |
927 | + | |
905 | 928 | end | ... | ... |