Commit b314b6eaae99b3d579d0b36d502cc0585314f62a
Committed by
Antonio Terceiro
1 parent
ff14fe17
Exists in
master
and in
29 other branches
Add environment portal community interface. closes ActionItem1488
Showing
5 changed files
with
106 additions
and
4 deletions
Show diff stats
app/controllers/admin/admin_panel_controller.rb
| ... | ... | @@ -16,6 +16,17 @@ class AdminPanelController < AdminController |
| 16 | 16 | end |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | + def manage_portal_community | |
| 20 | + params[:activate] == '1' ? environment.enable('use_portal_community') : environment.disable('use_portal_community') | |
| 21 | + environment.save | |
| 22 | + redirect_to :action => 'set_portal_community' | |
| 23 | + end | |
| 24 | + | |
| 25 | + def unset_portal_community | |
| 26 | + environment.unset_portal_community! | |
| 27 | + redirect_to :action => 'set_portal_community' | |
| 28 | + end | |
| 29 | + | |
| 19 | 30 | def set_portal_community |
| 20 | 31 | env = environment |
| 21 | 32 | @portal_community = env.portal_community || Community.new | ... | ... |
app/models/environment.rb
| ... | ... | @@ -616,7 +616,15 @@ class Environment < ActiveRecord::Base |
| 616 | 616 | end |
| 617 | 617 | |
| 618 | 618 | def portal_community=(value) |
| 619 | - settings[:portal_community_identifier] = value.identifier | |
| 619 | + settings[:portal_community_identifier] = value.nil? ? nil : value.identifier | |
| 620 | + end | |
| 621 | + | |
| 622 | + def unset_portal_community! | |
| 623 | + self.portal_community=nil | |
| 624 | + self.portal_folders=nil | |
| 625 | + self.news_amount_by_folder=nil | |
| 626 | + self.disable('use_portal_community') | |
| 627 | + self.save | |
| 620 | 628 | end |
| 621 | 629 | |
| 622 | 630 | def is_portal_community?(profile) | ... | ... |
app/views/admin_panel/set_portal_community.rhtml
| 1 | 1 | <h1> <%= _('Set Environment Portal') %></h1> |
| 2 | 2 | |
| 3 | -<% form_tag do %> | |
| 4 | - <%= labelled_form_field(_('Portal identifier'), text_field_tag('portal_community_identifier', @portal_community.identifier, :size => 40) ) %> | |
| 3 | +<% if @portal_community.new_record? %> | |
| 4 | + <% form_tag do %> | |
| 5 | + <%= labelled_form_field(_('Portal identifier'), text_field_tag('portal_community_identifier', @portal_community.identifier, :size => 40) ) %> | |
| 6 | + | |
| 7 | + <% button_bar do %> | |
| 8 | + <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %> | |
| 9 | + <% end %> | |
| 10 | + <% end %> | |
| 11 | +<% else %> | |
| 12 | + <%= _('Portal identifier: %s') % link_to(@portal_community.identifier, @portal_community.url) %> | |
| 5 | 13 | |
| 6 | 14 | <% button_bar do %> |
| 7 | - <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %> | |
| 15 | + <%if @portal_community.environment.enabled?('use_portal_community') %> | |
| 16 | + <%= button 'disable', _('Disable'), {:action => 'manage_portal_community', :activate => 0} %> | |
| 17 | + <% else %> | |
| 18 | + <%= button 'enable', _('Enable'), {:action => 'manage_portal_community', :activate => 1} %> | |
| 19 | + <% end %> | |
| 20 | + <%= button 'folder', _('Select Portal Folders'), {:action => 'set_portal_folders'} %> | |
| 21 | + <%= button 'amount', _('Define Amount by Folder'), {:action => 'set_portal_news_amount'} %> | |
| 22 | + <%= button 'delete', _('Remove'), { :action => 'unset_portal_community'} %> | |
| 8 | 23 | <% end %> |
| 9 | 24 | <% end %> | ... | ... |
test/functional/admin_panel_controller_test.rb
| ... | ... | @@ -121,6 +121,59 @@ class AdminPanelControllerTest < Test::Unit::TestCase |
| 121 | 121 | assert_equal c, e.portal_community |
| 122 | 122 | end |
| 123 | 123 | |
| 124 | + should 'unset portal community' do | |
| 125 | + e = Environment.default | |
| 126 | + @controller.stubs(:environment).returns(e) | |
| 127 | + c = Community.create!(:name => 'portal_community') | |
| 128 | + | |
| 129 | + get :unset_portal_community | |
| 130 | + e.reload | |
| 131 | + | |
| 132 | + assert_nil e.portal_community | |
| 133 | + assert_equal false, e.enabled?('use_portal_community') | |
| 134 | + end | |
| 135 | + | |
| 136 | + should 'redirect to set_portal_community after unset portal community' do | |
| 137 | + e = Environment.default | |
| 138 | + @controller.stubs(:environment).returns(e) | |
| 139 | + | |
| 140 | + get :unset_portal_community | |
| 141 | + assert_redirected_to :action => 'set_portal_community' | |
| 142 | + end | |
| 143 | + | |
| 144 | + should 'enable portal community' do | |
| 145 | + e = Environment.default | |
| 146 | + @controller.stubs(:environment).returns(e) | |
| 147 | + c = Community.create!(:name => 'portal_community') | |
| 148 | + e.portal_community=c | |
| 149 | + e.save | |
| 150 | + assert_equal false, e.enabled?('use_portal_community') | |
| 151 | + | |
| 152 | + get :manage_portal_community, :activate => 1 | |
| 153 | + e.reload | |
| 154 | + assert_equal true, e.enabled?('use_portal_community') | |
| 155 | + end | |
| 156 | + | |
| 157 | + should 'disable portal community' do | |
| 158 | + e = Environment.default | |
| 159 | + @controller.stubs(:environment).returns(e) | |
| 160 | + c = Community.create!(:name => 'portal_community') | |
| 161 | + e.portal_community=c | |
| 162 | + e.save | |
| 163 | + assert_equal false, e.enabled?('use_portal_community') | |
| 164 | + | |
| 165 | + get :manage_portal_community, :activate => 0 | |
| 166 | + e.reload | |
| 167 | + assert_equal false, e.enabled?('use_portal_community') | |
| 168 | + end | |
| 169 | + | |
| 170 | + should 'redirect to set_portal_community after enable or disable portal community' do | |
| 171 | + e = Environment.default | |
| 172 | + @controller.stubs(:environment).returns(e) | |
| 173 | + get :manage_portal_community | |
| 174 | + assert_redirected_to :action => 'set_portal_community' | |
| 175 | + end | |
| 176 | + | |
| 124 | 177 | should 'change portal_community and list new portal folders as options' do |
| 125 | 178 | env = Environment.default |
| 126 | 179 | old = Community.create!(:name => 'old_portal') | ... | ... |
test/unit/environment_test.rb
| ... | ... | @@ -737,6 +737,21 @@ class EnvironmentTest < Test::Unit::TestCase |
| 737 | 737 | assert_equal c, e.portal_community |
| 738 | 738 | end |
| 739 | 739 | |
| 740 | + should 'unset the portal community' do | |
| 741 | + e = Environment.default | |
| 742 | + c = fast_create(Community) | |
| 743 | + | |
| 744 | + e.portal_community = c; e.save! | |
| 745 | + e.reload | |
| 746 | + assert_equal c, e.portal_community | |
| 747 | + e.unset_portal_community! | |
| 748 | + e.reload | |
| 749 | + assert_nil e.portal_community | |
| 750 | + assert_equal [], e.portal_folders | |
| 751 | + assert_equal 0, e.news_amount_by_folder | |
| 752 | + assert_equal false, e.enabled?('use_portal_community') | |
| 753 | + end | |
| 754 | + | |
| 740 | 755 | should 'have a set of portal folders' do |
| 741 | 756 | e = Environment.default |
| 742 | 757 | ... | ... |