diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb
index 6c2b103..86fb9e6 100644
--- a/app/controllers/admin/admin_panel_controller.rb
+++ b/app/controllers/admin/admin_panel_controller.rb
@@ -71,4 +71,22 @@ class AdminPanelController < AdminController
end
end
end
+
+ def manage_organizations_status
+ scope = environment.organizations
+ @filter = params[:filter] || 'any'
+ @title = "Organization profiles"
+ @title = @title+" - "+@filter if @filter != 'any'
+
+ if @filter == 'enabled'
+ scope = scope.visible
+ elsif @filter == 'disabled'
+ scope = scope.disabled
+ end
+
+ scope = scope.order('name ASC')
+
+ @q = params[:q]
+ @collection = find_by_contents(:organizations, scope, @q, {:per_page => 10, :page => params[:npage]})[:results]
+ end
end
diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb
index cf1055f..1e5eaed 100644
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -74,10 +74,51 @@ class ProfileEditorController < MyProfileController
if request.post?
if @profile.destroy
session[:notice] = _('The profile was deleted.')
- redirect_to :controller => 'home'
+ if(params[:return_to])
+ redirect_to params[:return_to]
+ else
+ redirect_to :controller => 'home'
+ end
else
session[:notice] = _('Could not delete profile')
end
end
end
+
+ def deactivate_profile
+ if environment.admins.include?(current_person)
+ profile = environment.profiles.find(params[:id])
+ if profile.disable
+ profile.save
+ session[:notice] = _("The profile '#{profile.name}' was deactivated.")
+ else
+ session[:notice] = _('Could not deactivate profile.')
+ end
+ end
+
+ redirect_to_previous_location
+ end
+
+ def activate_profile
+ if environment.admins.include?(current_person)
+ profile = environment.profiles.find(params[:id])
+
+ if profile.enable
+ session[:notice] = _("The profile '#{profile.name}' was activated.")
+ else
+ session[:notice] = _('Could not activate the profile.')
+ end
+ end
+
+ redirect_to_previous_location
+ end
+
+ protected
+
+ def redirect_to_previous_location
+ back = request.referer
+ back = "/" if back.nil?
+
+ redirect_to back
+ end
end
diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb
index a20b1b7..d21be7c 100644
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -97,7 +97,12 @@ class Enterprise < Organization
self.tasks.where(:type => 'EnterpriseActivation').first
end
- def enable(owner)
+ def enable(owner = nil)
+ if owner.nil?
+ self.visible = true
+ return self.save
+ end
+
return if enabled
# must be set first for the following to work
self.enabled = true
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 490a672..4e309de 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -121,6 +121,7 @@ class Profile < ActiveRecord::Base
end
scope :visible, :conditions => { :visible => true }
+ scope :disabled, :conditions => { :visible => false }
scope :public, :conditions => { :visible => true, :public_profile => true }
# Subclasses must override this method
@@ -775,7 +776,7 @@ private :generate_url, :url_options
end
include Noosfero::Plugin::HotSpot
-
+
def folder_types
types = Article.folder_types
plugins.dispatch(:content_types).each {|type|
@@ -899,6 +900,13 @@ private :generate_url, :url_options
end
def disable
+ self.visible = false
+ self.save
+ end
+
+ def enable
+ self.visible = true
+ self.save
end
def control_panel_settings_button
diff --git a/app/views/admin_panel/index.html.erb b/app/views/admin_panel/index.html.erb
index 163a6a0..f5980be 100644
--- a/app/views/admin_panel/index.html.erb
+++ b/app/views/admin_panel/index.html.erb
@@ -20,6 +20,7 @@
<%= link_to _('Users'), :controller => 'users' %> |
<%= link_to _('Profile templates'), :controller => 'templates' %> |
<%= link_to _('Fields'), :controller => 'features', :action => 'manage_fields' %> |
+ <%= link_to _('Manage organizations status'), :action => 'manage_organizations_status' %> |
diff --git a/app/views/admin_panel/manage_organizations_status.html.erb b/app/views/admin_panel/manage_organizations_status.html.erb
new file mode 100644
index 0000000..3a708f1
--- /dev/null
+++ b/app/views/admin_panel/manage_organizations_status.html.erb
@@ -0,0 +1,69 @@
+<%= _('Manage organizations') %>
+
+<%= form_tag( { :action => 'manage_organizations_status' }, :method => 'get', :class => 'users-search' ) do %>
+
+
+
+ <%= text_field_tag 'q', @q, :title => _("Find profiles"), :style=>"width:85%" %>
+
+
+ <%= submit_button(:search, _('Search')) %>
+
+
+
+
+
+
+
+
+
+
+
+ <%= _('Member') %> |
+ <%= _('Actions') %> |
+
+
+ <% @collection.each do |p| %>
+
+ <%= link_to_profile p.short_name, p.identifier, :title => p.name %> |
+
+
+
+ <% if p.visible %>
+ <%= button_without_text :'deactivate-user', _('Deactivate'), {:controller => "profile_editor", :action => 'deactivate_profile', :profile => p.identifier, :id => p.id}, :confirm => _("Do you want to deactivate this profile ?") %>
+ <% else %>
+ <%= button_without_text :'activate-user', _('Activate'), {:controller => "profile_editor", :action => 'activate_profile', :profile => p.identifier, :id => p.id}, :confirm => _("Do you want to activate this profile ?") %>
+ <% end %>
+ <%= button_without_text :'delete', _('Remove'), {:controller => "profile_editor", :action => 'destroy_profile', :profile => p.identifier, :id => p.id, :return_to => "/admin/admin_panel/manage_organizations_status"}, :method => :post, :confirm => _("Do you want to deactivate this profile ?") %>
+
+ |
+
+ <% end %>
+
+
+<% end %>
+
+<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
+
+<% button_bar do %>
+ <%= button :back, _('Back'), :controller => 'admin_panel' %>
+<% end %>
+
+
\ No newline at end of file
diff --git a/app/views/profile_editor/edit.html.erb b/app/views/profile_editor/edit.html.erb
index abef586..437cab7 100644
--- a/app/views/profile_editor/edit.html.erb
+++ b/app/views/profile_editor/edit.html.erb
@@ -1,5 +1,6 @@
<%= _('Profile settings for %s') % profile.name %>
+<%= javascript_include_tag 'deactivate_profile' %>
<%= error_messages_for :profile_data %>
<%= labelled_form_for :profile_data, :html => { :id => 'profile-data', :multipart => true } do |f| %>
@@ -67,6 +68,15 @@
<% if user && user.has_permission?('destroy_profile', profile) %>
<% button_bar(:id => 'delete-profile') do %>
<%= button(:remove, _('Delete profile'), {:action => :destroy_profile}) %>
+
+ <% if environment.admins.include?(current_person) %>
+
+ <% if profile.visible? %>
+ <%= button(:remove, _('Deactivate profile'), {:action => :deactivate_profile, :id=>profile.id}, :id=>'deactivate_profile_button', :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %>
+ <% else %>
+ <%= button(:add, _('Activate profile'), {:action => :activate_profile, :id=>profile.id}, :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %>
+ <% end %>
+ <% end %>
<% end %>
<% end %>
-<% end %>
+<% end %>
\ No newline at end of file
diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb
index 01583c1..c614231 100644
--- a/test/functional/admin_panel_controller_test.rb
+++ b/test/functional/admin_panel_controller_test.rb
@@ -378,4 +378,35 @@ class AdminPanelControllerTest < ActionController::TestCase
assert !Environment.default.signup_welcome_screen_body.blank?
end
+ should 'show list to deactivate organizations' do
+ enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
+ disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
+ user = create_user('user')
+
+ disabled_community.disable
+
+ Environment.default.add_admin user.person
+ login_as('user')
+
+ get :manage_organizations_status, :filter=>"enabled"
+ assert_match(/Organization profiles - enabled/, @response.body)
+ assert_match(/enabled community/, @response.body)
+ assert_not_match(/disabled community/, @response.body)
+ end
+
+ should 'show list to activate organizations' do
+ enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
+ disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
+ user = create_user('user')
+
+ disabled_community.disable
+
+ Environment.default.add_admin user.person
+ login_as('user')
+
+ get :manage_organizations_status, :filter=>"disabled"
+ assert_match(/Organization profiles - disabled/, @response.body)
+ assert_not_match(/enabled community/, @response.body)
+ assert_match(/disabled community/, @response.body)
+ end
end
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index 7bde51f..d1f014f 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -1095,4 +1095,57 @@ class ProfileEditorControllerTest < ActionController::TestCase
get :index, :profile => user.identifier
assert_tag :tag => 'div', :descendant => { :tag => 'a', :content => 'Edit Header and Footer' }
end
+
+ should 'deactivate organization profile' do
+ @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+ user = create_user('user').person
+ Environment.default.add_admin user
+ login_as('user')
+
+ community = fast_create(Community)
+ assert_equal true, community.enable
+
+ get :index, :profile => community.identifier
+ get :deactivate_profile, {:profile => community.identifier, :id => community.id}
+ assert_equal @request.session[:notice], "The profile '#{community.name}' was deactivated."
+ end
+
+ should 'activate organization profile' do
+ @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+ user = create_user('user').person
+ Environment.default.add_admin user
+ login_as('user')
+
+ community = fast_create(Community)
+ assert_equal true, community.disable
+
+ get :index, :profile => community.identifier
+ get :activate_profile, {:profile => community.identifier, :id => community.id}
+ assert_equal @request.session[:notice], "The profile '#{community.name}' was activated."
+ end
+
+ should 'not deactivate organization profile if user is not an admin' do
+ @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+ user = create_user('user').person
+ login_as('user')
+
+ community = fast_create(Community)
+ get :index, :profile => community.identifier
+ get :deactivate_profile, {:profile => community.identifier, :id => community.id}
+ assert_not_equal @request.session[:notice], "The profile '#{community.name}' was disabled."
+ end
+
+ should 'destroy organization profile' do
+ @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+ user = create_user('user').person
+ Environment.default.add_admin user
+ login_as('user')
+
+ community = fast_create(Community)
+ assert_equal true, community.enable
+
+ get :index, :profile => community.identifier
+ post :destroy_profile, {:profile => community.identifier, :id => community.id}
+ assert_equal @request.session[:notice], "The profile was deleted."
+ end
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 5d03d65..f6e2790 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -1955,4 +1955,22 @@ class ProfileTest < ActiveSupport::TestCase
p = fast_create(Profile)
assert p.folder_types.include?('ProfileTest::Folder1')
end
+
+ should 'enable profile visibility' do
+ profile = fast_create(Profile)
+
+ assert_equal true, profile.disable
+
+ assert_equal true, profile.enable
+ assert_equal true, profile.visible?
+ end
+
+ should 'disable profile visibility' do
+ profile = fast_create(Profile)
+
+ assert_equal true, profile.enable
+
+ assert_equal true, profile.disable
+ assert_equal false, profile.visible?
+ end
end
--
libgit2 0.21.2