Description:
shows more login/contest info on result page
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r304:a6eab16005af - - 2 files changed: 9 inserted, 1 deleted
@@ -1,315 +1,315 | |||
|
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 | 20 | if params[:page] == 'all' |
|
21 | 21 | @users = User.all |
|
22 | 22 | @paginated = false |
|
23 | 23 | else |
|
24 | 24 | @users = User.paginate :page => params[:page] |
|
25 | 25 | @paginated = true |
|
26 | 26 | end |
|
27 | 27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
28 | 28 | @contests = Contest.enabled |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def active |
|
32 | 32 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
33 | 33 | @users = [] |
|
34 | 34 | sessions.each do |session| |
|
35 | 35 | if session.data[:user_id] |
|
36 | 36 | @users << User.find(session.data[:user_id]) |
|
37 | 37 | end |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def show |
|
42 | 42 | @user = User.find(params[:id]) |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def new |
|
46 | 46 | @user = User.new |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def create |
|
50 | 50 | @user = User.new(params[:user]) |
|
51 | 51 | @user.activated = true |
|
52 | 52 | if @user.save |
|
53 | 53 | flash[:notice] = 'User was successfully created.' |
|
54 | 54 | redirect_to :action => 'list' |
|
55 | 55 | else |
|
56 | 56 | render :action => 'new' |
|
57 | 57 | end |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def create_from_list |
|
61 | 61 | lines = params[:user_list] |
|
62 | 62 | |
|
63 | 63 | note = [] |
|
64 | 64 | |
|
65 | 65 | lines.split("\n").each do |line| |
|
66 | 66 | items = line.chomp.split(',') |
|
67 | 67 | if items.length>=2 |
|
68 | 68 | login = items[0] |
|
69 | 69 | full_name = items[1] |
|
70 | 70 | |
|
71 | 71 | added_random_password = false |
|
72 | 72 | if items.length>=3 |
|
73 | 73 | password = items[2] |
|
74 | 74 | user_alias = (items.length>=4) ? items[3] : login |
|
75 | 75 | else |
|
76 | 76 | password = random_password |
|
77 | 77 | user_alias = (items.length>=4) ? items[3] : login |
|
78 | 78 | added_random_password = true |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | user = User.new({:login => login, |
|
82 | 82 | :full_name => full_name, |
|
83 | 83 | :password => password, |
|
84 | 84 | :password_confirmation => password, |
|
85 | 85 | :alias => user_alias}) |
|
86 | 86 | user.activated = true |
|
87 | 87 | user.save |
|
88 | 88 | |
|
89 | 89 | if added_random_password |
|
90 | 90 | note << "'#{login}' (+)" |
|
91 | 91 | else |
|
92 | 92 | note << login |
|
93 | 93 | end |
|
94 | 94 | end |
|
95 | 95 | end |
|
96 | 96 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
97 | 97 | ' were successfully created. ' + |
|
98 | 98 | '( (+) - created with random passwords.)' |
|
99 | 99 | redirect_to :action => 'list' |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def edit |
|
103 | 103 | @user = User.find(params[:id]) |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def update |
|
107 | 107 | @user = User.find(params[:id]) |
|
108 | 108 | if @user.update_attributes(params[:user]) |
|
109 | 109 | flash[:notice] = 'User was successfully updated.' |
|
110 | 110 | redirect_to :action => 'show', :id => @user |
|
111 | 111 | else |
|
112 | 112 | render :action => 'edit' |
|
113 | 113 | end |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | def destroy |
|
117 | 117 | User.find(params[:id]).destroy |
|
118 | 118 | redirect_to :action => 'list' |
|
119 | 119 | end |
|
120 | 120 | |
|
121 | 121 | def user_stat |
|
122 | 122 | @problems = Problem.find_available_problems |
|
123 | - @users = User.find(:all) | |
|
123 | + @users = User.find(:all, :include => [:contests, :contest_stat]) | |
|
124 | 124 | @scorearray = Array.new |
|
125 | 125 | @users.each do |u| |
|
126 | 126 | ustat = Array.new |
|
127 | 127 | ustat[0] = u |
|
128 | 128 | @problems.each do |p| |
|
129 | 129 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
130 | 130 | if (sub!=nil) and (sub.points!=nil) |
|
131 | 131 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
132 | 132 | else |
|
133 | 133 | ustat << [0,false] |
|
134 | 134 | end |
|
135 | 135 | end |
|
136 | 136 | @scorearray << ustat |
|
137 | 137 | end |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def import |
|
141 | 141 | if params[:file]=='' |
|
142 | 142 | flash[:notice] = 'Error importing no file' |
|
143 | 143 | redirect_to :action => 'list' and return |
|
144 | 144 | end |
|
145 | 145 | import_from_file(params[:file]) |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | def random_all_passwords |
|
149 | 149 | users = User.find(:all) |
|
150 | 150 | @prefix = params[:prefix] || '' |
|
151 | 151 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
152 | 152 | @changed = false |
|
153 | 153 | if request.request_method == :post |
|
154 | 154 | @non_admin_users.each do |user| |
|
155 | 155 | password = random_password |
|
156 | 156 | user.password = password |
|
157 | 157 | user.password_confirmation = password |
|
158 | 158 | user.save |
|
159 | 159 | end |
|
160 | 160 | @changed = true |
|
161 | 161 | end |
|
162 | 162 | end |
|
163 | 163 | |
|
164 | 164 | # contest management |
|
165 | 165 | |
|
166 | 166 | def contests |
|
167 | 167 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
168 | 168 | @contests = Contest.enabled |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | def assign_from_list |
|
172 | 172 | contest_id = params[:users_contest_id] |
|
173 | 173 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
174 | 174 | contest = Contest.find(params[:new_contest][:id]) |
|
175 | 175 | if !contest |
|
176 | 176 | flash[:notice] = 'Error: no contest' |
|
177 | 177 | redirect_to :action => 'contests', :id =>contest_id |
|
178 | 178 | end |
|
179 | 179 | |
|
180 | 180 | note = [] |
|
181 | 181 | users.each do |u| |
|
182 | 182 | u.contests = [contest] |
|
183 | 183 | note << u.login |
|
184 | 184 | end |
|
185 | 185 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
186 | 186 | " were successfully reassigned to #{contest.title}." |
|
187 | 187 | redirect_to :action => 'contests', :id =>contest.id |
|
188 | 188 | end |
|
189 | 189 | |
|
190 | 190 | def add_to_contest |
|
191 | 191 | user = User.find(params[:id]) |
|
192 | 192 | contest = Contest.find(params[:contest_id]) |
|
193 | 193 | if user and contest |
|
194 | 194 | user.contests << contest |
|
195 | 195 | end |
|
196 | 196 | redirect_to :action => 'list' |
|
197 | 197 | end |
|
198 | 198 | |
|
199 | 199 | def remove_from_contest |
|
200 | 200 | user = User.find(params[:id]) |
|
201 | 201 | contest = Contest.find(params[:contest_id]) |
|
202 | 202 | if user and contest |
|
203 | 203 | user.contests.delete(contest) |
|
204 | 204 | end |
|
205 | 205 | redirect_to :action => 'list' |
|
206 | 206 | end |
|
207 | 207 | |
|
208 | 208 | def contest_management |
|
209 | 209 | end |
|
210 | 210 | |
|
211 | 211 | def manage_contest |
|
212 | 212 | contest = Contest.find(params[:contest][:id]) |
|
213 | 213 | if !contest |
|
214 | 214 | flash[:notice] = 'You did not choose the contest.' |
|
215 | 215 | redirect_to :action => 'contest_management' and return |
|
216 | 216 | end |
|
217 | 217 | |
|
218 | 218 | operation = params[:operation] |
|
219 | 219 | |
|
220 | 220 | if not ['add','remove','assign'].include? operation |
|
221 | 221 | flash[:notice] = 'You did not choose the operation to perform.' |
|
222 | 222 | redirect_to :action => 'contest_management' and return |
|
223 | 223 | end |
|
224 | 224 | |
|
225 | 225 | lines = params[:login_list] |
|
226 | 226 | if !lines or lines.blank? |
|
227 | 227 | flash[:notice] = 'You entered an empty list.' |
|
228 | 228 | redirect_to :action => 'contest_management' and return |
|
229 | 229 | end |
|
230 | 230 | |
|
231 | 231 | note = [] |
|
232 | 232 | users = [] |
|
233 | 233 | lines.split("\n").each do |line| |
|
234 | 234 | user = User.find_by_login(line.chomp) |
|
235 | 235 | if user |
|
236 | 236 | if operation=='add' |
|
237 | 237 | if ! user.contests.include? contest |
|
238 | 238 | user.contests << contest |
|
239 | 239 | end |
|
240 | 240 | elsif operation=='remove' |
|
241 | 241 | user.contests.delete(contest) |
|
242 | 242 | else |
|
243 | 243 | user.contests = [contest] |
|
244 | 244 | end |
|
245 | 245 | |
|
246 | 246 | if params[:reset_timer] |
|
247 | 247 | user.contest_stat.forced_logout = true |
|
248 | 248 | user.contest_stat.reset_timer_and_save |
|
249 | 249 | end |
|
250 | 250 | |
|
251 | 251 | if params[:notification_emails] |
|
252 | 252 | send_contest_update_notification_email(user, contest) |
|
253 | 253 | end |
|
254 | 254 | |
|
255 | 255 | note << user.login |
|
256 | 256 | users << user |
|
257 | 257 | end |
|
258 | 258 | end |
|
259 | 259 | |
|
260 | 260 | if params[:reset_timer] |
|
261 | 261 | logout_users(users) |
|
262 | 262 | end |
|
263 | 263 | |
|
264 | 264 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
265 | 265 | ' were successfully modified. ' |
|
266 | 266 | redirect_to :action => 'contest_management' |
|
267 | 267 | end |
|
268 | 268 | |
|
269 | 269 | # admin management |
|
270 | 270 | |
|
271 | 271 | def admin |
|
272 | 272 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
273 | 273 | end |
|
274 | 274 | |
|
275 | 275 | def grant_admin |
|
276 | 276 | login = params[:login] |
|
277 | 277 | user = User.find_by_login(login) |
|
278 | 278 | if user!=nil |
|
279 | 279 | admin_role = Role.find_by_name('admin') |
|
280 | 280 | user.roles << admin_role |
|
281 | 281 | else |
|
282 | 282 | flash[:notice] = 'Unknown user' |
|
283 | 283 | end |
|
284 | 284 | flash[:notice] = 'User added as admins' |
|
285 | 285 | redirect_to :action => 'admin' |
|
286 | 286 | end |
|
287 | 287 | |
|
288 | 288 | def revoke_admin |
|
289 | 289 | user = User.find(params[:id]) |
|
290 | 290 | if user==nil |
|
291 | 291 | flash[:notice] = 'Unknown user' |
|
292 | 292 | redirect_to :action => 'admin' and return |
|
293 | 293 | elsif user.login == 'root' |
|
294 | 294 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
295 | 295 | redirect_to :action => 'admin' and return |
|
296 | 296 | end |
|
297 | 297 | |
|
298 | 298 | admin_role = Role.find_by_name('admin') |
|
299 | 299 | user.roles.delete(admin_role) |
|
300 | 300 | flash[:notice] = 'User permission revoked' |
|
301 | 301 | redirect_to :action => 'admin' |
|
302 | 302 | end |
|
303 | 303 | |
|
304 | 304 | protected |
|
305 | 305 | |
|
306 | 306 | def random_password(length=5) |
|
307 | 307 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
308 | 308 | newpass = "" |
|
309 | 309 | length.times { newpass << chars[rand(chars.size-1)] } |
|
310 | 310 | return newpass |
|
311 | 311 | end |
|
312 | 312 | |
|
313 | 313 | def import_from_file(f) |
|
314 | 314 | data_hash = YAML.load(f) |
|
315 | 315 | @import_log = "" |
@@ -1,35 +1,43 | |||
|
1 | 1 | <h1>User grading results</h1> |
|
2 | 2 | |
|
3 | 3 | <table class="info"> |
|
4 | 4 | <tr class="info-head"> |
|
5 | 5 | <th>User</th> |
|
6 | 6 | <th>Name</th> |
|
7 | 7 | <th>Activated?</th> |
|
8 | + <th>Logged in</th> | |
|
9 | + <th>Contest(s)</th> | |
|
8 | 10 | <% @problems.each do |p| %> |
|
9 | 11 | <th><%= p.name %></th> |
|
10 | 12 | <% end %> |
|
11 | 13 | <th>Total</th> |
|
12 | 14 | <th>Passed</th> |
|
13 | 15 | </tr> |
|
14 | 16 | <% counter = 0 %> |
|
15 | 17 | <% @scorearray.each do |sc| %> |
|
16 | 18 | <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>"> |
|
17 | 19 | <% total = 0 %> |
|
18 | 20 | <% num_passed = 0 %> |
|
19 | 21 | <% sc.each_index do |i| %> |
|
20 | 22 | <% if i==0 %> |
|
21 | 23 | <td><%= sc[i].login %></td> |
|
22 | 24 | <td><%= sc[i].full_name %></td> |
|
23 | 25 | <td><%= sc[i].activated %></td> |
|
26 | + <td> | |
|
27 | + <%= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no' %> | |
|
28 | + </td> | |
|
29 | + <td> | |
|
30 | + <%= sc[i].contests.collect {|c| c.name}.join(', ') %> | |
|
31 | + </td> | |
|
24 | 32 | <% else %> |
|
25 | 33 | <td><%= sc[i][0] %></td> |
|
26 | 34 | <% total += sc[i][0] %> |
|
27 | 35 | <% num_passed += 1 if sc[i][1] %> |
|
28 | 36 | <% end %> |
|
29 | 37 | <% end %> |
|
30 | 38 | <td><%= total %></td> |
|
31 | 39 | <td><%= num_passed %></td> |
|
32 | 40 | </tr> |
|
33 | 41 | <% counter += 1 %> |
|
34 | 42 | <% end %> |
|
35 | 43 | </table> |
You need to be logged in to leave comments.
Login now