Commit 3e453e4429a04ecf271b1895478054ec118ce228
1 parent
d09c5df5
Exists in
master
and in
29 other branches
Allow admins to activate and deactivate environment users.
Showing
18 changed files
with
320 additions
and
220 deletions
Show diff stats
app/controllers/admin/environment_users_controller.rb
... | ... | @@ -1,44 +0,0 @@ |
1 | -class EnvironmentUsersController < AdminController | |
2 | - | |
3 | - protect 'manage_environment_users', :environment | |
4 | - | |
5 | - def per_page | |
6 | - 10 | |
7 | - end | |
8 | - | |
9 | - def index | |
10 | - @q = params[:q] | |
11 | - if @q.blank? | |
12 | - @collection = environment.people.no_templates(environment).paginate( | |
13 | - :per_page => per_page, | |
14 | - :page => params[:npage] | |
15 | - ) | |
16 | - else | |
17 | - @collection = find_by_contents(:people, environment.people.no_templates(environment), @q, {:per_page => per_page, :page => params[:npage]})[:results] | |
18 | - end | |
19 | - end | |
20 | - | |
21 | - def set_admin_role | |
22 | - @person = environment.people.find(params[:id]) | |
23 | - environment.add_admin(@person) | |
24 | - redirect_to :action => :index, :q => params[:q] | |
25 | - end | |
26 | - | |
27 | - def reset_admin_role | |
28 | - @person = environment.people.find(params[:id]) | |
29 | - environment.remove_admin(@person) | |
30 | - redirect_to :action => :index, :q => params[:q] | |
31 | - end | |
32 | - | |
33 | - def activate | |
34 | - @person = environment.people.find(params[:id]) | |
35 | - @person.user.activate | |
36 | - redirect_to :action => :index, :q => params[:q] | |
37 | - end | |
38 | - | |
39 | - def deactivate | |
40 | - @person = environment.people.find(params[:id]) | |
41 | - @person.user.deactivate | |
42 | - redirect_to :action => :index, :q => params[:q] | |
43 | - end | |
44 | -end |
app/controllers/admin/users_controller.rb
... | ... | @@ -4,7 +4,57 @@ class UsersController < AdminController |
4 | 4 | |
5 | 5 | protect 'manage_environment_users', :environment |
6 | 6 | |
7 | + include UsersHelper | |
8 | + | |
9 | + def per_page | |
10 | + 10 | |
11 | + end | |
12 | + | |
7 | 13 | def index |
14 | + @filter = params[:filter] | |
15 | + if @filter.blank? || @filter == 'all_users' | |
16 | + @filter = 'all_users' | |
17 | + scope = environment.people.no_templates(environment) | |
18 | + elsif @filter == 'admin_users' | |
19 | + scope = environment.people.no_templates(environment).admins | |
20 | + elsif @filter == 'activated_users' | |
21 | + scope = environment.people.no_templates(environment).activated | |
22 | + elsif @filter == 'deactivated_users' | |
23 | + scope = environment.people.no_templates(environment).deactivated | |
24 | + end | |
25 | + @q = params[:q] | |
26 | + if @q.blank? | |
27 | + @collection = scope.paginate(:per_page => per_page, :page => params[:npage]) | |
28 | + else | |
29 | + @collection = find_by_contents(:people, scope, @q, {:per_page => per_page, :page => params[:npage]})[:results] | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + def set_admin_role | |
34 | + @person = environment.people.find(params[:id]) | |
35 | + environment.add_admin(@person) | |
36 | + redirect_to :action => :index, :q => params[:q], :filter => params[:filter] | |
37 | + end | |
38 | + | |
39 | + def reset_admin_role | |
40 | + @person = environment.people.find(params[:id]) | |
41 | + environment.remove_admin(@person) | |
42 | + redirect_to :action => :index, :q => params[:q], :filter => params[:filter] | |
43 | + end | |
44 | + | |
45 | + def activate | |
46 | + @person = environment.people.find(params[:id]) | |
47 | + @person.user.activate | |
48 | + redirect_to :action => :index, :q => params[:q], :filter => params[:filter] | |
49 | + end | |
50 | + | |
51 | + def deactivate | |
52 | + @person = environment.people.find(params[:id]) | |
53 | + @person.user.deactivate | |
54 | + redirect_to :action => :index, :q => params[:q], :filter => params[:filter] | |
55 | + end | |
56 | + | |
57 | + def download | |
8 | 58 | respond_to do |format| |
9 | 59 | format.html |
10 | 60 | format.xml do | ... | ... |
app/controllers/admin/xxx-environment_users_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,44 @@ |
1 | +class EnvironmentUsersController < AdminController | |
2 | + | |
3 | + protect 'manage_environment_users', :environment | |
4 | + | |
5 | + def per_page | |
6 | + 10 | |
7 | + end | |
8 | + | |
9 | + def index | |
10 | + @q = params[:q] | |
11 | + if @q.blank? | |
12 | + @collection = environment.people.no_templates(environment).paginate( | |
13 | + :per_page => per_page, | |
14 | + :page => params[:npage] | |
15 | + ) | |
16 | + else | |
17 | + @collection = find_by_contents(:people, environment.people.no_templates(environment), @q, {:per_page => per_page, :page => params[:npage]})[:results] | |
18 | + end | |
19 | + end | |
20 | + | |
21 | + def set_admin_role | |
22 | + @person = environment.people.find(params[:id]) | |
23 | + environment.add_admin(@person) | |
24 | + redirect_to :action => :index, :q => params[:q] | |
25 | + end | |
26 | + | |
27 | + def reset_admin_role | |
28 | + @person = environment.people.find(params[:id]) | |
29 | + environment.remove_admin(@person) | |
30 | + redirect_to :action => :index, :q => params[:q] | |
31 | + end | |
32 | + | |
33 | + def activate | |
34 | + @person = environment.people.find(params[:id]) | |
35 | + @person.user.activate | |
36 | + redirect_to :action => :index, :q => params[:q] | |
37 | + end | |
38 | + | |
39 | + def deactivate | |
40 | + @person = environment.people.find(params[:id]) | |
41 | + @person.user.deactivate | |
42 | + redirect_to :action => :index, :q => params[:q] | |
43 | + end | |
44 | +end | ... | ... |
app/controllers/application_controller.rb
... | ... | @@ -0,0 +1,25 @@ |
1 | +module UsersHelper | |
2 | + | |
3 | + FILTER_TRANSLATION = { | |
4 | + 'all_users' => _('All users'), | |
5 | + 'admin_users' => _('Admin users'), | |
6 | + 'activated_users' => _('Activated users'), | |
7 | + 'deactivated_users' => _('Deativated users'), | |
8 | + } | |
9 | + | |
10 | + def filter_selector(filter, float = 'right') | |
11 | + options = options_for_select(FILTER_TRANSLATION.map {|key, name| [name, key]}, :selected => filter) | |
12 | + url_params = url_for(params.merge(:filter => 'FILTER')) | |
13 | + onchange = "document.location.href = '#{url_params}'.replace('FILTER', this.value)" | |
14 | + select_field = select_tag(:filter, options, :onchange => onchange) | |
15 | + content_tag('div', | |
16 | + content_tag('strong', _('Filter')) + ': ' + select_field, | |
17 | + :class => "environment-users-customize-search" | |
18 | + ) | |
19 | + end | |
20 | + | |
21 | + def filter_title(filter) | |
22 | + FILTER_TRANSLATION[filter] | |
23 | + end | |
24 | + | |
25 | +end | ... | ... |
app/models/person.rb
... | ... | @@ -75,6 +75,10 @@ class Person < Profile |
75 | 75 | named_scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*' |
76 | 76 | named_scope :non_abusers, :joins => "LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'", :conditions => ["tasks.status != 3 OR tasks.id is NULL"], :select => "DISTINCT profiles.*" |
77 | 77 | |
78 | + named_scope :admins, :joins => [:role_assignments => :role], :conditions => ['roles.key = ?', 'environment_administrator' ] | |
79 | + named_scope :activated, :joins => :user, :conditions => ['users.activation_code IS NULL AND users.activated_at IS NOT NULL'] | |
80 | + named_scope :deactivated, :joins => :user, :conditions => ['NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)'] | |
81 | + | |
78 | 82 | after_destroy do |person| |
79 | 83 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } |
80 | 84 | end | ... | ... |
app/views/environment_users/_environment_users_search_form.rhtml
... | ... | @@ -1,8 +0,0 @@ |
1 | -<% form_tag( { :controller => 'environment_users', :action => 'index' }, :method => 'get', :class => 'environment-users-search' ) do %> | |
2 | - <div class="search-field"> | |
3 | - <span class="formfield"> | |
4 | - <%= text_field_tag 'q', @q, :title => _("Find users") %> | |
5 | - </span> | |
6 | - <%= submit_button(:search, _('Search')) %> | |
7 | - </div> | |
8 | -<% end %> |
app/views/environment_users/_index_buttons.rhtml
app/views/environment_users/_users_list.rhtml
... | ... | @@ -1,30 +0,0 @@ |
1 | -<% title = _('All Users') %> | |
2 | - | |
3 | -<h3><%= title %></h3> | |
4 | -<table> | |
5 | - <tr> | |
6 | - <th><%= _('Member') %></th> | |
7 | - <th><%= _('Actions') %></th> | |
8 | - </tr> | |
9 | - <% @collection.each do |p| %> | |
10 | - <tr title="<%= p.name %>"> | |
11 | - <td><%= link_to_profile p.short_name, p.identifier, :title => p.name %> </td> | |
12 | - <td> | |
13 | - <div class="members-buttons-cell"> | |
14 | - <% if p.is_admin? %> | |
15 | - <%= button_without_text :'reset-admin-role', _('Reset admin role'), :action => 'reset_admin_role', :id => p, :q => @q %> | |
16 | - <% else %> | |
17 | - <%= button_without_text :'set-admin-role', _('Set admin role'), :action => 'set_admin_role', :id => p, :q => @q %> | |
18 | - <% end %> | |
19 | - <% if !p.user.activated? %> | |
20 | - <%= button_without_text :'activate-user', _('Activate user'), :action => 'activate', :id => p, :q => @q %> | |
21 | - <% else %> | |
22 | - <%= button_without_text :'deactivate-user', _('Deactivate user'), :action => 'deactivate', :id => p, :q => @q %> | |
23 | - <% end %> | |
24 | - </div> | |
25 | - </td> | |
26 | - </tr> | |
27 | - <% end %> | |
28 | -</table> | |
29 | - | |
30 | -<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %> | |
31 | 0 | \ No newline at end of file |
app/views/environment_users/index.rhtml
... | ... | @@ -1,12 +0,0 @@ |
1 | -<h1><%= _('Edit Users')%></h1> | |
2 | - | |
3 | -<%= render :partial => 'index_buttons' %> | |
4 | - | |
5 | -<div id="search-users"> | |
6 | - <%= render :partial => 'environment_users_search_form' %> | |
7 | -</div> | |
8 | -<div id="users-list"> | |
9 | - <%= render :partial => 'users_list' %> | |
10 | -</div> | |
11 | - | |
12 | -<%= render :partial => 'index_buttons' %> |
... | ... | @@ -0,0 +1,6 @@ |
1 | +<% button_bar do %> | |
2 | + <%= button :'text-plain', _('User list as [CSV]'), :action => :download, :format => 'csv' %> | |
3 | + <%= button :'text-html', _('User list as [XML]'), :action => :download, :format => 'xml' %> | |
4 | + <%= button :send, _('Send e-mail to all users'), :action => 'send_mail' %> | |
5 | + <%= button :back, _('Back'), :controller => 'admin_panel' %> | |
6 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +<div class="environment-users-results-header"> | |
2 | + <div id='environment-users-filter-title'><%= filter_title(@filter) %></div> | |
3 | + <%= filter_selector(@filter) %> | |
4 | + <div style="clear: both"></div> | |
5 | +</div> | |
6 | + | |
7 | +<table> | |
8 | + <tr> | |
9 | + <th><%= _('Member') %></th> | |
10 | + <th><%= _('Actions') %></th> | |
11 | + </tr> | |
12 | + <% @collection.each do |p| %> | |
13 | + <tr title="<%= p.name %>"> | |
14 | + <td><%= link_to_profile p.short_name, p.identifier, :title => p.name %> </td> | |
15 | + <td> | |
16 | + <div class="members-buttons-cell"> | |
17 | + <% if p.is_admin? %> | |
18 | + <%= button_without_text :'reset-admin-role', _('Reset admin role'), :action => 'reset_admin_role', :id => p, :q => @q, :filter => @filter %> | |
19 | + <% else %> | |
20 | + <%= button_without_text :'set-admin-role', _('Set admin role'), :action => 'set_admin_role', :id => p, :q => @q, :filter => @filter %> | |
21 | + <% end %> | |
22 | + <% if !p.user.activated? %> | |
23 | + <%= button_without_text :'activate-user', _('Activate user'), :action => 'activate', :id => p, :q => @q, :filter => @filter %> | |
24 | + <% else %> | |
25 | + <%= button_without_text :'deactivate-user', _('Deactivate user'), :action => 'deactivate', :id => p, :q => @q, :filter => @filter %> | |
26 | + <% end %> | |
27 | + </div> | |
28 | + </td> | |
29 | + </tr> | |
30 | + <% end %> | |
31 | +</table> | |
32 | + | |
33 | +<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %> | |
0 | 34 | \ No newline at end of file | ... | ... |
app/views/users/index.rhtml
1 | 1 | <h1><%= _('Manage users') %></h1> |
2 | 2 | |
3 | -<ul> | |
4 | - <li> | |
5 | - <%= _('Download users list') %>: | |
6 | - <%= link_to '[CSV]', :format => 'csv' %> | |
7 | - <%= link_to '[XML]', :format => 'xml' %> | |
8 | - </li> | |
9 | - <li> | |
10 | - <%= link_to _('Send e-mail to users'), :action => 'send_mail' %> | |
11 | - </li> | |
12 | - <li> | |
13 | - <%= link_to _('Edit users'), :controller => 'environment_users' %> | |
14 | - </li> | |
15 | -</ul> | |
16 | - | |
17 | -<% button_bar do %> | |
18 | - <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %> | |
3 | +<% form_tag( { :action => 'index' }, :method => 'get', :class => 'users-search' ) do %> | |
4 | +<div id="search-users"> | |
5 | + <%= render :partial => 'users_search_form' %> | |
6 | +</div> | |
7 | +<div id="users-list"> | |
8 | + <%= render :partial => 'users_list' %> | |
9 | +</div> | |
19 | 10 | <% end %> |
11 | + | |
12 | +<%= render :partial => 'index_buttons' %> | |
20 | 13 | \ No newline at end of file | ... | ... |
public/stylesheets/application.css
... | ... | @@ -4150,6 +4150,19 @@ h1#agenda-title { |
4150 | 4150 | -webkit-border-radius: 5px; |
4151 | 4151 | } |
4152 | 4152 | |
4153 | +.environment-users-results-header { | |
4154 | + font-size: 0.9em; | |
4155 | + padding: 6px 0px 0px 0px; | |
4156 | + margin:0 0 5px 0; | |
4157 | + border-bottom: 2px dotted #999; | |
4158 | + text-align: right; | |
4159 | +} | |
4160 | +#environment-users-filter-title { | |
4161 | + font-weight: bold; | |
4162 | + font-size: 130%; | |
4163 | + line-height: 35px; | |
4164 | + float: left; | |
4165 | +} | |
4153 | 4166 | |
4154 | 4167 | /* * * Profile search * * * * * * * */ |
4155 | 4168 | ... | ... |
test/functional/environment_users_controller_test.rb
... | ... | @@ -1,103 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../test_helper' | |
2 | -require 'environment_users_controller' | |
3 | - | |
4 | -# Re-raise errors caught by the controller. | |
5 | -class EnvironmentUsersController; def rescue_action(e) raise e end; end | |
6 | - | |
7 | -class EnvironmentUsersControllerTest < ActionController::TestCase | |
8 | - | |
9 | - # all_fixtures | |
10 | - def setup | |
11 | - @controller = EnvironmentUsersController.new | |
12 | - @request = ActionController::TestRequest.new | |
13 | - @response = ActionController::TestResponse.new | |
14 | - | |
15 | - admin_user = create_user_with_permission('adminuser', 'manage_environment_users', Environment.default) | |
16 | - login_as('adminuser') | |
17 | - end | |
18 | - | |
19 | - should 'not access without right permission' do | |
20 | - guest = create_user('guest') | |
21 | - login_as 'guest' | |
22 | - | |
23 | - get :index | |
24 | - assert_response 403 # forbidden | |
25 | - end | |
26 | - | |
27 | - should 'grant access with right permission' do | |
28 | - get :index | |
29 | - assert_response :success | |
30 | - end | |
31 | - | |
32 | - should 'blank search results include activated and deactivated users' do | |
33 | - deactivated = create_user('deactivated') | |
34 | - deactivated.activated_at = nil | |
35 | - deactivated.person.visible = false | |
36 | - deactivated.save! | |
37 | - get :index, :q => '' | |
38 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /adminuser/}} | |
39 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /deactivated/}} | |
40 | - end | |
41 | - | |
42 | - should 'blank search include all users' do | |
43 | - (1..5).each {|i| | |
44 | - u = create_user('user'+i.to_s) | |
45 | - } | |
46 | - get :index, :q => '' # blank search | |
47 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /adminuser/}} | |
48 | - (1..5).each {|i| | |
49 | - u = 'user'+i.to_s | |
50 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
51 | - } | |
52 | - end | |
53 | - | |
54 | - should 'search not include all users' do | |
55 | - (1..5).each {|i| | |
56 | - u = create_user('user'+i.to_s) | |
57 | - } | |
58 | - get :index, :q => 'er5' # search | |
59 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /user5/}} | |
60 | - (1..4).each {|i| | |
61 | - u = 'user'+i.to_s | |
62 | - assert_no_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
63 | - } | |
64 | - end | |
65 | - | |
66 | - should 'set admin role' do | |
67 | - u = create_user() | |
68 | - assert_equal false, u.person.is_admin? | |
69 | - post :set_admin_role, :id => u.person.id, :q => '' | |
70 | - u.reload | |
71 | - assert u.person.is_admin? | |
72 | - end | |
73 | - | |
74 | - should 'reset admin role' do | |
75 | - u = create_user() | |
76 | - e = Environment.default | |
77 | - e.add_admin(u.person) | |
78 | - u.reload | |
79 | - assert u.person.is_admin? | |
80 | - post :reset_admin_role, :id => u.person.id, :q => '' | |
81 | - u.reload | |
82 | - assert_equal false, u.person.is_admin? | |
83 | - end | |
84 | - | |
85 | - should 'activate user' do | |
86 | - u = create_user() | |
87 | - assert_equal false, u.activated? | |
88 | - post :activate, :id => u.person.id, :q => '' | |
89 | - u.reload | |
90 | - assert u.activated? | |
91 | - end | |
92 | - | |
93 | - should 'deactivate user' do | |
94 | - u = create_user() | |
95 | - u.activated_at = Time.now.utc | |
96 | - u.activation_code = nil | |
97 | - u.person.visible = true | |
98 | - assert u.activated? | |
99 | - post :deactivate, :id => u.person.id, :q => '' | |
100 | - u.reload | |
101 | - assert_equal false, u.activated? | |
102 | - end | |
103 | -end |
test/functional/users_controller_test.rb
... | ... | @@ -6,11 +6,13 @@ class UsersController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class UsersControllerTest < ActionController::TestCase |
8 | 8 | |
9 | - all_fixtures | |
10 | 9 | def setup |
11 | 10 | @controller = UsersController.new |
12 | 11 | @request = ActionController::TestRequest.new |
13 | 12 | @response = ActionController::TestResponse.new |
13 | + | |
14 | + admin_user = create_user_with_permission('adminuser', 'manage_environment_users', Environment.default) | |
15 | + login_as('adminuser') | |
14 | 16 | end |
15 | 17 | |
16 | 18 | should 'not access without right permission' do |
... | ... | @@ -28,11 +30,83 @@ class UsersControllerTest < ActionController::TestCase |
28 | 30 | assert_response :success |
29 | 31 | end |
30 | 32 | |
33 | + should 'blank search results include activated and deactivated users' do | |
34 | + deactivated = create_user('deactivated') | |
35 | + deactivated.activated_at = nil | |
36 | + deactivated.person.visible = false | |
37 | + deactivated.save! | |
38 | + get :index, :q => '' | |
39 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /adminuser/}} | |
40 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /deactivated/}} | |
41 | + end | |
42 | + | |
43 | + should 'blank search include all users' do | |
44 | + (1..5).each {|i| | |
45 | + u = create_user('user'+i.to_s) | |
46 | + } | |
47 | + get :index, :q => '' # blank search | |
48 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /adminuser/}} | |
49 | + (1..5).each {|i| | |
50 | + u = 'user'+i.to_s | |
51 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
52 | + } | |
53 | + end | |
54 | + | |
55 | + should 'search not include all users' do | |
56 | + (1..5).each {|i| | |
57 | + u = create_user('user'+i.to_s) | |
58 | + } | |
59 | + get :index, :q => 'er5' # search | |
60 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /user5/}} | |
61 | + (1..4).each {|i| | |
62 | + u = 'user'+i.to_s | |
63 | + assert_no_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
64 | + } | |
65 | + end | |
66 | + | |
67 | + should 'set admin role' do | |
68 | + u = create_user() | |
69 | + assert_equal false, u.person.is_admin? | |
70 | + post :set_admin_role, :id => u.person.id, :q => '' | |
71 | + u.reload | |
72 | + assert u.person.is_admin? | |
73 | + end | |
74 | + | |
75 | + should 'reset admin role' do | |
76 | + u = create_user() | |
77 | + e = Environment.default | |
78 | + e.add_admin(u.person) | |
79 | + u.reload | |
80 | + assert u.person.is_admin? | |
81 | + post :reset_admin_role, :id => u.person.id, :q => '' | |
82 | + u.reload | |
83 | + assert_equal false, u.person.is_admin? | |
84 | + end | |
85 | + | |
86 | + should 'activate user' do | |
87 | + u = create_user() | |
88 | + assert_equal false, u.activated? | |
89 | + post :activate, :id => u.person.id, :q => '' | |
90 | + u.reload | |
91 | + assert u.activated? | |
92 | + end | |
93 | + | |
94 | + should 'deactivate user' do | |
95 | + u = create_user() | |
96 | + u.activated_at = Time.now.utc | |
97 | + u.activation_code = nil | |
98 | + u.person.visible = true | |
99 | + assert u.activated? | |
100 | + post :deactivate, :id => u.person.id, :q => '' | |
101 | + u.reload | |
102 | + assert_equal false, u.activated? | |
103 | + end | |
104 | + | |
31 | 105 | should 'response as XML to export users' do |
32 | 106 | admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default) |
33 | 107 | login_as('admin_user') |
34 | 108 | |
35 | - get :index, :format => 'xml' | |
109 | + get :download, :format => 'xml' | |
36 | 110 | assert_equal 'text/xml', @response.content_type |
37 | 111 | end |
38 | 112 | |
... | ... | @@ -40,7 +114,7 @@ class UsersControllerTest < ActionController::TestCase |
40 | 114 | admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default) |
41 | 115 | login_as('admin_user') |
42 | 116 | |
43 | - get :index, :format => 'csv' | |
117 | + get :download, :format => 'csv' | |
44 | 118 | assert_equal 'text/csv', @response.content_type |
45 | 119 | assert_equal 'name;email', @response.body.split("\n")[0] |
46 | 120 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -1335,4 +1335,56 @@ class PersonTest < ActiveSupport::TestCase |
1335 | 1335 | assert_includes non_abusers, not_abuser |
1336 | 1336 | end |
1337 | 1337 | |
1338 | + should 'admins named_scope return persons who are admin users' do | |
1339 | + Person.delete_all | |
1340 | + e = Environment.default | |
1341 | + admins = [] | |
1342 | + (1..5).each {|i| | |
1343 | + u = create_user('user'+i.to_s) | |
1344 | + e.add_admin(u.person) | |
1345 | + admins << u.person | |
1346 | + } | |
1347 | + (6..10).each {|i| | |
1348 | + u = create_user('user'+i.to_s) | |
1349 | + } | |
1350 | + assert_equal admins, Person.admins | |
1351 | + end | |
1352 | + | |
1353 | + should 'activated named_scope return persons who are activated users' do | |
1354 | + Person.delete_all | |
1355 | + e = Environment.default | |
1356 | + activated = [] | |
1357 | + (1..5).each {|i| | |
1358 | + u = create_user('user'+i.to_s) | |
1359 | + u.activated_at = Time.now.utc | |
1360 | + u.activation_code = nil | |
1361 | + u.save! | |
1362 | + activated << u.person | |
1363 | + } | |
1364 | + (6..10).each {|i| | |
1365 | + u = create_user('user'+i.to_s) | |
1366 | + u.activated_at = nil | |
1367 | + u.save! | |
1368 | + } | |
1369 | + assert_equal activated, Person.activated | |
1370 | + end | |
1371 | + | |
1372 | + should 'deactivated named_scope return persons who are deactivated users' do | |
1373 | + Person.delete_all | |
1374 | + e = Environment.default | |
1375 | + deactivated = [] | |
1376 | + (1..5).each {|i| | |
1377 | + u = create_user('user'+i.to_s) | |
1378 | + u.activated_at = nil | |
1379 | + u.save! | |
1380 | + deactivated << u.person | |
1381 | + } | |
1382 | + (6..10).each {|i| | |
1383 | + u = create_user('user'+i.to_s) | |
1384 | + u.activated_at = Time.now.utc | |
1385 | + u.activation_code = nil | |
1386 | + u.save! | |
1387 | + } | |
1388 | + assert_equal deactivated, Person.deactivated | |
1389 | + end | |
1338 | 1390 | end | ... | ... |