Description:
resets contest start time when changing users' contest
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r289:bafc73878f35 - - 2 files changed: 9 inserted, 3 deleted

@@ -115,192 +115,195
115 @scorearray = Array.new
115 @scorearray = Array.new
116 @users.each do |u|
116 @users.each do |u|
117 ustat = Array.new
117 ustat = Array.new
118 ustat[0] = u
118 ustat[0] = u
119 @problems.each do |p|
119 @problems.each do |p|
120 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
120 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
121 if (sub!=nil) and (sub.points!=nil)
121 if (sub!=nil) and (sub.points!=nil)
122 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
122 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
123 else
123 else
124 ustat << [0,false]
124 ustat << [0,false]
125 end
125 end
126 end
126 end
127 @scorearray << ustat
127 @scorearray << ustat
128 end
128 end
129 end
129 end
130
130
131 def import
131 def import
132 if params[:file]==''
132 if params[:file]==''
133 flash[:notice] = 'Error importing no file'
133 flash[:notice] = 'Error importing no file'
134 redirect_to :action => 'list' and return
134 redirect_to :action => 'list' and return
135 end
135 end
136 import_from_file(params[:file])
136 import_from_file(params[:file])
137 end
137 end
138
138
139 def random_all_passwords
139 def random_all_passwords
140 users = User.find(:all)
140 users = User.find(:all)
141 @prefix = params[:prefix] || ''
141 @prefix = params[:prefix] || ''
142 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
142 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
143 @changed = false
143 @changed = false
144 if request.request_method == :post
144 if request.request_method == :post
145 @non_admin_users.each do |user|
145 @non_admin_users.each do |user|
146 password = random_password
146 password = random_password
147 user.password = password
147 user.password = password
148 user.password_confirmation = password
148 user.password_confirmation = password
149 user.save
149 user.save
150 end
150 end
151 @changed = true
151 @changed = true
152 end
152 end
153 end
153 end
154
154
155 # contest management
155 # contest management
156
156
157 def add_to_contest
157 def add_to_contest
158 user = User.find(params[:id])
158 user = User.find(params[:id])
159 contest = Contest.find(params[:contest_id])
159 contest = Contest.find(params[:contest_id])
160 if user and contest
160 if user and contest
161 user.contests << contest
161 user.contests << contest
162 end
162 end
163 redirect_to :action => 'list'
163 redirect_to :action => 'list'
164 end
164 end
165
165
166 def remove_from_contest
166 def remove_from_contest
167 user = User.find(params[:id])
167 user = User.find(params[:id])
168 contest = Contest.find(params[:contest_id])
168 contest = Contest.find(params[:contest_id])
169 if user and contest
169 if user and contest
170 user.contests.delete(contest)
170 user.contests.delete(contest)
171 end
171 end
172 redirect_to :action => 'list'
172 redirect_to :action => 'list'
173 end
173 end
174
174
175 def contest_management
175 def contest_management
176 end
176 end
177
177
178 def manage_contest
178 def manage_contest
179 contest = Contest.find(params[:contest][:id])
179 contest = Contest.find(params[:contest][:id])
180 if !contest
180 if !contest
181 flash[:notice] = 'You did not choose the contest.'
181 flash[:notice] = 'You did not choose the contest.'
182 redirect_to :action => 'contest_management' and return
182 redirect_to :action => 'contest_management' and return
183 end
183 end
184
184
185 operation = params[:operation]
185 operation = params[:operation]
186
186
187 if not ['add','remove','assign'].include? operation
187 if not ['add','remove','assign'].include? operation
188 flash[:notice] = 'You did not choose the operation to perform.'
188 flash[:notice] = 'You did not choose the operation to perform.'
189 redirect_to :action => 'contest_management' and return
189 redirect_to :action => 'contest_management' and return
190 end
190 end
191
191
192 lines = params[:login_list]
192 lines = params[:login_list]
193 if !lines or lines.blank?
193 if !lines or lines.blank?
194 flash[:notice] = 'You entered an empty list.'
194 flash[:notice] = 'You entered an empty list.'
195 redirect_to :action => 'contest_management' and return
195 redirect_to :action => 'contest_management' and return
196 end
196 end
197
197
198 note = []
198 note = []
199 lines.split("\n").each do |line|
199 lines.split("\n").each do |line|
200 puts line
200 puts line
201 user = User.find_by_login(line.chomp)
201 user = User.find_by_login(line.chomp)
202 puts user
202 puts user
203 if user
203 if user
204 if operation=='add'
204 if operation=='add'
205 user.contests << contest
205 user.contests << contest
206 elsif operation=='remove'
206 elsif operation=='remove'
207 user.contests.delete(contest)
207 user.contests.delete(contest)
208 else
208 else
209 user.contests = [contest]
209 user.contests = [contest]
210 end
210 end
211 +
212 + user.contest_stat.destroy if params[:reset_timer]
213 +
211 note << user.login
214 note << user.login
212 end
215 end
213 end
216 end
214 flash[:notice] = 'User(s) ' + note.join(', ') +
217 flash[:notice] = 'User(s) ' + note.join(', ') +
215 ' were successfully modified. '
218 ' were successfully modified. '
216 redirect_to :action => 'contest_management'
219 redirect_to :action => 'contest_management'
217 end
220 end
218
221
219 # admin management
222 # admin management
220
223
221 def admin
224 def admin
222 @admins = User.find(:all).find_all {|user| user.admin? }
225 @admins = User.find(:all).find_all {|user| user.admin? }
223 end
226 end
224
227
225 def grant_admin
228 def grant_admin
226 login = params[:login]
229 login = params[:login]
227 user = User.find_by_login(login)
230 user = User.find_by_login(login)
228 if user!=nil
231 if user!=nil
229 admin_role = Role.find_by_name('admin')
232 admin_role = Role.find_by_name('admin')
230 user.roles << admin_role
233 user.roles << admin_role
231 else
234 else
232 flash[:notice] = 'Unknown user'
235 flash[:notice] = 'Unknown user'
233 end
236 end
234 flash[:notice] = 'User added as admins'
237 flash[:notice] = 'User added as admins'
235 redirect_to :action => 'admin'
238 redirect_to :action => 'admin'
236 end
239 end
237
240
238 def revoke_admin
241 def revoke_admin
239 user = User.find(params[:id])
242 user = User.find(params[:id])
240 if user==nil
243 if user==nil
241 flash[:notice] = 'Unknown user'
244 flash[:notice] = 'Unknown user'
242 redirect_to :action => 'admin' and return
245 redirect_to :action => 'admin' and return
243 elsif user.login == 'root'
246 elsif user.login == 'root'
244 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
247 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
245 redirect_to :action => 'admin' and return
248 redirect_to :action => 'admin' and return
246 end
249 end
247
250
248 admin_role = Role.find_by_name('admin')
251 admin_role = Role.find_by_name('admin')
249 user.roles.delete(admin_role)
252 user.roles.delete(admin_role)
250 flash[:notice] = 'User permission revoked'
253 flash[:notice] = 'User permission revoked'
251 redirect_to :action => 'admin'
254 redirect_to :action => 'admin'
252 end
255 end
253
256
254 protected
257 protected
255
258
256 def random_password(length=5)
259 def random_password(length=5)
257 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
260 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
258 newpass = ""
261 newpass = ""
259 length.times { newpass << chars[rand(chars.size-1)] }
262 length.times { newpass << chars[rand(chars.size-1)] }
260 return newpass
263 return newpass
261 end
264 end
262
265
263 def import_from_file(f)
266 def import_from_file(f)
264 data_hash = YAML.load(f)
267 data_hash = YAML.load(f)
265 @import_log = ""
268 @import_log = ""
266
269
267 country_data = data_hash[:countries]
270 country_data = data_hash[:countries]
268 site_data = data_hash[:sites]
271 site_data = data_hash[:sites]
269 user_data = data_hash[:users]
272 user_data = data_hash[:users]
270
273
271 # import country
274 # import country
272 countries = {}
275 countries = {}
273 country_data.each_pair do |id,country|
276 country_data.each_pair do |id,country|
274 c = Country.find_by_name(country[:name])
277 c = Country.find_by_name(country[:name])
275 if c!=nil
278 if c!=nil
276 countries[id] = c
279 countries[id] = c
277 @import_log << "Found #{country[:name]}\n"
280 @import_log << "Found #{country[:name]}\n"
278 else
281 else
279 countries[id] = Country.new(:name => country[:name])
282 countries[id] = Country.new(:name => country[:name])
280 countries[id].save
283 countries[id].save
281 @import_log << "Created #{country[:name]}\n"
284 @import_log << "Created #{country[:name]}\n"
282 end
285 end
283 end
286 end
284
287
285 # import sites
288 # import sites
286 sites = {}
289 sites = {}
287 site_data.each_pair do |id,site|
290 site_data.each_pair do |id,site|
288 s = Site.find_by_name(site[:name])
291 s = Site.find_by_name(site[:name])
289 if s!=nil
292 if s!=nil
290 @import_log << "Found #{site[:name]}\n"
293 @import_log << "Found #{site[:name]}\n"
291 else
294 else
292 s = Site.new(:name => site[:name])
295 s = Site.new(:name => site[:name])
293 @import_log << "Created #{site[:name]}\n"
296 @import_log << "Created #{site[:name]}\n"
294 end
297 end
295 s.password = site[:password]
298 s.password = site[:password]
296 s.country = countries[site[:country_id]]
299 s.country = countries[site[:country_id]]
297 s.save
300 s.save
298 sites[id] = s
301 sites[id] = s
299 end
302 end
300
303
301 # import users
304 # import users
302 user_data.each_pair do |id,user|
305 user_data.each_pair do |id,user|
303 u = User.find_by_login(user[:login])
306 u = User.find_by_login(user[:login])
304 if u!=nil
307 if u!=nil
305 @import_log << "Found #{user[:login]}\n"
308 @import_log << "Found #{user[:login]}\n"
306 else
309 else
@@ -1,16 +1,19
1 %h1 Bulk edit users in contests
1 %h1 Bulk edit users in contests
2
2
3 - form_tag :action => 'manage_contest' do
3 - form_tag :action => 'manage_contest' do
4 List users' login below; one per line.
4 List users' login below; one per line.
5 %br/
5 %br/
6 - = text_area_tag 'login_list', nil, :rows => 25, :cols => 80
6 + = text_area_tag 'login_list', nil, :rows => 23, :cols => 80
7 %br/
7 %br/
8 You want to
8 You want to
9 = select(nil,"operation",[['assign users to','assign'],['add users to','add'],['remove users from','remove']])
9 = select(nil,"operation",[['assign users to','assign'],['add users to','add'],['remove users from','remove']])
10 contest
10 contest
11 = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
11 = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
12 - &nbsp;&nbsp;&nbsp;&nbsp;
12 + = check_box_tag 'reset_timer'
13 - = submit_tag "Perform action", :confirm => 'Are you sure?'
13 + Auto-reset current contest timer.
14 + %br/
15 +
16 + = submit_tag "Perform action!", :confirm => 'Are you sure?'
14
17
15 %hr/
18 %hr/
16 = link_to '[go back to index]', :action => 'index'
19 = link_to '[go back to index]', :action => 'index'
You need to be logged in to leave comments. Login now