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

@@ -163,96 +163,99
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 = ""
@@ -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