Description:
more test on user_admin
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r752:3a8a3897c926 - - 6 files changed: 71 inserted, 59 deleted

@@ -0,0 +1,50
1 + require "application_system_test_case"
2 +
3 + class UsersTest < ApplicationSystemTestCase
4 + # test "visiting the index" do
5 + # visit users_url
6 + #
7 + # assert_selector "h1", text: "User"
8 + # end
9 +
10 + test "add new user and edit" do
11 + login('admin','admin')
12 + within 'header' do
13 + click_on 'Manage'
14 + click_on 'Users', match: :first
15 + end
16 +
17 + assert_text "Users"
18 + assert_text "New user"
19 +
20 + click_on "New user", match: :first
21 + fill_in 'Login', with: 'test1'
22 + fill_in 'Full name', with: 'test1 McTestface'
23 + fill_in 'e-mail', with: 'a@a.com'
24 + fill_in 'Password', with: 'abcdef'
25 + fill_in 'Password confirmation', with: 'abcdef'
26 +
27 + click_on 'Create'
28 +
29 + assert_text 'User was successfully created'
30 + assert_text 'a@a.com'
31 + assert_text 'test1 McTestface'
32 +
33 + within('tr', text: 'McTestface') do
34 + click_on 'Edit'
35 + end
36 +
37 + fill_in 'Alias', with: 'hahaha'
38 + fill_in 'Remark', with: 'section 2'
39 + click_on 'Update User'
40 +
41 + assert_text 'section 2'
42 + end
43 +
44 + def login(username,password)
45 + visit root_path
46 + fill_in "Login", with: username
47 + fill_in "Password", with: password
48 + click_on "Login"
49 + end
50 + end
@@ -20,396 +20,395
20 @contests = Contest.enabled
20 @contests = Contest.enabled
21 end
21 end
22
22
23 def active
23 def active
24 sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago)
24 sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago)
25 @users = []
25 @users = []
26 sessions.each do |session|
26 sessions.each do |session|
27 if session.data[:user_id]
27 if session.data[:user_id]
28 @users << User.find(session.data[:user_id])
28 @users << User.find(session.data[:user_id])
29 end
29 end
30 end
30 end
31 end
31 end
32
32
33 def show
33 def show
34 @user = User.find(params[:id])
34 @user = User.find(params[:id])
35 end
35 end
36
36
37 def new
37 def new
38 @user = User.new
38 @user = User.new
39 end
39 end
40
40
41 def create
41 def create
42 @user = User.new(user_params)
42 @user = User.new(user_params)
43 @user.activated = true
43 @user.activated = true
44 if @user.save
44 if @user.save
45 flash[:notice] = 'User was successfully created.'
45 flash[:notice] = 'User was successfully created.'
46 redirect_to :action => 'index'
46 redirect_to :action => 'index'
47 else
47 else
48 render :action => 'new'
48 render :action => 'new'
49 end
49 end
50 end
50 end
51
51
52 def clear_last_ip
52 def clear_last_ip
53 @user = User.find(params[:id])
53 @user = User.find(params[:id])
54 @user.last_ip = nil
54 @user.last_ip = nil
55 @user.save
55 @user.save
56 redirect_to action: 'index', page: params[:page]
56 redirect_to action: 'index', page: params[:page]
57 end
57 end
58
58
59 def create_from_list
59 def create_from_list
60 lines = params[:user_list]
60 lines = params[:user_list]
61
61
62 note = []
62 note = []
63
63
64 lines.split("\n").each do |line|
64 lines.split("\n").each do |line|
65 items = line.chomp.split(',')
65 items = line.chomp.split(',')
66 if items.length>=2
66 if items.length>=2
67 login = items[0]
67 login = items[0]
68 full_name = items[1]
68 full_name = items[1]
69 remark =''
69 remark =''
70 user_alias = ''
70 user_alias = ''
71
71
72 added_random_password = false
72 added_random_password = false
73 if items.length >= 3 and items[2].chomp(" ").length > 0;
73 if items.length >= 3 and items[2].chomp(" ").length > 0;
74 password = items[2].chomp(" ")
74 password = items[2].chomp(" ")
75 else
75 else
76 password = random_password
76 password = random_password
77 add_random_password=true;
77 add_random_password=true;
78 end
78 end
79
79
80 if items.length>= 4 and items[3].chomp(" ").length > 0;
80 if items.length>= 4 and items[3].chomp(" ").length > 0;
81 user_alias = items[3].chomp(" ")
81 user_alias = items[3].chomp(" ")
82 else
82 else
83 user_alias = login
83 user_alias = login
84 end
84 end
85
85
86 if items.length>=5
86 if items.length>=5
87 remark = items[4].strip;
87 remark = items[4].strip;
88 end
88 end
89
89
90 user = User.find_by_login(login)
90 user = User.find_by_login(login)
91 if (user)
91 if (user)
92 user.full_name = full_name
92 user.full_name = full_name
93 user.password = password
93 user.password = password
94 user.remark = remark
94 user.remark = remark
95 else
95 else
96 user = User.new({:login => login,
96 user = User.new({:login => login,
97 :full_name => full_name,
97 :full_name => full_name,
98 :password => password,
98 :password => password,
99 :password_confirmation => password,
99 :password_confirmation => password,
100 :alias => user_alias,
100 :alias => user_alias,
101 :remark => remark})
101 :remark => remark})
102 end
102 end
103 user.activated = true
103 user.activated = true
104 user.save
104 user.save
105
105
106 if added_random_password
106 if added_random_password
107 note << "'#{login}' (+)"
107 note << "'#{login}' (+)"
108 else
108 else
109 note << login
109 note << login
110 end
110 end
111 end
111 end
112 end
112 end
113 flash[:success] = 'User(s) ' + note.join(', ') +
113 flash[:success] = 'User(s) ' + note.join(', ') +
114 ' were successfully created. ' +
114 ' were successfully created. ' +
115 '( (+) - created with random passwords.)'
115 '( (+) - created with random passwords.)'
116 redirect_to :action => 'index'
116 redirect_to :action => 'index'
117 end
117 end
118
118
119 def edit
119 def edit
120 @user = User.find(params[:id])
120 @user = User.find(params[:id])
121 end
121 end
122
122
123 def update
123 def update
124 @user = User.find(params[:id])
124 @user = User.find(params[:id])
125 if @user.update_attributes(user_params)
125 if @user.update_attributes(user_params)
126 flash[:notice] = 'User was successfully updated.'
126 flash[:notice] = 'User was successfully updated.'
127 redirect_to :action => 'show', :id => @user
127 redirect_to :action => 'show', :id => @user
128 else
128 else
129 render :action => 'edit'
129 render :action => 'edit'
130 end
130 end
131 end
131 end
132
132
133 def destroy
133 def destroy
134 User.find(params[:id]).destroy
134 User.find(params[:id]).destroy
135 redirect_to :action => 'index'
135 redirect_to :action => 'index'
136 end
136 end
137
137
138 def user_stat
138 def user_stat
139 if params[:commit] == 'download csv'
139 if params[:commit] == 'download csv'
140 @problems = Problem.all
140 @problems = Problem.all
141 else
141 else
142 @problems = Problem.available_problems
142 @problems = Problem.available_problems
143 end
143 end
144 @users = User.includes(:contests, :contest_stat).where(enabled: true)
144 @users = User.includes(:contests, :contest_stat).where(enabled: true)
145 @scorearray = Array.new
145 @scorearray = Array.new
146 @users.each do |u|
146 @users.each do |u|
147 ustat = Array.new
147 ustat = Array.new
148 ustat[0] = u
148 ustat[0] = u
149 @problems.each do |p|
149 @problems.each do |p|
150 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
150 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
151 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
151 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
152 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
152 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
153 else
153 else
154 ustat << [0,false]
154 ustat << [0,false]
155 end
155 end
156 end
156 end
157 @scorearray << ustat
157 @scorearray << ustat
158 end
158 end
159 if params[:commit] == 'download csv' then
159 if params[:commit] == 'download csv' then
160 csv = gen_csv_from_scorearray(@scorearray,@problems)
160 csv = gen_csv_from_scorearray(@scorearray,@problems)
161 send_data csv, filename: 'last_score.csv'
161 send_data csv, filename: 'last_score.csv'
162 else
162 else
163 render template: 'user_admin/user_stat'
163 render template: 'user_admin/user_stat'
164 end
164 end
165 end
165 end
166
166
167 def user_stat_max
167 def user_stat_max
168 if params[:commit] == 'download csv'
168 if params[:commit] == 'download csv'
169 @problems = Problem.all
169 @problems = Problem.all
170 else
170 else
171 @problems = Problem.available_problems
171 @problems = Problem.available_problems
172 end
172 end
173 @users = User.includes(:contests).includes(:contest_stat).all
173 @users = User.includes(:contests).includes(:contest_stat).all
174 @scorearray = Array.new
174 @scorearray = Array.new
175 #set up range from param
175 #set up range from param
176 since_id = params.fetch(:since_id, 0).to_i
176 since_id = params.fetch(:since_id, 0).to_i
177 until_id = params.fetch(:until_id, 0).to_i
177 until_id = params.fetch(:until_id, 0).to_i
178 @users.each do |u|
178 @users.each do |u|
179 ustat = Array.new
179 ustat = Array.new
180 ustat[0] = u
180 ustat[0] = u
181 @problems.each do |p|
181 @problems.each do |p|
182 max_points = 0
182 max_points = 0
183 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
183 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
184 max_points = sub.points if sub and sub.points and (sub.points > max_points)
184 max_points = sub.points if sub and sub.points and (sub.points > max_points)
185 end
185 end
186 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
186 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
187 end
187 end
188 @scorearray << ustat
188 @scorearray << ustat
189 end
189 end
190
190
191 if params[:commit] == 'download csv' then
191 if params[:commit] == 'download csv' then
192 csv = gen_csv_from_scorearray(@scorearray,@problems)
192 csv = gen_csv_from_scorearray(@scorearray,@problems)
193 send_data csv, filename: 'max_score.csv'
193 send_data csv, filename: 'max_score.csv'
194 else
194 else
195 render template: 'user_admin/user_stat'
195 render template: 'user_admin/user_stat'
196 end
196 end
197 end
197 end
198
198
199 def import
199 def import
200 if params[:file]==''
200 if params[:file]==''
201 flash[:notice] = 'Error importing no file'
201 flash[:notice] = 'Error importing no file'
202 redirect_to :action => 'index' and return
202 redirect_to :action => 'index' and return
203 end
203 end
204 import_from_file(params[:file])
204 import_from_file(params[:file])
205 end
205 end
206
206
207 def random_all_passwords
207 def random_all_passwords
208 users = User.all
208 users = User.all
209 @prefix = params[:prefix] || ''
209 @prefix = params[:prefix] || ''
210 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
210 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
211 @changed = false
211 @changed = false
212 - if request.request_method == 'POST'
212 + if params[:commit] == 'Go ahead'
213 @non_admin_users.each do |user|
213 @non_admin_users.each do |user|
214 password = random_password
214 password = random_password
215 user.password = password
215 user.password = password
216 user.password_confirmation = password
216 user.password_confirmation = password
217 user.save
217 user.save
218 end
218 end
219 @changed = true
219 @changed = true
220 end
220 end
221 end
221 end
222
222
223 -
224 # contest management
223 # contest management
225
224
226 def contests
225 def contests
227 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
226 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
228 @contests = Contest.enabled
227 @contests = Contest.enabled
229 end
228 end
230
229
231 def assign_from_list
230 def assign_from_list
232 contest_id = params[:users_contest_id]
231 contest_id = params[:users_contest_id]
233 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
232 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
234 contest = Contest.find(params[:new_contest][:id])
233 contest = Contest.find(params[:new_contest][:id])
235 if !contest
234 if !contest
236 flash[:notice] = 'Error: no contest'
235 flash[:notice] = 'Error: no contest'
237 redirect_to :action => 'contests', :id =>contest_id
236 redirect_to :action => 'contests', :id =>contest_id
238 end
237 end
239
238
240 note = []
239 note = []
241 users.each do |u|
240 users.each do |u|
242 u.contests = [contest]
241 u.contests = [contest]
243 note << u.login
242 note << u.login
244 end
243 end
245 flash[:notice] = 'User(s) ' + note.join(', ') +
244 flash[:notice] = 'User(s) ' + note.join(', ') +
246 " were successfully reassigned to #{contest.title}."
245 " were successfully reassigned to #{contest.title}."
247 redirect_to :action => 'contests', :id =>contest.id
246 redirect_to :action => 'contests', :id =>contest.id
248 end
247 end
249
248
250 def add_to_contest
249 def add_to_contest
251 user = User.find(params[:id])
250 user = User.find(params[:id])
252 contest = Contest.find(params[:contest_id])
251 contest = Contest.find(params[:contest_id])
253 if user and contest
252 if user and contest
254 user.contests << contest
253 user.contests << contest
255 end
254 end
256 redirect_to :action => 'index'
255 redirect_to :action => 'index'
257 end
256 end
258
257
259 def remove_from_contest
258 def remove_from_contest
260 user = User.find(params[:id])
259 user = User.find(params[:id])
261 contest = Contest.find(params[:contest_id])
260 contest = Contest.find(params[:contest_id])
262 if user and contest
261 if user and contest
263 user.contests.delete(contest)
262 user.contests.delete(contest)
264 end
263 end
265 redirect_to :action => 'index'
264 redirect_to :action => 'index'
266 end
265 end
267
266
268 def contest_management
267 def contest_management
269 end
268 end
270
269
271 def manage_contest
270 def manage_contest
272 contest = Contest.find(params[:contest][:id])
271 contest = Contest.find(params[:contest][:id])
273 if !contest
272 if !contest
274 flash[:notice] = 'You did not choose the contest.'
273 flash[:notice] = 'You did not choose the contest.'
275 redirect_to :action => 'contest_management' and return
274 redirect_to :action => 'contest_management' and return
276 end
275 end
277
276
278 operation = params[:operation]
277 operation = params[:operation]
279
278
280 if not ['add','remove','assign'].include? operation
279 if not ['add','remove','assign'].include? operation
281 flash[:notice] = 'You did not choose the operation to perform.'
280 flash[:notice] = 'You did not choose the operation to perform.'
282 redirect_to :action => 'contest_management' and return
281 redirect_to :action => 'contest_management' and return
283 end
282 end
284
283
285 lines = params[:login_list]
284 lines = params[:login_list]
286 if !lines or lines.blank?
285 if !lines or lines.blank?
287 flash[:notice] = 'You entered an empty list.'
286 flash[:notice] = 'You entered an empty list.'
288 redirect_to :action => 'contest_management' and return
287 redirect_to :action => 'contest_management' and return
289 end
288 end
290
289
291 note = []
290 note = []
292 users = []
291 users = []
293 lines.split("\n").each do |line|
292 lines.split("\n").each do |line|
294 user = User.find_by_login(line.chomp)
293 user = User.find_by_login(line.chomp)
295 if user
294 if user
296 if operation=='add'
295 if operation=='add'
297 if ! user.contests.include? contest
296 if ! user.contests.include? contest
298 user.contests << contest
297 user.contests << contest
299 end
298 end
300 elsif operation=='remove'
299 elsif operation=='remove'
301 user.contests.delete(contest)
300 user.contests.delete(contest)
302 else
301 else
303 user.contests = [contest]
302 user.contests = [contest]
304 end
303 end
305
304
306 if params[:reset_timer]
305 if params[:reset_timer]
307 user.contest_stat.forced_logout = true
306 user.contest_stat.forced_logout = true
308 user.contest_stat.reset_timer_and_save
307 user.contest_stat.reset_timer_and_save
309 end
308 end
310
309
311 if params[:notification_emails]
310 if params[:notification_emails]
312 send_contest_update_notification_email(user, contest)
311 send_contest_update_notification_email(user, contest)
313 end
312 end
314
313
315 note << user.login
314 note << user.login
316 users << user
315 users << user
317 end
316 end
318 end
317 end
319
318
320 if params[:reset_timer]
319 if params[:reset_timer]
321 logout_users(users)
320 logout_users(users)
322 end
321 end
323
322
324 flash[:notice] = 'User(s) ' + note.join(', ') +
323 flash[:notice] = 'User(s) ' + note.join(', ') +
325 ' were successfully modified. '
324 ' were successfully modified. '
326 redirect_to :action => 'contest_management'
325 redirect_to :action => 'contest_management'
327 end
326 end
328
327
329 # admin management
328 # admin management
330
329
331 def admin
330 def admin
332 @admins = User.all.find_all {|user| user.admin? }
331 @admins = User.all.find_all {|user| user.admin? }
333 end
332 end
334
333
335 def grant_admin
334 def grant_admin
336 login = params[:login]
335 login = params[:login]
337 user = User.find_by_login(login)
336 user = User.find_by_login(login)
338 if user!=nil
337 if user!=nil
339 admin_role = Role.find_by_name('admin')
338 admin_role = Role.find_by_name('admin')
340 user.roles << admin_role
339 user.roles << admin_role
341 else
340 else
342 flash[:notice] = 'Unknown user'
341 flash[:notice] = 'Unknown user'
343 end
342 end
344 flash[:notice] = 'User added as admins'
343 flash[:notice] = 'User added as admins'
345 redirect_to :action => 'admin'
344 redirect_to :action => 'admin'
346 end
345 end
347
346
348 def revoke_admin
347 def revoke_admin
349 user = User.find(params[:id])
348 user = User.find(params[:id])
350 if user==nil
349 if user==nil
351 flash[:notice] = 'Unknown user'
350 flash[:notice] = 'Unknown user'
352 redirect_to :action => 'admin' and return
351 redirect_to :action => 'admin' and return
353 elsif user.login == 'root'
352 elsif user.login == 'root'
354 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
353 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
355 redirect_to :action => 'admin' and return
354 redirect_to :action => 'admin' and return
356 end
355 end
357
356
358 admin_role = Role.find_by_name('admin')
357 admin_role = Role.find_by_name('admin')
359 user.roles.delete(admin_role)
358 user.roles.delete(admin_role)
360 flash[:notice] = 'User permission revoked'
359 flash[:notice] = 'User permission revoked'
361 redirect_to :action => 'admin'
360 redirect_to :action => 'admin'
362 end
361 end
363
362
364 # mass mailing
363 # mass mailing
365
364
366 def mass_mailing
365 def mass_mailing
367 end
366 end
368
367
369 def bulk_mail
368 def bulk_mail
370 lines = params[:login_list]
369 lines = params[:login_list]
371 if !lines or lines.blank?
370 if !lines or lines.blank?
372 flash[:notice] = 'You entered an empty list.'
371 flash[:notice] = 'You entered an empty list.'
373 redirect_to :action => 'mass_mailing' and return
372 redirect_to :action => 'mass_mailing' and return
374 end
373 end
375
374
376 mail_subject = params[:subject]
375 mail_subject = params[:subject]
377 if !mail_subject or mail_subject.blank?
376 if !mail_subject or mail_subject.blank?
378 flash[:notice] = 'You entered an empty mail subject.'
377 flash[:notice] = 'You entered an empty mail subject.'
379 redirect_to :action => 'mass_mailing' and return
378 redirect_to :action => 'mass_mailing' and return
380 end
379 end
381
380
382 mail_body = params[:email_body]
381 mail_body = params[:email_body]
383 if !mail_body or mail_body.blank?
382 if !mail_body or mail_body.blank?
384 flash[:notice] = 'You entered an empty mail body.'
383 flash[:notice] = 'You entered an empty mail body.'
385 redirect_to :action => 'mass_mailing' and return
384 redirect_to :action => 'mass_mailing' and return
386 end
385 end
387
386
388 note = []
387 note = []
389 users = []
388 users = []
390 lines.split("\n").each do |line|
389 lines.split("\n").each do |line|
391 user = User.find_by_login(line.chomp)
390 user = User.find_by_login(line.chomp)
392 if user
391 if user
393 send_mail(user.email, mail_subject, mail_body)
392 send_mail(user.email, mail_subject, mail_body)
394 note << user.login
393 note << user.login
395 end
394 end
396 end
395 end
397
396
398 flash[:notice] = 'User(s) ' + note.join(', ') +
397 flash[:notice] = 'User(s) ' + note.join(', ') +
399 ' were successfully modified. '
398 ' were successfully modified. '
400 redirect_to :action => 'mass_mailing'
399 redirect_to :action => 'mass_mailing'
401 end
400 end
402
401
403 #bulk manage
402 #bulk manage
404 def bulk_manage
403 def bulk_manage
405
404
406 begin
405 begin
407 @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex]
406 @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex]
408 @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised
407 @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised
409 rescue Exception
408 rescue Exception
410 flash[:error] = 'Regular Expression is malformed'
409 flash[:error] = 'Regular Expression is malformed'
411 @users = nil
410 @users = nil
412 end
411 end
413
412
414 if params[:commit]
413 if params[:commit]
415 @action = {}
414 @action = {}
@@ -1,38 +1,14
1 - = error_messages_for 'user'
1 + = simple_form_for(@user) do |f|
2 - / [form:user]
2 + = f.error_notification
3 - .form-group
3 + .row
4 - %label.col-md-2.control-label{for: :login} Login
4 + .col-md-6.col-md-offset-2
5 - .col-md-4
5 + = f.input :login, label: 'Login'
6 - = text_field 'user', 'login', class: 'form-control'
6 + = f.input :full_name, label: 'Full name'
7 - .col-md-6
7 + = f.input :password
8 - .form-group
8 + = f.input :password_confirmation
9 - %label.col-md-2.control-label{for: :full_name} Full name
9 + = f.input :email
10 - .col-md-4
10 + = f.input :alias
11 - = text_field 'user', 'full_name', class: 'form-control'
11 + = f.input :remark
12 - .col-md-6
12 + = f.button :submit, class: 'btn btn-success'
13 - .form-group
13 + = link_to 'Cancel', :back, class: 'btn btn-default'
14 - %label.col-md-2.control-label{for: :password} Password
14 +
15 - .col-md-4
16 - = password_field 'user', 'password', class: 'form-control'
17 - .col-md-6
18 - .form-group
19 - %label.col-md-2.control-label{for: :password_confirmation} Password (confirm)
20 - .col-md-4
21 - = password_field 'user', 'password_confirmation', class: 'form-control'
22 - .col-md-6
23 - .form-group
24 - %label.col-md-2.control-label{for: :email} E-mail
25 - .col-md-4
26 - = email_field 'user', 'email', class: 'form-control'
27 - .col-md-6
28 - .form-group
29 - %label.col-md-2.control-label{for: :alias} Alias
30 - .col-md-4
31 - = text_field 'user', 'alias', class: 'form-control'
32 - .col-md-6
33 - .form-group
34 - %label.col-md-2.control-label{for: :remark} Remark
35 - .col-md-4
36 - = text_field 'user', 'remark', class: 'form-control'
37 - .col-md-6
38 - / [eoform:user]
@@ -1,13 +1,4
1 %h1 Editing user
1 %h1 Editing user
2 + = simple_form_for @user, url: user_admin_path(@user) do |f|
3 + = render partial: 'form', local: f
2
4
3 - = form_tag( {:action => 'update', :id => @user}, {class: 'form-horizontal'}) do
4 - = error_messages_for 'user'
5 - = render partial: "form"
6 - .form-group
7 - .col-md-offset-2.col-md-4
8 - = submit_tag "Edit", class: 'btn btn-primary'
9 -
10 -
11 - = link_to 'Show', :action => 'show', :id => @user
12 - |
13 - = link_to 'Back', :action => 'index'
@@ -1,7 +1,3
1 %h1 New user
1 %h1 New user
2 - = form_tag( {action: 'create'}, { class: 'form-horizontal'}) do
2 + = simple_form_for @user, url: user_admin_index_path do |f|
3 - = render :partial => 'form'
3 + = render partial: 'form', local: f
4 - .form-group
5 - .col-md-offset-2.col-md-10
6 - = submit_tag "Create", class: 'btn btn-primary'
7 - = link_to 'Back', :action => 'index'
@@ -1,171 +1,171
1 Rails.application.routes.draw do
1 Rails.application.routes.draw do
2 resources :tags
2 resources :tags
3 get "sources/direct_edit"
3 get "sources/direct_edit"
4
4
5 root :to => 'main#login'
5 root :to => 'main#login'
6
6
7 #logins
7 #logins
8 match 'login/login', to: 'login#login', via: [:get,:post]
8 match 'login/login', to: 'login#login', via: [:get,:post]
9
9
10
10
11 resources :contests
11 resources :contests
12
12
13 resources :sites
13 resources :sites
14
14
15 resources :test
15 resources :test
16
16
17 resources :messages do
17 resources :messages do
18 collection do
18 collection do
19 get 'console'
19 get 'console'
20 end
20 end
21 end
21 end
22
22
23 resources :announcements do
23 resources :announcements do
24 member do
24 member do
25 get 'toggle','toggle_front'
25 get 'toggle','toggle_front'
26 end
26 end
27 end
27 end
28
28
29 resources :problems do
29 resources :problems do
30 member do
30 member do
31 get 'toggle'
31 get 'toggle'
32 get 'toggle_test'
32 get 'toggle_test'
33 get 'toggle_view_testcase'
33 get 'toggle_view_testcase'
34 get 'stat'
34 get 'stat'
35 end
35 end
36 collection do
36 collection do
37 get 'turn_all_off'
37 get 'turn_all_off'
38 get 'turn_all_on'
38 get 'turn_all_on'
39 get 'import'
39 get 'import'
40 get 'manage'
40 get 'manage'
41 get 'quick_create'
41 get 'quick_create'
42 post 'do_manage'
42 post 'do_manage'
43 end
43 end
44 end
44 end
45
45
46 resources :groups do
46 resources :groups do
47 member do
47 member do
48 post 'add_user', to: 'groups#add_user', as: 'add_user'
48 post 'add_user', to: 'groups#add_user', as: 'add_user'
49 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
49 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
50 delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user'
50 delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user'
51 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
51 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
52 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
52 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
53 delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem'
53 delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem'
54 end
54 end
55 collection do
55 collection do
56
56
57 end
57 end
58 end
58 end
59
59
60 resources :testcases, only: [] do
60 resources :testcases, only: [] do
61 member do
61 member do
62 get 'download_input'
62 get 'download_input'
63 get 'download_sol'
63 get 'download_sol'
64 end
64 end
65 collection do
65 collection do
66 get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
66 get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
67 end
67 end
68 end
68 end
69
69
70 resources :grader_configuration, controller: 'configurations'
70 resources :grader_configuration, controller: 'configurations'
71
71
72 resources :users do
72 resources :users do
73 member do
73 member do
74 get 'toggle_activate', 'toggle_enable'
74 get 'toggle_activate', 'toggle_enable'
75 get 'stat'
75 get 'stat'
76 end
76 end
77 end
77 end
78
78
79 resources :submissions do
79 resources :submissions do
80 member do
80 member do
81 get 'download'
81 get 'download'
82 get 'compiler_msg'
82 get 'compiler_msg'
83 get 'rejudge'
83 get 'rejudge'
84 end
84 end
85 collection do
85 collection do
86 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
86 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
87 get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
87 get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
88 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
88 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
89 end
89 end
90 end
90 end
91
91
92
92
93 #user admin
93 #user admin
94 resources :user_admin do
94 resources :user_admin do
95 collection do
95 collection do
96 match 'bulk_manage', via: [:get, :post]
96 match 'bulk_manage', via: [:get, :post]
97 get 'bulk_mail'
97 get 'bulk_mail'
98 get 'user_stat'
98 get 'user_stat'
99 get 'import'
99 get 'import'
100 get 'new_list'
100 get 'new_list'
101 get 'admin'
101 get 'admin'
102 - get 'random_all_passwords'
103 get 'active'
102 get 'active'
104 get 'mass_mailing'
103 get 'mass_mailing'
104 + post 'grant_admin'
105 match 'create_from_list', via: [:get, :post]
105 match 'create_from_list', via: [:get, :post]
106 - post 'grant_admin'
106 + match 'random_all_passwords', via: [:get, :post]
107 end
107 end
108 member do
108 member do
109 get 'clear_last_ip'
109 get 'clear_last_ip'
110 end
110 end
111 end
111 end
112
112
113 resources :contest_management, only: [:index] do
113 resources :contest_management, only: [:index] do
114 collection do
114 collection do
115 get 'user_stat'
115 get 'user_stat'
116 get 'clear_stat'
116 get 'clear_stat'
117 get 'clear_all_stat'
117 get 'clear_all_stat'
118 end
118 end
119 end
119 end
120
120
121 #get 'user_admin', to: 'user_admin#index'
121 #get 'user_admin', to: 'user_admin#index'
122 #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
122 #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
123 #post 'user_admin', to: 'user_admin#create'
123 #post 'user_admin', to: 'user_admin#create'
124 #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
124 #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
125
125
126 #singular resource
126 #singular resource
127 #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly
127 #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly
128 #report
128 #report
129 resource :report, only: [], controller: 'report' do
129 resource :report, only: [], controller: 'report' do
130 get 'login'
130 get 'login'
131 get 'multiple_login'
131 get 'multiple_login'
132 get 'problem_hof/:id', action: 'problem_hof'
132 get 'problem_hof/:id', action: 'problem_hof'
133 get 'current_score'
133 get 'current_score'
134 get 'max_score'
134 get 'max_score'
135 post 'show_max_score'
135 post 'show_max_score'
136 end
136 end
137 #get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
137 #get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
138 #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
138 #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
139 #get "report/login"
139 #get "report/login"
140 #get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
140 #get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
141 #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
141 #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
142
142
143 resource :main, only: [], controller: 'main' do
143 resource :main, only: [], controller: 'main' do
144 get 'list'
144 get 'list'
145 get 'submission(/:id)', action: 'submission', as: 'main_submission'
145 get 'submission(/:id)', action: 'submission', as: 'main_submission'
146 post 'submit'
146 post 'submit'
147 get 'announcements'
147 get 'announcements'
148 get 'help'
148 get 'help'
149 end
149 end
150 #main
150 #main
151 #get "main/list"
151 #get "main/list"
152 #get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
152 #get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
153 #post 'main/submit', to: 'main#submit'
153 #post 'main/submit', to: 'main#submit'
154 #get 'main/announcements', to: 'main#announcements'
154 #get 'main/announcements', to: 'main#announcements'
155
155
156
156
157 #
157 #
158 get 'tasks/view/:file.:ext' => 'tasks#view'
158 get 'tasks/view/:file.:ext' => 'tasks#view'
159 get 'tasks/download/:id/:file.:ext' => 'tasks#download'
159 get 'tasks/download/:id/:file.:ext' => 'tasks#download'
160 get 'heartbeat/:id/edit' => 'heartbeat#edit'
160 get 'heartbeat/:id/edit' => 'heartbeat#edit'
161
161
162 #grader
162 #grader
163 get 'graders/list', to: 'graders#list', as: 'grader_list'
163 get 'graders/list', to: 'graders#list', as: 'grader_list'
164
164
165
165
166 # See how all your routes lay out with "rake routes"
166 # See how all your routes lay out with "rake routes"
167
167
168 # This is a legacy wild controller route that's not recommended for RESTful applications.
168 # This is a legacy wild controller route that's not recommended for RESTful applications.
169 # Note: This route will make all actions in every controller accessible via GET requests.
169 # Note: This route will make all actions in every controller accessible via GET requests.
170 # match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
170 # match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
171 end
171 end
You need to be logged in to leave comments. Login now