Commit 99de90c22994fc84392b4e419d99c04c77e496b2
Committed by
Luciano Prestes
1 parent
28ce7315
Exists in
merge_deactive_and_ban
deactive_and_active_profile: Add deactive and active profiles on administration
(ActionItem3287) Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
6 changed files
with
110 additions
and
2 deletions
Show diff stats
app/controllers/admin/admin_panel_controller.rb
| ... | ... | @@ -71,4 +71,22 @@ class AdminPanelController < AdminController |
| 71 | 71 | end |
| 72 | 72 | end |
| 73 | 73 | end |
| 74 | + | |
| 75 | + def manage_profile_status | |
| 76 | + scope = environment.profiles | |
| 77 | + @filter = params[:filter] || 'any' | |
| 78 | + @title = "All 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(:people, scope, @q, {:per_page => 10, :page => params[:npage]})[:results] | |
| 91 | + end | |
| 74 | 92 | end | ... | ... |
app/controllers/my_profile/profile_editor_controller.rb
| ... | ... | @@ -90,6 +90,20 @@ class ProfileEditorController < MyProfileController |
| 90 | 90 | end |
| 91 | 91 | end |
| 92 | 92 | |
| 93 | - redirect_to "/" | |
| 93 | + redirect_to request.referer | |
| 94 | + end | |
| 95 | + | |
| 96 | + def activate_profile | |
| 97 | + if environment.admins.include?(current_person) | |
| 98 | + profile = Profile.find(params[:id]) | |
| 99 | + | |
| 100 | + if profile.enable | |
| 101 | + session[:notice] = _("The profile '#{profile.name}' was activated.") | |
| 102 | + else | |
| 103 | + session[:notice] = _('Could not activate the profile.') | |
| 104 | + end | |
| 105 | + end | |
| 106 | + | |
| 107 | + redirect_to request.referer | |
| 94 | 108 | end |
| 95 | 109 | end | ... | ... |
app/models/profile.rb
| ... | ... | @@ -121,6 +121,7 @@ class Profile < ActiveRecord::Base |
| 121 | 121 | end |
| 122 | 122 | |
| 123 | 123 | scope :visible, :conditions => { :visible => true } |
| 124 | + scope :disabled, :conditions => { :visible => false } | |
| 124 | 125 | scope :public, :conditions => { :visible => true, :public_profile => true } |
| 125 | 126 | |
| 126 | 127 | # Subclasses must override this method |
| ... | ... | @@ -900,6 +901,11 @@ private :generate_url, :url_options |
| 900 | 901 | def disable |
| 901 | 902 | end |
| 902 | 903 | |
| 904 | + def enable | |
| 905 | + self.visible = true | |
| 906 | + self.save | |
| 907 | + end | |
| 908 | + | |
| 903 | 909 | def control_panel_settings_button |
| 904 | 910 | {:title => _('Edit Profile'), :icon => 'edit-profile'} |
| 905 | 911 | end | ... | ... |
app/views/admin_panel/index.html.erb
| ... | ... | @@ -20,6 +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 | 24 | </table> |
| 24 | 25 | |
| 25 | 26 | ... | ... |
| ... | ... | @@ -0,0 +1,64 @@ |
| 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> | |
| 0 | 65 | \ No newline at end of file | ... | ... |
app/views/profile_editor/edit.html.erb
| ... | ... | @@ -69,7 +69,12 @@ |
| 69 | 69 | <%= button(:remove, _('Delete profile'), {:action => :destroy_profile}) %> |
| 70 | 70 | |
| 71 | 71 | <% if environment.admins.include?(current_person) %> |
| 72 | - <%= button(:remove, _('Deactivate profile'), {:action => :deactivate_profile, :id=>profile.id}, :data => {:confirm=>_("Are you sure ?")}) %> | |
| 72 | + | |
| 73 | + <% if profile.visible? %> | |
| 74 | + <%= button(:remove, _('Deactivate profile'), {:action => :deactivate_profile, :id=>profile.id}, :data => {:confirm=>_("Are you sure ?")}) %> | |
| 75 | + <% else %> | |
| 76 | + <%= button(:add, _('Activate profile'), {:action => :activate_profile, :id=>profile.id}, :data => {:confirm=>_("Are you sure ?")}) %> | |
| 77 | + <% end %> | |
| 73 | 78 | <% end %> |
| 74 | 79 | <% end %> |
| 75 | 80 | <% end %> | ... | ... |