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