diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb
index 1660e64..28eef4e 100644
--- a/app/controllers/admin/admin_panel_controller.rb
+++ b/app/controllers/admin/admin_panel_controller.rb
@@ -16,6 +16,17 @@ class AdminPanelController < AdminController
end
end
+ def manage_portal_community
+ params[:activate] == '1' ? environment.enable('use_portal_community') : environment.disable('use_portal_community')
+ environment.save
+ redirect_to :action => 'set_portal_community'
+ end
+
+ def unset_portal_community
+ environment.unset_portal_community!
+ redirect_to :action => 'set_portal_community'
+ end
+
def set_portal_community
env = environment
@portal_community = env.portal_community || Community.new
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 0d0f345..fe3c3d0 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -616,7 +616,15 @@ class Environment < ActiveRecord::Base
end
def portal_community=(value)
- settings[:portal_community_identifier] = value.identifier
+ settings[:portal_community_identifier] = value.nil? ? nil : value.identifier
+ end
+
+ def unset_portal_community!
+ self.portal_community=nil
+ self.portal_folders=nil
+ self.news_amount_by_folder=nil
+ self.disable('use_portal_community')
+ self.save
end
def is_portal_community?(profile)
diff --git a/app/views/admin_panel/set_portal_community.rhtml b/app/views/admin_panel/set_portal_community.rhtml
index dbc1693..b161f06 100644
--- a/app/views/admin_panel/set_portal_community.rhtml
+++ b/app/views/admin_panel/set_portal_community.rhtml
@@ -1,9 +1,24 @@
<%= _('Set Environment Portal') %>
-<% form_tag do %>
- <%= labelled_form_field(_('Portal identifier'), text_field_tag('portal_community_identifier', @portal_community.identifier, :size => 40) ) %>
+<% if @portal_community.new_record? %>
+ <% form_tag do %>
+ <%= labelled_form_field(_('Portal identifier'), text_field_tag('portal_community_identifier', @portal_community.identifier, :size => 40) ) %>
+
+ <% button_bar do %>
+ <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %>
+ <% end %>
+ <% end %>
+<% else %>
+ <%= _('Portal identifier: %s') % link_to(@portal_community.identifier, @portal_community.url) %>
<% button_bar do %>
- <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %>
+ <%if @portal_community.environment.enabled?('use_portal_community') %>
+ <%= button 'disable', _('Disable'), {:action => 'manage_portal_community', :activate => 0} %>
+ <% else %>
+ <%= button 'enable', _('Enable'), {:action => 'manage_portal_community', :activate => 1} %>
+ <% end %>
+ <%= button 'folder', _('Select Portal Folders'), {:action => 'set_portal_folders'} %>
+ <%= button 'amount', _('Define Amount by Folder'), {:action => 'set_portal_news_amount'} %>
+ <%= button 'delete', _('Remove'), { :action => 'unset_portal_community'} %>
<% end %>
<% end %>
diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb
index 8bfc133..166959e 100644
--- a/test/functional/admin_panel_controller_test.rb
+++ b/test/functional/admin_panel_controller_test.rb
@@ -121,6 +121,59 @@ class AdminPanelControllerTest < Test::Unit::TestCase
assert_equal c, e.portal_community
end
+ should 'unset portal community' do
+ e = Environment.default
+ @controller.stubs(:environment).returns(e)
+ c = Community.create!(:name => 'portal_community')
+
+ get :unset_portal_community
+ e.reload
+
+ assert_nil e.portal_community
+ assert_equal false, e.enabled?('use_portal_community')
+ end
+
+ should 'redirect to set_portal_community after unset portal community' do
+ e = Environment.default
+ @controller.stubs(:environment).returns(e)
+
+ get :unset_portal_community
+ assert_redirected_to :action => 'set_portal_community'
+ end
+
+ should 'enable portal community' do
+ e = Environment.default
+ @controller.stubs(:environment).returns(e)
+ c = Community.create!(:name => 'portal_community')
+ e.portal_community=c
+ e.save
+ assert_equal false, e.enabled?('use_portal_community')
+
+ get :manage_portal_community, :activate => 1
+ e.reload
+ assert_equal true, e.enabled?('use_portal_community')
+ end
+
+ should 'disable portal community' do
+ e = Environment.default
+ @controller.stubs(:environment).returns(e)
+ c = Community.create!(:name => 'portal_community')
+ e.portal_community=c
+ e.save
+ assert_equal false, e.enabled?('use_portal_community')
+
+ get :manage_portal_community, :activate => 0
+ e.reload
+ assert_equal false, e.enabled?('use_portal_community')
+ end
+
+ should 'redirect to set_portal_community after enable or disable portal community' do
+ e = Environment.default
+ @controller.stubs(:environment).returns(e)
+ get :manage_portal_community
+ assert_redirected_to :action => 'set_portal_community'
+ end
+
should 'change portal_community and list new portal folders as options' do
env = Environment.default
old = Community.create!(:name => 'old_portal')
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index fb9e8fa..ede6729 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -737,6 +737,21 @@ class EnvironmentTest < Test::Unit::TestCase
assert_equal c, e.portal_community
end
+ should 'unset the portal community' do
+ e = Environment.default
+ c = fast_create(Community)
+
+ e.portal_community = c; e.save!
+ e.reload
+ assert_equal c, e.portal_community
+ e.unset_portal_community!
+ e.reload
+ assert_nil e.portal_community
+ assert_equal [], e.portal_folders
+ assert_equal 0, e.news_amount_by_folder
+ assert_equal false, e.enabled?('use_portal_community')
+ end
+
should 'have a set of portal folders' do
e = Environment.default
--
libgit2 0.21.2