Commit 4c1e0c9f4535c1cd2292b9cc62391777ac4afdc4

Authored by Gabriela Navarro
Committed by Rodrigo Souto
1 parent 726cd88c

admin-panel: refactoring of manage organizations

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Signed-off-by: Rodrigo Souto <rodrigo@colivre.coop.br>
app/controllers/admin/admin_panel_controller.rb
... ... @@ -71,22 +71,4 @@ class AdminPanelController &lt; AdminController
71 71 end
72 72 end
73 73 end
74   -
75   - def manage_organizations_status
76   - scope = environment.organizations
77   - @filter = params[:filter] || 'any'
78   - @title = "Organization profiles"
79   - @title = @title+" - "+@filter if @filter != 'any'
80   -
81   - if @filter == 'enabled'
82   - scope = scope.visible
83   - elsif @filter == 'disabled'
84   - scope = scope.disabled
85   - end
86   -
87   - scope = scope.order('name ASC')
88   -
89   - @q = params[:q]
90   - @collection = find_by_contents(:organizations, environment, scope, @q, {:per_page => 10, :page => params[:npage]})[:results]
91   - end
92 74 end
... ...
app/controllers/admin/organizations_controller.rb 0 → 100644
... ... @@ -0,0 +1,66 @@
  1 +class OrganizationsController < AdminController
  2 +
  3 + protect 'manage_environment_organizations', :environment
  4 +
  5 + def index
  6 + @filter = params[:filter] || 'any'
  7 + @title = _('Organization profiles')
  8 + @type = params[:type] || "any"
  9 + @types_filter = [[_('All'), 'any'], [_('Community'), 'Community'], [_('Enterprise'), 'Enterprise']]
  10 + @types_filter = @types_filter | @plugins.dispatch(:organization_types_filter_options)
  11 +
  12 + scope = @plugins.dispatch_first(:filter_manage_organization_scope, @type)
  13 + if scope.blank?
  14 + scope = environment.organizations
  15 + scope = scope.where(:type => @type) if @type != 'any'
  16 + end
  17 +
  18 + if @filter == 'enabled'
  19 + scope = scope.visible
  20 + elsif @filter == 'disabled'
  21 + scope = scope.disabled
  22 + end
  23 +
  24 + scope = scope.order('name ASC')
  25 +
  26 + @q = params[:q]
  27 + @collection = find_by_contents(:organizations, environment, scope, @q, {:per_page => per_page, :page => params[:npage]})[:results]
  28 + end
  29 +
  30 + def activate
  31 + organization = environment.organizations.find(params[:id])
  32 + if organization.enable
  33 + render :text => (_('%s enabled') % organization.name).to_json
  34 + else
  35 + render :text => (_('%s could not be enabled') % organization.name).to_json
  36 + end
  37 + end
  38 +
  39 + def deactivate
  40 + organization = environment.organizations.find(params[:id])
  41 + if organization.disable
  42 + render :text => (_('%s disabled') % organization.name).to_json
  43 + else
  44 + render :text => (_('%s could not be disable') % organization.name).to_json
  45 + end
  46 + end
  47 +
  48 + def destroy
  49 + if request.post?
  50 + organization = environment.organizations.find(params[:id])
  51 + if organization && organization.destroy
  52 + render :text => (_('%s removed') % organization.name).to_json
  53 + else
  54 + render :text => (_('%s could not be removed') % organization.name).to_json
  55 + end
  56 + else
  57 + render :nothing => true
  58 + end
  59 + end
  60 +
  61 + private
  62 +
  63 + def per_page
  64 + 10
  65 + end
  66 +end
... ...
app/helpers/users_helper.rb
... ... @@ -14,7 +14,7 @@ module UsersHelper
14 14 select_field = select_tag(:filter, options, :onchange => onchange)
15 15 content_tag('div',
16 16 content_tag('strong', _('Filter')) + ': ' + select_field,
17   - :class => "environment-users-customize-search"
  17 + :class => "environment-profiles-customize-search"
18 18 )
19 19 end
20 20  
... ...
app/models/environment.rb
... ... @@ -29,6 +29,7 @@ class Environment &lt; ActiveRecord::Base
29 29 'manage_environment_roles' => N_('Manage environment roles'),
30 30 'manage_environment_validators' => N_('Manage environment validators'),
31 31 'manage_environment_users' => N_('Manage environment users'),
  32 + 'manage_environment_organizations' => N_('Manage environment organizations'),
32 33 'manage_environment_templates' => N_('Manage environment templates'),
33 34 'manage_environment_licenses' => N_('Manage environment licenses'),
34 35 'manage_environment_trusted_sites' => N_('Manage environment trusted sites'),
... ...
app/models/profile.rb
... ... @@ -957,11 +957,19 @@ private :generate_url, :url_options
957 957 self.save
958 958 end
959 959  
  960 + def disabled?
  961 + !visible
  962 + end
  963 +
960 964 def enable
961 965 self.visible = true
962 966 self.save
963 967 end
964 968  
  969 + def enabled?
  970 + visible
  971 + end
  972 +
965 973 def control_panel_settings_button
966 974 {:title => _('Edit Profile'), :icon => 'edit-profile'}
967 975 end
... ...
app/views/admin_panel/index.html.erb
... ... @@ -18,9 +18,9 @@
18 18 <table>
19 19 <tr><td><%= link_to _('User roles'), :controller => 'role' %></td></tr>
20 20 <tr><td><%= link_to _('Users'), :controller => 'users' %></td></tr>
  21 + <tr><td><%= link_to _('Organizations'), :controller => 'organizations' %></td></tr>
21 22 <tr><td><%= link_to _('Profile templates'), :controller => 'templates' %></td></tr>
22 23 <tr><td><%= link_to _('Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr>
23   - <tr><td><%= link_to _('Manage organizations status'), :action => 'manage_organizations_status' %></td></tr>
24 24 </table>
25 25  
26 26  
... ...
app/views/admin_panel/manage_organizations_status.html.erb
... ... @@ -1,69 +0,0 @@
1   -<h1><%= _('Manage organizations') %></h1>
2   -
3   -<%= form_tag( { :action => 'manage_organizations_status' }, :method => 'get', :class => 'users-search' ) do %>
4   -
5   - <div class="search-field">
6   - <span class="formfield">
7   - <%= text_field_tag 'q', @q, :title => _("Find profiles"), :style=>"width:85%" %>
8   - </span>
9   -
10   - <%= submit_button(:search, _('Search')) %>
11   - </div>
12   -
13   - <div class="environment-users-results-header">
14   - <div id='environment-users-filter-title'><%= @title %></div>
15   -
16   - <div id="environment-users-filter-filter">
17   - <strong><%= _("Filter by: ") %></strong>
18   -
19   - <select id="profile_filter_select">
20   - <%= options_for_select([['Any', 'any'],["Disabled profiles", "disabled"], ["Enabled profiles", "enabled"]], @filter) %>
21   - </select>
22   - </div>
23   - <div style="clear: both"></div>
24   - </div>
25   -
26   - <table>
27   - <colgroup>
28   - <col width="80%">
29   - <col width="20%">
30   - </colgroup>
31   -
32   - <tr>
33   - <th><%= _('Member') %></th>
34   - <th><%= _('Actions') %></th>
35   - </tr>
36   -
37   - <% @collection.each do |p| %>
38   - <tr title="<%= p.name %>">
39   - <td><%= link_to_profile p.short_name, p.identifier, :title => p.name %> </td>
40   -
41   - <td class='actions'>
42   - <div class="members-buttons-cell">
43   - <% if p.visible %>
44   - <%= 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 ?") %>
45   - <% else %>
46   - <%= 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 ?") %>
47   - <% end %>
48   - <%= 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 ?") %>
49   - </div>
50   - </td>
51   - </tr>
52   - <% end %>
53   - </table>
54   -
55   -<% end %>
56   -
57   -<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
58   -
59   -<% button_bar do %>
60   - <%= button :back, _('Back'), :controller => 'admin_panel' %>
61   -<% end %>
62   -
63   -<script type="text/javascript">
64   - jQuery(document).ready(function(){
65   - jQuery("#profile_filter_select").change(function(){
66   - document.location.href = '/admin/admin_panel/manage_organizations_status?filter='+this.value;
67   - });
68   - });
69   -</script>
70 0 \ No newline at end of file
app/views/organizations/_results.html.erb 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +<div class='results'>
  2 + <table id='organizations-list'>
  3 + <colgroup>
  4 + <col width="60%">
  5 + <col width="20%">
  6 + <col width="20%">
  7 + </colgroup>
  8 +
  9 + <tr>
  10 + <th><%= _('Profile') %></th>
  11 + <th><%= _('Actions') %></th>
  12 + <th><%= _('Type') %>
  13 +
  14 + <%= select_tag(:type, options_for_select(@types_filter, @type)) %>
  15 + </th>
  16 + </tr>
  17 +
  18 + <% @collection.each do |p| %>
  19 + <tr title="<%= p.name %>">
  20 + <td><%= link_to_profile p.short_name, p.identifier, :title => p.name %> </td>
  21 +
  22 + <td class='actions'>
  23 + <div class="members-buttons-cell">
  24 + <% if p.visible %>
  25 + <%= button_without_text :'deactivate-user', _('Deactivate'), {:action => 'deactivate', :id => p.id}, :class => 'action', 'data-confirm' => _("Do you want to deactivate this organization?") %>
  26 + <% else %>
  27 + <%= button_without_text :'activate-user', _('Activate'), {:action => 'activate', :id => p.id}, :class => 'action', 'data-confirm' => _("Do you want to activate this organization?") %>
  28 + <% end %>
  29 + <%= button_without_text :'delete', _('Remove'), {:action => 'destroy', :id => p.id}, :class => 'action', 'data-method' => :post, 'data-confirm' => _("Do you want to destroy this organization?") %>
  30 + </div>
  31 + </td>
  32 +
  33 + <td> <%= _("#{p.type}") %> </td>
  34 + </tr>
  35 + <% end %>
  36 + </table>
  37 +
  38 + <div>
  39 + <%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
  40 + </div>
  41 +</div>
... ...
app/views/organizations/index.html.erb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +<h1><%= _('Organizations') %></h1>
  2 +
  3 +<%= form_tag( { :action => 'index' }, :method => 'get', :id => 'manage-profiles' ) do %>
  4 +
  5 + <div class="search-field">
  6 + <span class="formfield">
  7 + <%= text_field_tag 'q', @q, :title => _('Find organizations'), :style=>"width:85%" %>
  8 + </span>
  9 +
  10 + <%= submit_button(:search, _('Search')) %>
  11 + </div>
  12 +
  13 + <div class="environment-profiles-results-header">
  14 + <div id='environment-profiles-filter-title'><%= @title %></div>
  15 +
  16 + <div id="environment-profiles-filter-filter">
  17 + <strong><%= _("Filter by: ") %></strong>
  18 + <%= select_tag(:filter, options_for_select([[_('Any'), 'any'],[_('Disabled'), "disabled"], [_('Enabled') , "enabled"]], @filter)) %>
  19 + </div>
  20 + <div style="clear: both"></div>
  21 + </div>
  22 +
  23 + <%= render :partial => 'results' %>
  24 +
  25 + <% button_bar do %>
  26 + <%= button :back, _('Back'), :controller => 'admin_panel' %>
  27 + <% end %>
  28 +<% end %>
  29 +
  30 +<%= javascript_include_tag 'manage-organizations' %>
... ...
app/views/organizations/index.js.erb 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../views/shared/admin/profiles/index.js.rb
0 2 \ No newline at end of file
... ...
app/views/shared/admin/profiles/index.js.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +jQuery('#manage-profiles .results').replaceWith('<%= escape_javascript(render 'results') %>');
... ...
app/views/users/_users_list.html.erb
1   -<div class="environment-users-results-header">
2   - <div id='environment-users-filter-title'><%= users_filter_title(@filter) %></div>
  1 +<div class="environment-profiles-results-header">
  2 + <div id='environment-profiles-filter-title'><%= users_filter_title(@filter) %></div>
3 3 <%= filter_selector(@filter) %>
4 4 <div style="clear: both"></div>
5 5 </div>
... ...
lib/noosfero/plugin.rb
... ... @@ -299,6 +299,18 @@ class Noosfero::Plugin
299 299 nil
300 300 end
301 301  
  302 + # -> Filters the types of organizations that are shown on manage organizations
  303 + # returns a scope filtered by the specified type
  304 + def filter_manage_organization_scope type
  305 + nil
  306 + end
  307 +
  308 + # -> Add new options for manage organization filters
  309 + # returns an array of new options
  310 + # i.e [[_('Type'), 'type'], [_('Type2'), 'type2']]
  311 + def organization_types_filter_options
  312 + nil
  313 + end
302 314 # -> Adds content to profile editor info and settings
303 315 # returns = lambda block that creates html code or raw rhtml/html.erb
304 316 def profile_editor_extras
... ...
public/javascripts/manage-organizations.js 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +(function($) {
  2 + // Pagination
  3 + $('#manage-profiles').on('click', '.pagination a', function () {
  4 + $.ajax({
  5 + url: this.href,
  6 + beforeSend: function(){$('#manage-profiles .results').addClass('fetching')},
  7 + complete: function() {$('#manage-profiles .results').removeClass('fetching')},
  8 + dataType: 'script'
  9 + })
  10 + return false;
  11 + });
  12 +
  13 + // Actions
  14 + $('#manage-profiles').on('click', '.action', function () {
  15 + if(confirm($(this).data('confirm'))) {
  16 + $.ajax({
  17 + url: this.href,
  18 + method: $(this).data('method') || 'get',
  19 + dataType: 'script',
  20 + success: function(data){
  21 + if(data)
  22 + display_notice(JSON.parse(data));
  23 + },
  24 + error: function(xhr, textStatus, message){
  25 + display_notice(message);
  26 + }
  27 + });
  28 + $('#manage-profiles').submit();
  29 + }
  30 + return false;
  31 + });
  32 +
  33 + // Sorting and Views
  34 + $('#manage-profiles select').live('change', function(){
  35 + $('#manage-profiles').submit();
  36 + });
  37 +
  38 + // Form Ajax submission
  39 + $('#manage-profiles').submit(function () {
  40 + $.ajax({
  41 + url: this.action,
  42 + data: $(this).serialize(),
  43 + beforeSend: function(){$('#manage-profiles .results').addClass('fetching')},
  44 + complete: function() {$('#manage-profiles .results').removeClass('fetching')},
  45 + dataType: 'script'
  46 + })
  47 + return false;
  48 + });
  49 +})(jQuery);
... ...
public/stylesheets/application.css
... ... @@ -4763,7 +4763,7 @@ h1#agenda-title {
4763 4763 float: right;
4764 4764 }
4765 4765  
4766   -#environment-users-search form {
  4766 +#environment-profiles-search form {
4767 4767 padding: 10px;
4768 4768 margin-bottom: 15px;
4769 4769 background-color: #E6E6E6;
... ... @@ -4771,14 +4771,14 @@ h1#agenda-title {
4771 4771 -webkit-border-radius: 5px;
4772 4772 }
4773 4773  
4774   -.environment-users-results-header {
  4774 +.environment-profiles-results-header {
4775 4775 font-size: 0.9em;
4776 4776 padding: 6px 0px 0px 0px;
4777 4777 margin:0 0 5px 0;
4778 4778 border-bottom: 2px dotted #999;
4779 4779 text-align: right;
4780 4780 }
4781   -#environment-users-filter-title {
  4781 +#environment-profiles-filter-title {
4782 4782 font-weight: bold;
4783 4783 font-size: 130%;
4784 4784 line-height: 35px;
... ...
test/factories.rb
... ... @@ -65,7 +65,7 @@ module Noosfero::Factory
65 65 ###### old stuff to be rearranged
66 66 def create_admin_user(env)
67 67 admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env)
68   - admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance'])
  68 + admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_organizations', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance'])
69 69 create(RoleAssignment, :accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env])
70 70 admin_user.login
71 71 end
... ...
test/fixtures/roles.yml
... ... @@ -35,6 +35,7 @@ four:
35 35 - moderate_comments
36 36 - perform_task
37 37 - manage_environment_users
  38 + - manage_environment_organizations
38 39 - manage_environment_templates
39 40 - manage_environment_licenses
40 41 profile_admin:
... ... @@ -94,6 +95,7 @@ environment_administrator:
94 95 - manage_environment_validators
95 96 - moderate_comments
96 97 - manage_environment_users
  98 + - manage_environment_organizations
97 99 - edit_profile
98 100 - destroy_profile
99 101 - manage_environment_templates
... ...
test/functional/admin_panel_controller_test.rb
... ... @@ -17,12 +17,12 @@ class AdminPanelControllerTest &lt; ActionController::TestCase
17 17 should 'manage the correct environment' do
18 18 current = fast_create(Environment, :name => 'test environment', :is_default => false)
19 19 current.domains.create!(:name => 'example.com')
20   -
  20 +
21 21 @request.expects(:host).returns('example.com').at_least_once
22 22 get :index
23 23 assert_equal current, assigns(:environment)
24 24 end
25   -
  25 +
26 26 should 'link to site_info editing page' do
27 27 get :index
28 28 assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/site_info' }
... ... @@ -379,36 +379,4 @@ class AdminPanelControllerTest &lt; ActionController::TestCase
379 379 assert_equal body, Environment.default.signup_welcome_screen_body
380 380 assert !Environment.default.signup_welcome_screen_body.blank?
381 381 end
382   -
383   - should 'show list to deactivate organizations' do
384   - enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
385   - disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
386   - user = create_user('user')
387   -
388   - disabled_community.disable
389   -
390   - Environment.default.add_admin user.person
391   - login_as('user')
392   -
393   - get :manage_organizations_status, :filter=>"enabled"
394   - assert_match(/Organization profiles - enabled/, @response.body)
395   - assert_match(/enabled community/, @response.body)
396   - assert_not_match(/disabled community/, @response.body)
397   - end
398   -
399   - should 'show list to activate organizations' do
400   - enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
401   - disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
402   - user = create_user('user')
403   -
404   - disabled_community.disable
405   -
406   - Environment.default.add_admin user.person
407   - login_as('user')
408   -
409   - get :manage_organizations_status, :filter=>"disabled"
410   - assert_match(/Organization profiles - disabled/, @response.body)
411   - assert_not_match(/enabled community/, @response.body)
412   - assert_match(/disabled community/, @response.body)
413   - end
414 382 end
... ...
test/functional/organizations_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,116 @@
  1 +require_relative "../test_helper"
  2 +require 'organizations_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class OrganizationsController; def rescue_action(e) raise e end; end
  6 +
  7 +class OrganizationsControllerTest < ActionController::TestCase
  8 +
  9 + def setup
  10 + @controller = OrganizationsController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 +
  14 + Environment.destroy_all
  15 + @environment = fast_create(Environment, :is_default => true)
  16 +
  17 + admin_user = create_user_with_permission('adminuser', 'manage_environment_organizations', environment)
  18 + login_as('adminuser')
  19 + end
  20 +
  21 + attr_accessor :environment
  22 +
  23 + should 'not access without right permission' do
  24 + create_user('guest')
  25 + login_as 'guest'
  26 + get :index
  27 + assert_response 403 # forbidden
  28 + end
  29 +
  30 + should 'grant access with right permission' do
  31 + get :index
  32 + assert_response :success
  33 + end
  34 +
  35 + should 'show list to deactivate organizations' do
  36 + enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
  37 + disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
  38 + disabled_community.disable
  39 +
  40 + get :index, :filter => 'enabled'
  41 +
  42 + assert_match(/enabled community/, @response.body)
  43 + assert_not_match(/disabled community/, @response.body)
  44 + end
  45 +
  46 + should 'show list to activate organizations' do
  47 + enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
  48 + disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
  49 + disabled_community.disable
  50 +
  51 + get :index, :filter => 'disabled'
  52 +
  53 + assert_not_match(/enabled community/, @response.body)
  54 + assert_match(/disabled community/, @response.body)
  55 + end
  56 +
  57 + should 'show list only of enterprises' do
  58 + community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
  59 + enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
  60 +
  61 + get :index, :type => 'Enterprise'
  62 +
  63 + assert_match(/Enterprise Test/, @response.body)
  64 + assert_not_match(/Community Test/, @response.body)
  65 + end
  66 +
  67 + should 'show list only of communities' do
  68 + community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
  69 + enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
  70 +
  71 + get :index, :type => 'Community'
  72 +
  73 + assert_not_match(/Enterprise Test/, @response.body)
  74 + assert_match(/Community Test/, @response.body)
  75 + end
  76 +
  77 + should 'show list all organizations' do
  78 + community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
  79 + enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
  80 +
  81 + get :index, :type => 'any'
  82 +
  83 + assert_match(/Enterprise Test/, @response.body)
  84 + assert_match(/Community Test/, @response.body)
  85 + end
  86 +
  87 + should 'activate organization profile' do
  88 + organization = fast_create(Organization, :visible => false, :environment_id => environment.id)
  89 + assert organization.disabled?
  90 +
  91 + get :activate, {:id => organization.id}
  92 + organization.reload
  93 +
  94 + assert organization.enabled?
  95 + end
  96 +
  97 + should 'deactivate organization profile' do
  98 + organization = fast_create(Organization, :visible => true, :environment_id => environment.id)
  99 + assert organization.enabled?
  100 +
  101 + get :deactivate, {:id => organization.id}
  102 + organization.reload
  103 +
  104 + assert organization.disabled?
  105 + end
  106 +
  107 + should 'destroy organization profile' do
  108 + organization = fast_create(Organization, :environment_id => environment.id)
  109 +
  110 + post :destroy, {:id => organization.id}
  111 +
  112 + assert_raise ActiveRecord::RecordNotFound do
  113 + organization.reload
  114 + end
  115 + end
  116 +end
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -1152,57 +1152,4 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
1152 1152 get :index, :profile => user.identifier
1153 1153 assert_tag :tag => 'div', :descendant => { :tag => 'a', :content => 'Edit Header and Footer' }
1154 1154 end
1155   -
1156   - should 'deactivate organization profile' do
1157   - @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
1158   - user = create_user('user').person
1159   - Environment.default.add_admin user
1160   - login_as('user')
1161   -
1162   - community = fast_create(Community)
1163   - assert_equal true, community.enable
1164   -
1165   - get :index, :profile => community.identifier
1166   - get :deactivate_profile, {:profile => community.identifier, :id => community.id}
1167   - assert_equal @request.session[:notice], "The profile '#{community.name}' was deactivated."
1168   - end
1169   -
1170   - should 'activate organization profile' do
1171   - @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
1172   - user = create_user('user').person
1173   - Environment.default.add_admin user
1174   - login_as('user')
1175   -
1176   - community = fast_create(Community)
1177   - assert_equal true, community.disable
1178   -
1179   - get :index, :profile => community.identifier
1180   - get :activate_profile, {:profile => community.identifier, :id => community.id}
1181   - assert_equal @request.session[:notice], "The profile '#{community.name}' was activated."
1182   - end
1183   -
1184   - should 'not deactivate organization profile if user is not an admin' do
1185   - @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
1186   - user = create_user('user').person
1187   - login_as('user')
1188   -
1189   - community = fast_create(Community)
1190   - get :index, :profile => community.identifier
1191   - get :deactivate_profile, {:profile => community.identifier, :id => community.id}
1192   - assert_not_equal @request.session[:notice], "The profile '#{community.name}' was disabled."
1193   - end
1194   -
1195   - should 'destroy organization profile' do
1196   - @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
1197   - user = create_user('user').person
1198   - Environment.default.add_admin user
1199   - login_as('user')
1200   -
1201   - community = fast_create(Community)
1202   - assert_equal true, community.enable
1203   -
1204   - get :index, :profile => community.identifier
1205   - post :destroy_profile, {:profile => community.identifier, :id => community.id}
1206   - assert_equal @request.session[:notice], "The profile was deleted."
1207   - end
1208 1155 end
... ...