Commit 6984558b1999dee376d38ced3deee8dfbca83ee7
Committed by
Arthur Esposte
1 parent
98e92d96
Exists in
master
and in
22 other branches
Add UI to activate and deactivate profiles
(ActionItem3287) It can be done while edit a profile or in environment administration panel Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
10 changed files
with
258 additions
and
4 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_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, scope, @q, {:per_page => 10, :page => params[:npage]})[:results] | |
| 91 | + end | |
| 74 | 92 | end | ... | ... |
app/controllers/my_profile/profile_editor_controller.rb
| ... | ... | @@ -74,10 +74,51 @@ class ProfileEditorController < MyProfileController |
| 74 | 74 | if request.post? |
| 75 | 75 | if @profile.destroy |
| 76 | 76 | session[:notice] = _('The profile was deleted.') |
| 77 | - redirect_to :controller => 'home' | |
| 77 | + if(params[:return_to]) | |
| 78 | + redirect_to params[:return_to] | |
| 79 | + else | |
| 80 | + redirect_to :controller => 'home' | |
| 81 | + end | |
| 78 | 82 | else |
| 79 | 83 | session[:notice] = _('Could not delete profile') |
| 80 | 84 | end |
| 81 | 85 | end |
| 82 | 86 | end |
| 87 | + | |
| 88 | + def deactivate_profile | |
| 89 | + if environment.admins.include?(current_person) | |
| 90 | + profile = environment.profiles.find(params[:id]) | |
| 91 | + if profile.disable | |
| 92 | + profile.save | |
| 93 | + session[:notice] = _("The profile '#{profile.name}' was deactivated.") | |
| 94 | + else | |
| 95 | + session[:notice] = _('Could not deactivate profile.') | |
| 96 | + end | |
| 97 | + end | |
| 98 | + | |
| 99 | + redirect_to_previous_location | |
| 100 | + end | |
| 101 | + | |
| 102 | + def activate_profile | |
| 103 | + if environment.admins.include?(current_person) | |
| 104 | + profile = environment.profiles.find(params[:id]) | |
| 105 | + | |
| 106 | + if profile.enable | |
| 107 | + session[:notice] = _("The profile '#{profile.name}' was activated.") | |
| 108 | + else | |
| 109 | + session[:notice] = _('Could not activate the profile.') | |
| 110 | + end | |
| 111 | + end | |
| 112 | + | |
| 113 | + redirect_to_previous_location | |
| 114 | + end | |
| 115 | + | |
| 116 | + protected | |
| 117 | + | |
| 118 | + def redirect_to_previous_location | |
| 119 | + back = request.referer | |
| 120 | + back = "/" if back.nil? | |
| 121 | + | |
| 122 | + redirect_to back | |
| 123 | + end | |
| 83 | 124 | end | ... | ... |
app/models/enterprise.rb
| ... | ... | @@ -97,7 +97,12 @@ class Enterprise < Organization |
| 97 | 97 | self.tasks.where(:type => 'EnterpriseActivation').first |
| 98 | 98 | end |
| 99 | 99 | |
| 100 | - def enable(owner) | |
| 100 | + def enable(owner = nil) | |
| 101 | + if owner.nil? | |
| 102 | + self.visible = true | |
| 103 | + return self.save | |
| 104 | + end | |
| 105 | + | |
| 101 | 106 | return if enabled |
| 102 | 107 | # must be set first for the following to work |
| 103 | 108 | self.enabled = true | ... | ... |
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 |
| ... | ... | @@ -775,7 +776,7 @@ private :generate_url, :url_options |
| 775 | 776 | end |
| 776 | 777 | |
| 777 | 778 | include Noosfero::Plugin::HotSpot |
| 778 | - | |
| 779 | + | |
| 779 | 780 | def folder_types |
| 780 | 781 | types = Article.folder_types |
| 781 | 782 | plugins.dispatch(:content_types).each {|type| |
| ... | ... | @@ -899,6 +900,13 @@ private :generate_url, :url_options |
| 899 | 900 | end |
| 900 | 901 | |
| 901 | 902 | def disable |
| 903 | + self.visible = false | |
| 904 | + self.save | |
| 905 | + end | |
| 906 | + | |
| 907 | + def enable | |
| 908 | + self.visible = true | |
| 909 | + self.save | |
| 902 | 910 | end |
| 903 | 911 | |
| 904 | 912 | def control_panel_settings_button | ... | ... |
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 organizations status'), :action => 'manage_organizations_status' %></td></tr> | |
| 23 | 24 | </table> |
| 24 | 25 | |
| 25 | 26 | ... | ... |
app/views/admin_panel/manage_organizations_status.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,69 @@ |
| 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> | |
| 0 | 70 | \ No newline at end of file | ... | ... |
app/views/profile_editor/edit.html.erb
| 1 | 1 | <h1><%= _('Profile settings for %s') % profile.name %></h1> |
| 2 | 2 | |
| 3 | +<%= javascript_include_tag 'deactivate_profile' %> | |
| 3 | 4 | <%= error_messages_for :profile_data %> |
| 4 | 5 | |
| 5 | 6 | <%= labelled_form_for :profile_data, :html => { :id => 'profile-data', :multipart => true } do |f| %> |
| ... | ... | @@ -67,6 +68,15 @@ |
| 67 | 68 | <% if user && user.has_permission?('destroy_profile', profile) %> |
| 68 | 69 | <% button_bar(:id => 'delete-profile') do %> |
| 69 | 70 | <%= button(:remove, _('Delete profile'), {:action => :destroy_profile}) %> |
| 71 | + | |
| 72 | + <% if environment.admins.include?(current_person) %> | |
| 73 | + | |
| 74 | + <% if profile.visible? %> | |
| 75 | + <%= 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?")}) %> | |
| 76 | + <% else %> | |
| 77 | + <%= button(:add, _('Activate profile'), {:action => :activate_profile, :id=>profile.id}, :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %> | |
| 78 | + <% end %> | |
| 79 | + <% end %> | |
| 70 | 80 | <% end %> |
| 71 | 81 | <% end %> |
| 72 | 82 | -<% end %> |
| 83 | +<% end %> | |
| 73 | 84 | \ No newline at end of file | ... | ... |
test/functional/admin_panel_controller_test.rb
| ... | ... | @@ -378,4 +378,35 @@ class AdminPanelControllerTest < ActionController::TestCase |
| 378 | 378 | assert !Environment.default.signup_welcome_screen_body.blank? |
| 379 | 379 | end |
| 380 | 380 | |
| 381 | + should 'show list to deactivate organizations' do | |
| 382 | + enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community") | |
| 383 | + disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community") | |
| 384 | + user = create_user('user') | |
| 385 | + | |
| 386 | + disabled_community.disable | |
| 387 | + | |
| 388 | + Environment.default.add_admin user.person | |
| 389 | + login_as('user') | |
| 390 | + | |
| 391 | + get :manage_organizations_status, :filter=>"enabled" | |
| 392 | + assert_match(/Organization profiles - enabled/, @response.body) | |
| 393 | + assert_match(/enabled community/, @response.body) | |
| 394 | + assert_not_match(/disabled community/, @response.body) | |
| 395 | + end | |
| 396 | + | |
| 397 | + should 'show list to activate organizations' do | |
| 398 | + enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community") | |
| 399 | + disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community") | |
| 400 | + user = create_user('user') | |
| 401 | + | |
| 402 | + disabled_community.disable | |
| 403 | + | |
| 404 | + Environment.default.add_admin user.person | |
| 405 | + login_as('user') | |
| 406 | + | |
| 407 | + get :manage_organizations_status, :filter=>"disabled" | |
| 408 | + assert_match(/Organization profiles - disabled/, @response.body) | |
| 409 | + assert_not_match(/enabled community/, @response.body) | |
| 410 | + assert_match(/disabled community/, @response.body) | |
| 411 | + end | |
| 381 | 412 | end | ... | ... |
test/functional/profile_editor_controller_test.rb
| ... | ... | @@ -1095,4 +1095,57 @@ class ProfileEditorControllerTest < ActionController::TestCase |
| 1095 | 1095 | get :index, :profile => user.identifier |
| 1096 | 1096 | assert_tag :tag => 'div', :descendant => { :tag => 'a', :content => 'Edit Header and Footer' } |
| 1097 | 1097 | end |
| 1098 | + | |
| 1099 | + should 'deactivate organization profile' do | |
| 1100 | + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status' | |
| 1101 | + user = create_user('user').person | |
| 1102 | + Environment.default.add_admin user | |
| 1103 | + login_as('user') | |
| 1104 | + | |
| 1105 | + community = fast_create(Community) | |
| 1106 | + assert_equal true, community.enable | |
| 1107 | + | |
| 1108 | + get :index, :profile => community.identifier | |
| 1109 | + get :deactivate_profile, {:profile => community.identifier, :id => community.id} | |
| 1110 | + assert_equal @request.session[:notice], "The profile '#{community.name}' was deactivated." | |
| 1111 | + end | |
| 1112 | + | |
| 1113 | + should 'activate organization profile' do | |
| 1114 | + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status' | |
| 1115 | + user = create_user('user').person | |
| 1116 | + Environment.default.add_admin user | |
| 1117 | + login_as('user') | |
| 1118 | + | |
| 1119 | + community = fast_create(Community) | |
| 1120 | + assert_equal true, community.disable | |
| 1121 | + | |
| 1122 | + get :index, :profile => community.identifier | |
| 1123 | + get :activate_profile, {:profile => community.identifier, :id => community.id} | |
| 1124 | + assert_equal @request.session[:notice], "The profile '#{community.name}' was activated." | |
| 1125 | + end | |
| 1126 | + | |
| 1127 | + should 'not deactivate organization profile if user is not an admin' do | |
| 1128 | + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status' | |
| 1129 | + user = create_user('user').person | |
| 1130 | + login_as('user') | |
| 1131 | + | |
| 1132 | + community = fast_create(Community) | |
| 1133 | + get :index, :profile => community.identifier | |
| 1134 | + get :deactivate_profile, {:profile => community.identifier, :id => community.id} | |
| 1135 | + assert_not_equal @request.session[:notice], "The profile '#{community.name}' was disabled." | |
| 1136 | + end | |
| 1137 | + | |
| 1138 | + should 'destroy organization profile' do | |
| 1139 | + @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status' | |
| 1140 | + user = create_user('user').person | |
| 1141 | + Environment.default.add_admin user | |
| 1142 | + login_as('user') | |
| 1143 | + | |
| 1144 | + community = fast_create(Community) | |
| 1145 | + assert_equal true, community.enable | |
| 1146 | + | |
| 1147 | + get :index, :profile => community.identifier | |
| 1148 | + post :destroy_profile, {:profile => community.identifier, :id => community.id} | |
| 1149 | + assert_equal @request.session[:notice], "The profile was deleted." | |
| 1150 | + end | |
| 1098 | 1151 | end | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -1955,4 +1955,22 @@ class ProfileTest < 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_equal true, profile.disable | |
| 1963 | + | |
| 1964 | + assert_equal true, profile.enable | |
| 1965 | + assert_equal true, profile.visible? | |
| 1966 | + end | |
| 1967 | + | |
| 1968 | + should 'disable profile visibility' do | |
| 1969 | + profile = fast_create(Profile) | |
| 1970 | + | |
| 1971 | + assert_equal true, profile.enable | |
| 1972 | + | |
| 1973 | + assert_equal true, profile.disable | |
| 1974 | + assert_equal false, profile.visible? | |
| 1975 | + end | |
| 1958 | 1976 | end | ... | ... |