Description:
also shows users in all (without pagination)
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r300:5e2d8fe98a1a - - 2 files changed: 16 inserted, 2 deleted

@@ -1,212 +1,218
1 1 class UserAdminController < ApplicationController
2 2
3 3 include MailHelperMethods
4 4
5 5 before_filter :admin_authorization
6 6
7 7 def index
8 8 list
9 9 render :action => 'list'
10 10 end
11 11
12 12 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
13 13 verify :method => :post, :only => [ :destroy,
14 14 :create, :create_from_list,
15 15 :update ],
16 16 :redirect_to => { :action => :list }
17 17
18 18 def list
19 19 @user_count = User.count
20 - @users = User.paginate :page => params[:page]
20 + if params[:page] == 'all'
21 + @users = User.all
22 + @paginated = false
23 + else
24 + @users = User.paginate :page => params[:page]
25 + @paginated = true
26 + end
21 27 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
22 28 @contests = Contest.enabled
23 29 end
24 30
25 31 def active
26 32 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
27 33 @users = []
28 34 sessions.each do |session|
29 35 if session.data[:user_id]
30 36 @users << User.find(session.data[:user_id])
31 37 end
32 38 end
33 39 end
34 40
35 41 def show
36 42 @user = User.find(params[:id])
37 43 end
38 44
39 45 def new
40 46 @user = User.new
41 47 end
42 48
43 49 def create
44 50 @user = User.new(params[:user])
45 51 @user.activated = true
46 52 if @user.save
47 53 flash[:notice] = 'User was successfully created.'
48 54 redirect_to :action => 'list'
49 55 else
50 56 render :action => 'new'
51 57 end
52 58 end
53 59
54 60 def create_from_list
55 61 lines = params[:user_list]
56 62
57 63 note = []
58 64
59 65 lines.split("\n").each do |line|
60 66 items = line.chomp.split(',')
61 67 if items.length>=2
62 68 login = items[0]
63 69 full_name = items[1]
64 70
65 71 added_random_password = false
66 72 if items.length>=3
67 73 password = items[2]
68 74 user_alias = (items.length>=4) ? items[3] : login
69 75 else
70 76 password = random_password
71 77 user_alias = (items.length>=4) ? items[3] : login
72 78 added_random_password = true
73 79 end
74 80
75 81 user = User.new({:login => login,
76 82 :full_name => full_name,
77 83 :password => password,
78 84 :password_confirmation => password,
79 85 :alias => user_alias})
80 86 user.activated = true
81 87 user.save
82 88
83 89 if added_random_password
84 90 note << "'#{login}' (+)"
85 91 else
86 92 note << login
87 93 end
88 94 end
89 95 end
90 96 flash[:notice] = 'User(s) ' + note.join(', ') +
91 97 ' were successfully created. ' +
92 98 '( (+) - created with random passwords.)'
93 99 redirect_to :action => 'list'
94 100 end
95 101
96 102 def edit
97 103 @user = User.find(params[:id])
98 104 end
99 105
100 106 def update
101 107 @user = User.find(params[:id])
102 108 if @user.update_attributes(params[:user])
103 109 flash[:notice] = 'User was successfully updated.'
104 110 redirect_to :action => 'show', :id => @user
105 111 else
106 112 render :action => 'edit'
107 113 end
108 114 end
109 115
110 116 def destroy
111 117 User.find(params[:id]).destroy
112 118 redirect_to :action => 'list'
113 119 end
114 120
115 121 def user_stat
116 122 @problems = Problem.find_available_problems
117 123 @users = User.find(:all)
118 124 @scorearray = Array.new
119 125 @users.each do |u|
120 126 ustat = Array.new
121 127 ustat[0] = u
122 128 @problems.each do |p|
123 129 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
124 130 if (sub!=nil) and (sub.points!=nil)
125 131 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
126 132 else
127 133 ustat << [0,false]
128 134 end
129 135 end
130 136 @scorearray << ustat
131 137 end
132 138 end
133 139
134 140 def import
135 141 if params[:file]==''
136 142 flash[:notice] = 'Error importing no file'
137 143 redirect_to :action => 'list' and return
138 144 end
139 145 import_from_file(params[:file])
140 146 end
141 147
142 148 def random_all_passwords
143 149 users = User.find(:all)
144 150 @prefix = params[:prefix] || ''
145 151 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
146 152 @changed = false
147 153 if request.request_method == :post
148 154 @non_admin_users.each do |user|
149 155 password = random_password
150 156 user.password = password
151 157 user.password_confirmation = password
152 158 user.save
153 159 end
154 160 @changed = true
155 161 end
156 162 end
157 163
158 164 # contest management
159 165
160 166 def contests
161 167 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
162 168 @contests = Contest.enabled
163 169 end
164 170
165 171 def assign_from_list
166 172 contest_id = params[:users_contest_id]
167 173 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
168 174 contest = Contest.find(params[:new_contest][:id])
169 175 if !contest
170 176 flash[:notice] = 'Error: no contest'
171 177 redirect_to :action => 'contests', :id =>contest_id
172 178 end
173 179
174 180 note = []
175 181 users.each do |u|
176 182 u.contests = [contest]
177 183 note << u.login
178 184 end
179 185 flash[:notice] = 'User(s) ' + note.join(', ') +
180 186 " were successfully reassigned to #{contest.title}."
181 187 redirect_to :action => 'contests', :id =>contest.id
182 188 end
183 189
184 190 def add_to_contest
185 191 user = User.find(params[:id])
186 192 contest = Contest.find(params[:contest_id])
187 193 if user and contest
188 194 user.contests << contest
189 195 end
190 196 redirect_to :action => 'list'
191 197 end
192 198
193 199 def remove_from_contest
194 200 user = User.find(params[:id])
195 201 contest = Contest.find(params[:contest_id])
196 202 if user and contest
197 203 user.contests.delete(contest)
198 204 end
199 205 redirect_to :action => 'list'
200 206 end
201 207
202 208 def contest_management
203 209 end
204 210
205 211 def manage_contest
206 212 contest = Contest.find(params[:contest][:id])
207 213 if !contest
208 214 flash[:notice] = 'You did not choose the contest.'
209 215 redirect_to :action => 'contest_management' and return
210 216 end
211 217
212 218 operation = params[:operation]
@@ -1,77 +1,85
1 1 <h1>Listing users</h1>
2 2
3 3 <div class="submitbox">
4 4 <b>Quick add</b>
5 5 <% form_tag :action => 'create' do %>
6 6 <table border="0">
7 7 <tr>
8 8 <td><label for="user_login">Login</label></td>
9 9 <td><label for="user_full_name">Full name</label></td>
10 10 <td><label for="user_password">Password</label></td>
11 11 <td><label for="user_password_confirmation">Confirm</label></td>
12 12 <td><label for="user_email">Email</label></td>
13 13 </tr>
14 14 <tr>
15 15 <td><%= text_field 'user', 'login', :size => 10 %></td>
16 16 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
17 17 <td><%= password_field 'user', 'password', :size => 10 %></td>
18 18 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
19 19 <td><%= text_field 'user', 'email', :size => 15 %></td>
20 20 <td><%= submit_tag "Create" %></td>
21 21 </tr>
22 22 </table>
23 23 <% end %>
24 24 <br/>
25 25 <b>Import from site management</b>
26 26 <% form_tag({:action => 'import'}, :multipart => true) do %>
27 27 File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %>
28 28 <% end %>
29 29 <br/>
30 30 <b>What else: </b>
31 31 <%= link_to '[New user]', :action => 'new' %>
32 32 <%= link_to '[New list of users]', :action => 'new_list' %>
33 33 <%= link_to '[View administrators]', :action => 'admin' %>
34 34 <%= link_to '[Random passwords]', :action => 'random_all_passwords' %>
35 35 <%= link_to '[View active users]', :action => 'active' %>
36 36 <% if Configuration.multicontests? %>
37 37 <br/><b>Multi-contest:</b>
38 38 <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %>
39 39 View users in:
40 40 <% @contests.each do |contest| %>
41 41 <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %>
42 42 <% end %>
43 43 <%= link_to "[no contest]", :action => 'contests', :id => 'none' %>
44 44 <% end %>
45 45 </div>
46 46
47 - Total <%= @user_count %> users | <%= will_paginate @users, :container => false %>
47 + Total <%= @user_count %> users |
48 + <% if !@paginated %>
49 + Display all users.
50 + <%= link_to '[show in pages]', :action => 'list', :page => '1' %>
51 + <% else %>
52 + Display in pages.
53 + <%= link_to '[display all]', :action => 'list', :page => 'all' %> |
54 + <%= will_paginate @users, :container => false %>
55 + <% end %>
48 56 <table class="info">
49 57 <tr class="info-head">
50 58 <% for column in User.content_columns %>
51 59 <% if !@hidden_columns.index(column.name) %>
52 60 <th><%= column.human_name %></th>
53 61 <% end %>
54 62 <% end %>
55 63 <th></th>
56 64 <th></th>
57 65 <th></th>
58 66 </tr>
59 67
60 68 <% for user in @users %>
61 69 <tr class="info-<%= cycle("odd","even") %>">
62 70 <% for column in User.content_columns %>
63 71 <% if !@hidden_columns.index(column.name) %>
64 72 <td><%=h user.send(column.name) %></td>
65 73 <% end %>
66 74 <% end %>
67 75 <td><%= link_to 'Show', :action => 'show', :id => user %></td>
68 76 <td><%= link_to 'Edit', :action => 'edit', :id => user %></td>
69 77 <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td>
70 78 </tr>
71 79 <% end %>
72 80 </table>
73 81
74 82 <br />
75 83
76 84 <%= link_to '[New user]', :action => 'new' %>
77 85 <%= link_to '[New list of users]', :action => 'new_list' %>
You need to be logged in to leave comments. Login now