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 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 = ""
@@ -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 => 25, :cols => 80
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 - &nbsp;&nbsp;&nbsp;&nbsp;
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