Commit efb69e9805153e52c27119580ce0c87d109f8848

Authored by Arthur Esposte
Committed by Luciano Prestes
1 parent 99de90c2

deactive_and_active_profile: Change to manage only organizations profiles status

(ActionItem3287)

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
app/controllers/admin/admin_panel_controller.rb
... ... @@ -72,10 +72,10 @@ class AdminPanelController &lt; AdminController
72 72 end
73 73 end
74 74  
75   - def manage_profile_status
76   - scope = environment.profiles
  75 + def manage_organizations_status
  76 + scope = environment.organizations
77 77 @filter = params[:filter] || 'any'
78   - @title = "All profiles"
  78 + @title = "Organization profiles"
79 79 @title = @title+" - "+@filter if @filter != 'any'
80 80  
81 81 if @filter == 'enabled'
... ... @@ -87,6 +87,6 @@ class AdminPanelController &lt; AdminController
87 87 scope = scope.order('name ASC')
88 88  
89 89 @q = params[:q]
90   - @collection = find_by_contents(:people, scope, @q, {:per_page => 10, :page => params[:npage]})[:results]
  90 + @collection = find_by_contents(:organizations, scope, @q, {:per_page => 10, :page => params[:npage]})[:results]
91 91 end
92 92 end
... ...
app/models/enterprise.rb
... ... @@ -107,7 +107,12 @@ class Enterprise &lt; Organization
107 107 self.tasks.where(:type => 'EnterpriseActivation').first
108 108 end
109 109  
110   - def enable(owner)
  110 + def enable(owner = nil)
  111 + if owner.nil?
  112 + self.visible = true
  113 + return self.save
  114 + end
  115 +
111 116 return if enabled
112 117 # must be set first for the following to work
113 118 self.enabled = true
... ...
app/models/profile.rb
... ... @@ -899,6 +899,8 @@ private :generate_url, :url_options
899 899 end
900 900  
901 901 def disable
  902 + self.visible = false
  903 + self.save
902 904 end
903 905  
904 906 def enable
... ...
app/views/admin_panel/index.html.erb
... ... @@ -20,7 +20,7 @@
20 20 <tr><td><%= link_to _('Users'), :controller => 'users' %></td></tr>
21 21 <tr><td><%= link_to _('Profile templates'), :controller => 'templates' %></td></tr>
22 22 <tr><td><%= link_to _('Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr>
23   - <tr><td><%= link_to _('Manage profiles status'), :action => 'manage_profile_status' %></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 0 → 100644
... ... @@ -0,0 +1,64 @@
  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 + </div>
  49 + </td>
  50 + </tr>
  51 + <% end %>
  52 + </table>
  53 +
  54 +<% end %>
  55 +
  56 +<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
  57 +
  58 +<script type="text/javascript">
  59 + jQuery(document).ready(function(){
  60 + jQuery("#profile_filter_select").change(function(){
  61 + document.location.href = '/admin/admin_panel/manage_organizations_status?filter='+this.value;
  62 + });
  63 + });
  64 +</script>
0 65 \ No newline at end of file
... ...
app/views/admin_panel/manage_profile_status.html.erb
... ... @@ -1,64 +0,0 @@
1   -<h1><%= _('Manage profiles') %></h1>
2   -
3   -<%= form_tag( { :action => 'manage_profile_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   - </div>
49   - </td>
50   - </tr>
51   - <% end %>
52   - </table>
53   -
54   -<% end %>
55   -
56   -<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
57   -
58   -<script type="text/javascript">
59   - jQuery(document).ready(function(){
60   - jQuery("#profile_filter_select").change(function(){
61   - document.location.href = '/admin/admin_panel/manage_profile_status?filter='+this.value;
62   - });
63   - });
64   -</script>
65 0 \ No newline at end of file
test/unit/profile_test.rb
... ... @@ -1955,4 +1955,13 @@ class ProfileTest &lt; ActiveSupport::TestCase
1955 1955 p = fast_create(Profile)
1956 1956 assert p.folder_types.include?('ProfileTest::Folder1')
1957 1957 end
  1958 +
  1959 + should 'enable profile visibility' do
  1960 + profile = fast_create(Profile)
  1961 +
  1962 + assert profile.enable, _("Profile should have been enabled")
  1963 + assert profile.visible, _("Profile should be visible")
  1964 + profile.disable
  1965 + assert !profile.visible, _("Profile should not be visible")
  1966 + end
1958 1967 end
... ...