Description:
add TA roles
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r799:584294790340 - - 6 files changed: 71 inserted, 42 deleted
@@ -49,64 +49,63 | |||||
|
49 | end |
|
49 | end |
|
50 |
|
50 | ||
|
51 | #on-site new submission on specific problem |
|
51 | #on-site new submission on specific problem |
|
52 | def direct_edit_problem |
|
52 | def direct_edit_problem |
|
53 | @problem = Problem.find(params[:problem_id]) |
|
53 | @problem = Problem.find(params[:problem_id]) |
|
54 | unless @current_user.can_view_problem?(@problem) |
|
54 | unless @current_user.can_view_problem?(@problem) |
|
55 | unauthorized_redirect |
|
55 | unauthorized_redirect |
|
56 | return |
|
56 | return |
|
57 | end |
|
57 | end |
|
58 | @source = '' |
|
58 | @source = '' |
|
59 | if (params[:view_latest]) |
|
59 | if (params[:view_latest]) |
|
60 | sub = Submission.find_last_by_user_and_problem(@current_user.id,@problem.id) |
|
60 | sub = Submission.find_last_by_user_and_problem(@current_user.id,@problem.id) |
|
61 | @source = @submission.source.to_s if @submission and @submission.source |
|
61 | @source = @submission.source.to_s if @submission and @submission.source |
|
62 | end |
|
62 | end |
|
63 | render 'edit' |
|
63 | render 'edit' |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | # GET /submissions/1/edit |
|
66 | # GET /submissions/1/edit |
|
67 | def edit |
|
67 | def edit |
|
68 | @submission = Submission.find(params[:id]) |
|
68 | @submission = Submission.find(params[:id]) |
|
69 | @source = @submission.source.to_s |
|
69 | @source = @submission.source.to_s |
|
70 | @problem = @submission.problem |
|
70 | @problem = @submission.problem |
|
71 | @lang_id = @submission.language.id |
|
71 | @lang_id = @submission.language.id |
|
72 | end |
|
72 | end |
|
73 |
|
73 | ||
|
74 |
|
74 | ||
|
75 | def get_latest_submission_status |
|
75 | def get_latest_submission_status |
|
76 | @problem = Problem.find(params[:pid]) |
|
76 | @problem = Problem.find(params[:pid]) |
|
77 | @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid]) |
|
77 | @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid]) |
|
78 | respond_to do |format| |
|
78 | respond_to do |format| |
|
79 | format.js |
|
79 | format.js |
|
80 | end |
|
80 | end |
|
81 | end |
|
81 | end |
|
82 |
|
82 | ||
|
83 | # GET /submissions/:id/rejudge |
|
83 | # GET /submissions/:id/rejudge |
|
84 | def rejudge |
|
84 | def rejudge |
|
85 | @submission = Submission.find(params[:id]) |
|
85 | @submission = Submission.find(params[:id]) |
|
86 | @task = @submission.task |
|
86 | @task = @submission.task |
|
87 | @task.status_inqueue! if @task |
|
87 | @task.status_inqueue! if @task |
|
88 | respond_to do |format| |
|
88 | respond_to do |format| |
|
89 | format.js |
|
89 | format.js |
|
90 | end |
|
90 | end |
|
91 | end |
|
91 | end |
|
92 |
|
92 | ||
|
93 | protected |
|
93 | protected |
|
94 |
|
94 | ||
|
95 | def submission_authorization |
|
95 | def submission_authorization |
|
96 | #admin always has privileged |
|
96 | #admin always has privileged |
|
97 | - if @current_user.admin? |
|
97 | + return true if @current_user.admin? |
|
98 | - return true |
|
98 | + return true if @current_user.has_role?('TA') && (['show','download'].include? action_name) |
|
99 | - end |
|
||
|
100 |
|
99 | ||
|
101 | sub = Submission.find(params[:id]) |
|
100 | sub = Submission.find(params[:id]) |
|
102 | if @current_user.available_problems.include? sub.problem |
|
101 | if @current_user.available_problems.include? sub.problem |
|
103 | return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user |
|
102 | return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user |
|
104 | end |
|
103 | end |
|
105 |
|
104 | ||
|
106 | #default to NO |
|
105 | #default to NO |
|
107 | unauthorized_redirect |
|
106 | unauthorized_redirect |
|
108 | return false |
|
107 | return false |
|
109 | end |
|
108 | end |
|
110 |
|
109 | ||
|
111 |
|
110 | ||
|
112 | end |
|
111 | end |
@@ -317,126 +317,123 | |||||
|
317 |
|
317 | ||
|
318 | lines = params[:login_list] |
|
318 | lines = params[:login_list] |
|
319 | if !lines or lines.blank? |
|
319 | if !lines or lines.blank? |
|
320 | flash[:notice] = 'You entered an empty list.' |
|
320 | flash[:notice] = 'You entered an empty list.' |
|
321 | redirect_to :action => 'contest_management' and return |
|
321 | redirect_to :action => 'contest_management' and return |
|
322 | end |
|
322 | end |
|
323 |
|
323 | ||
|
324 | note = [] |
|
324 | note = [] |
|
325 | users = [] |
|
325 | users = [] |
|
326 | lines.split("\n").each do |line| |
|
326 | lines.split("\n").each do |line| |
|
327 | user = User.find_by_login(line.chomp) |
|
327 | user = User.find_by_login(line.chomp) |
|
328 | if user |
|
328 | if user |
|
329 | if operation=='add' |
|
329 | if operation=='add' |
|
330 | if ! user.contests.include? contest |
|
330 | if ! user.contests.include? contest |
|
331 | user.contests << contest |
|
331 | user.contests << contest |
|
332 | end |
|
332 | end |
|
333 | elsif operation=='remove' |
|
333 | elsif operation=='remove' |
|
334 | user.contests.delete(contest) |
|
334 | user.contests.delete(contest) |
|
335 | else |
|
335 | else |
|
336 | user.contests = [contest] |
|
336 | user.contests = [contest] |
|
337 | end |
|
337 | end |
|
338 |
|
338 | ||
|
339 | if params[:reset_timer] |
|
339 | if params[:reset_timer] |
|
340 | user.contest_stat.forced_logout = true |
|
340 | user.contest_stat.forced_logout = true |
|
341 | user.contest_stat.reset_timer_and_save |
|
341 | user.contest_stat.reset_timer_and_save |
|
342 | end |
|
342 | end |
|
343 |
|
343 | ||
|
344 | if params[:notification_emails] |
|
344 | if params[:notification_emails] |
|
345 | send_contest_update_notification_email(user, contest) |
|
345 | send_contest_update_notification_email(user, contest) |
|
346 | end |
|
346 | end |
|
347 |
|
347 | ||
|
348 | note << user.login |
|
348 | note << user.login |
|
349 | users << user |
|
349 | users << user |
|
350 | end |
|
350 | end |
|
351 | end |
|
351 | end |
|
352 |
|
352 | ||
|
353 | if params[:reset_timer] |
|
353 | if params[:reset_timer] |
|
354 | logout_users(users) |
|
354 | logout_users(users) |
|
355 | end |
|
355 | end |
|
356 |
|
356 | ||
|
357 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
357 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
358 | ' were successfully modified. ' |
|
358 | ' were successfully modified. ' |
|
359 | redirect_to :action => 'contest_management' |
|
359 | redirect_to :action => 'contest_management' |
|
360 | end |
|
360 | end |
|
361 |
|
361 | ||
|
362 | # admin management |
|
362 | # admin management |
|
363 |
|
363 | ||
|
364 | def admin |
|
364 | def admin |
|
365 | - @admins = User.all.find_all {|user| user.admin? } |
|
365 | + @admins = Role.where(name: 'admin').take.users |
|
|
366 | + @tas = Role.where(name: 'ta').take.users | ||
|
366 | end |
|
367 | end |
|
367 |
|
368 | ||
|
368 | - def grant_admin |
|
369 | + def modify_role |
|
369 |
- |
|
370 | + user = User.find_by_login(params[:login]) |
|
370 | - user = User.find_by_login(login) |
|
371 | + role = Role.find_by_name(params[:role]) |
|
371 | - if user!=nil |
|
372 | + unless user && role |
|
372 | - admin_role = Role.find_by_name('admin') |
|
373 | + flash[:error] = 'Unknown user or role' |
|
373 | - user.roles << admin_role |
|
374 | + redirect_to admin_user_admin_index_path |
|
374 | - else |
|
375 | + return |
|
375 | - flash[:notice] = 'Unknown user' |
|
||
|
376 | - end |
|
||
|
377 | - flash[:notice] = 'User added as admins' |
|
||
|
378 | - redirect_to :action => 'admin' |
|
||
|
379 | end |
|
376 | end |
|
380 | - |
|
377 | + if params[:commit] == 'Grant' |
|
381 | - def revoke_admin |
|
378 | + #grant role |
|
382 | - user = User.find(params[:id]) |
|
379 | + user.roles << role |
|
383 | - if user==nil |
|
380 | + flash[:notice] = "User '#{user.login}' has been granted the role '#{role.name}'" |
|
384 | - flash[:notice] = 'Unknown user' |
|
381 | + else |
|
385 | - redirect_to :action => 'admin' and return |
|
382 | + #revoke role |
|
386 |
- |
|
383 | + if user.login == 'root' && role.name == 'admin' |
|
387 |
- flash[: |
|
384 | + flash[:error] = 'You cannot revoke admisnistrator permission from root.' |
|
388 | - redirect_to :action => 'admin' and return |
|
385 | + redirect_to admin_user_admin_index_path |
|
|
386 | + return | ||
|
389 | end |
|
387 | end |
|
390 | - |
|
388 | + user.roles.delete(role) |
|
391 | - admin_role = Role.find_by_name('admin') |
|
389 | + flash[:notice] = "The role '#{role.name}' has been revoked from User '#{user.login}'" |
|
392 | - user.roles.delete(admin_role) |
|
390 | + end |
|
393 | - flash[:notice] = 'User permission revoked' |
|
391 | + redirect_to admin_user_admin_index_path |
|
394 | - redirect_to :action => 'admin' |
|
||
|
395 | end |
|
392 | end |
|
396 |
|
393 | ||
|
397 | # mass mailing |
|
394 | # mass mailing |
|
398 |
|
395 | ||
|
399 | def mass_mailing |
|
396 | def mass_mailing |
|
400 | end |
|
397 | end |
|
401 |
|
398 | ||
|
402 | def bulk_mail |
|
399 | def bulk_mail |
|
403 | lines = params[:login_list] |
|
400 | lines = params[:login_list] |
|
404 | if !lines or lines.blank? |
|
401 | if !lines or lines.blank? |
|
405 | flash[:notice] = 'You entered an empty list.' |
|
402 | flash[:notice] = 'You entered an empty list.' |
|
406 | redirect_to :action => 'mass_mailing' and return |
|
403 | redirect_to :action => 'mass_mailing' and return |
|
407 | end |
|
404 | end |
|
408 |
|
405 | ||
|
409 | mail_subject = params[:subject] |
|
406 | mail_subject = params[:subject] |
|
410 | if !mail_subject or mail_subject.blank? |
|
407 | if !mail_subject or mail_subject.blank? |
|
411 | flash[:notice] = 'You entered an empty mail subject.' |
|
408 | flash[:notice] = 'You entered an empty mail subject.' |
|
412 | redirect_to :action => 'mass_mailing' and return |
|
409 | redirect_to :action => 'mass_mailing' and return |
|
413 | end |
|
410 | end |
|
414 |
|
411 | ||
|
415 | mail_body = params[:email_body] |
|
412 | mail_body = params[:email_body] |
|
416 | if !mail_body or mail_body.blank? |
|
413 | if !mail_body or mail_body.blank? |
|
417 | flash[:notice] = 'You entered an empty mail body.' |
|
414 | flash[:notice] = 'You entered an empty mail body.' |
|
418 | redirect_to :action => 'mass_mailing' and return |
|
415 | redirect_to :action => 'mass_mailing' and return |
|
419 | end |
|
416 | end |
|
420 |
|
417 | ||
|
421 | note = [] |
|
418 | note = [] |
|
422 | users = [] |
|
419 | users = [] |
|
423 | lines.split("\n").each do |line| |
|
420 | lines.split("\n").each do |line| |
|
424 | user = User.find_by_login(line.chomp) |
|
421 | user = User.find_by_login(line.chomp) |
|
425 | if user |
|
422 | if user |
|
426 | send_mail(user.email, mail_subject, mail_body) |
|
423 | send_mail(user.email, mail_subject, mail_body) |
|
427 | note << user.login |
|
424 | note << user.login |
|
428 | end |
|
425 | end |
|
429 | end |
|
426 | end |
|
430 |
|
427 | ||
|
431 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
428 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
432 | ' were successfully modified. ' |
|
429 | ' were successfully modified. ' |
|
433 | redirect_to :action => 'mass_mailing' |
|
430 | redirect_to :action => 'mass_mailing' |
|
434 | end |
|
431 | end |
|
435 |
|
432 | ||
|
436 | #bulk manage |
|
433 | #bulk manage |
|
437 | def bulk_manage |
|
434 | def bulk_manage |
|
438 |
|
435 | ||
|
439 | begin |
|
436 | begin |
|
440 | @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex] |
|
437 | @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex] |
|
441 | @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised |
|
438 | @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised |
|
442 | rescue Exception |
|
439 | rescue Exception |
@@ -36,97 +36,101 | |||||
|
36 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
36 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
37 | validates_length_of :login, :within => 3..30 |
|
37 | validates_length_of :login, :within => 3..30 |
|
38 |
|
38 | ||
|
39 | validates_presence_of :full_name |
|
39 | validates_presence_of :full_name |
|
40 | validates_length_of :full_name, :minimum => 1 |
|
40 | validates_length_of :full_name, :minimum => 1 |
|
41 |
|
41 | ||
|
42 | validates_presence_of :password, :if => :password_required? |
|
42 | validates_presence_of :password, :if => :password_required? |
|
43 | validates_length_of :password, :within => 4..50, :if => :password_required? |
|
43 | validates_length_of :password, :within => 4..50, :if => :password_required? |
|
44 | validates_confirmation_of :password, :if => :password_required? |
|
44 | validates_confirmation_of :password, :if => :password_required? |
|
45 |
|
45 | ||
|
46 | validates_format_of :email, |
|
46 | validates_format_of :email, |
|
47 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
47 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
48 | :if => :email_validation? |
|
48 | :if => :email_validation? |
|
49 | validate :uniqueness_of_email_from_activated_users, |
|
49 | validate :uniqueness_of_email_from_activated_users, |
|
50 | :if => :email_validation? |
|
50 | :if => :email_validation? |
|
51 | validate :enough_time_interval_between_same_email_registrations, |
|
51 | validate :enough_time_interval_between_same_email_registrations, |
|
52 | :if => :email_validation? |
|
52 | :if => :email_validation? |
|
53 |
|
53 | ||
|
54 | # these are for ytopc |
|
54 | # these are for ytopc |
|
55 | # disable for now |
|
55 | # disable for now |
|
56 | #validates_presence_of :province |
|
56 | #validates_presence_of :province |
|
57 |
|
57 | ||
|
58 | attr_accessor :password |
|
58 | attr_accessor :password |
|
59 |
|
59 | ||
|
60 | before_save :encrypt_new_password |
|
60 | before_save :encrypt_new_password |
|
61 | before_save :assign_default_site |
|
61 | before_save :assign_default_site |
|
62 | before_save :assign_default_contest |
|
62 | before_save :assign_default_contest |
|
63 |
|
63 | ||
|
64 | # this is for will_paginate |
|
64 | # this is for will_paginate |
|
65 | cattr_reader :per_page |
|
65 | cattr_reader :per_page |
|
66 | @@per_page = 50 |
|
66 | @@per_page = 50 |
|
67 |
|
67 | ||
|
68 | def self.authenticate(login, password) |
|
68 | def self.authenticate(login, password) |
|
69 | user = find_by_login(login) |
|
69 | user = find_by_login(login) |
|
70 | if user |
|
70 | if user |
|
71 | return user if user.authenticated?(password) |
|
71 | return user if user.authenticated?(password) |
|
72 | end |
|
72 | end |
|
73 | end |
|
73 | end |
|
74 |
|
74 | ||
|
75 | def authenticated?(password) |
|
75 | def authenticated?(password) |
|
76 | if self.activated |
|
76 | if self.activated |
|
77 | hashed_password == User.encrypt(password,self.salt) |
|
77 | hashed_password == User.encrypt(password,self.salt) |
|
78 | else |
|
78 | else |
|
79 | false |
|
79 | false |
|
80 | end |
|
80 | end |
|
81 | end |
|
81 | end |
|
82 |
|
82 | ||
|
83 | def admin? |
|
83 | def admin? |
|
84 | - self.roles.where(name: 'admin').count > 0 |
|
84 | + has_role?('admin') |
|
|
85 | + end | ||
|
|
86 | + | ||
|
|
87 | + def has_role?(role) | ||
|
|
88 | + self.roles.where(name: role).count > 0 | ||
|
85 | end |
|
89 | end |
|
86 |
|
90 | ||
|
87 | def email_for_editing |
|
91 | def email_for_editing |
|
88 | if self.email==nil |
|
92 | if self.email==nil |
|
89 | "(unknown)" |
|
93 | "(unknown)" |
|
90 | elsif self.email=='' |
|
94 | elsif self.email=='' |
|
91 | "(blank)" |
|
95 | "(blank)" |
|
92 | else |
|
96 | else |
|
93 | self.email |
|
97 | self.email |
|
94 | end |
|
98 | end |
|
95 | end |
|
99 | end |
|
96 |
|
100 | ||
|
97 | def email_for_editing=(e) |
|
101 | def email_for_editing=(e) |
|
98 | self.email=e |
|
102 | self.email=e |
|
99 | end |
|
103 | end |
|
100 |
|
104 | ||
|
101 | def alias_for_editing |
|
105 | def alias_for_editing |
|
102 | if self.alias==nil |
|
106 | if self.alias==nil |
|
103 | "(unknown)" |
|
107 | "(unknown)" |
|
104 | elsif self.alias=='' |
|
108 | elsif self.alias=='' |
|
105 | "(blank)" |
|
109 | "(blank)" |
|
106 | else |
|
110 | else |
|
107 | self.alias |
|
111 | self.alias |
|
108 | end |
|
112 | end |
|
109 | end |
|
113 | end |
|
110 |
|
114 | ||
|
111 | def alias_for_editing=(e) |
|
115 | def alias_for_editing=(e) |
|
112 | self.alias=e |
|
116 | self.alias=e |
|
113 | end |
|
117 | end |
|
114 |
|
118 | ||
|
115 | def activation_key |
|
119 | def activation_key |
|
116 | if self.hashed_password==nil |
|
120 | if self.hashed_password==nil |
|
117 | encrypt_new_password |
|
121 | encrypt_new_password |
|
118 | end |
|
122 | end |
|
119 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
123 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
120 | end |
|
124 | end |
|
121 |
|
125 | ||
|
122 | def verify_activation_key(key) |
|
126 | def verify_activation_key(key) |
|
123 | key == activation_key |
|
127 | key == activation_key |
|
124 | end |
|
128 | end |
|
125 |
|
129 | ||
|
126 | def self.random_password(length=5) |
|
130 | def self.random_password(length=5) |
|
127 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
131 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
128 | password = '' |
|
132 | password = '' |
|
129 | length.times { password << chars[rand(chars.length - 1)] } |
|
133 | length.times { password << chars[rand(chars.length - 1)] } |
|
130 | password |
|
134 | password |
|
131 | end |
|
135 | end |
|
132 |
|
136 |
@@ -1,25 +1,54 | |||||
|
1 | - %h1 Administrators |
|
1 | + %h1 Modify Role |
|
2 | - |
|
2 | + .row |
|
3 | - %table{:class => 'info'} |
|
3 | + .col-md-6 |
|
4 | - %tr{:class => 'info-head'} |
|
4 | + %h4 Administrators |
|
|
5 | + = form_tag modify_role_user_admin_index_path, method: 'post', class: 'form-inline' do | ||
|
|
6 | + = hidden_field_tag :role, 'admin' | ||
|
|
7 | + .form-group | ||
|
|
8 | + = label_tag :login, 'Grant admin role to:' | ||
|
|
9 | + = text_field_tag 'login',nil, class: 'form-control' | ||
|
|
10 | + .form-group | ||
|
|
11 | + = submit_tag 'Grant', class: 'btn btn-primary' | ||
|
|
12 | + %br | ||
|
|
13 | + %table.table.table-condense.table-hover.table-striped.table-bordered | ||
|
|
14 | + %thead{:class => 'info-head'} | ||
|
5 | %th # |
|
15 | %th # |
|
6 | %th Login |
|
16 | %th Login |
|
7 | %th Full name |
|
17 | %th Full name |
|
8 | %th |
|
18 | %th |
|
9 | - @admins.each_with_index do |user, i| |
|
19 | - @admins.each_with_index do |user, i| |
|
10 | %tr |
|
20 | %tr |
|
11 | %td= i+1 |
|
21 | %td= i+1 |
|
12 | %td= user.login |
|
22 | %td= user.login |
|
13 | %td= user.full_name |
|
23 | %td= user.full_name |
|
14 | %td |
|
24 | %td |
|
15 | - if user.login!='root' |
|
25 | - if user.login!='root' |
|
16 | - = link_to '[revoke]', :action => 'revoke_admin', :id => user.id |
|
26 | + = link_to '[revoke]', modify_role_user_admin_index_path( login: user.login, role: 'admin', commit: 'revoke') |
|
17 | - %hr |
|
27 | + .col-md-6 |
|
|
28 | + %h4 Teacher Assistants (TA) | ||
|
|
29 | + = form_tag modify_role_user_admin_index_path, method: 'post', class: 'form-inline' do | ||
|
|
30 | + = hidden_field_tag :role, 'TA' | ||
|
|
31 | + .form-group | ||
|
|
32 | + = label_tag :login, 'Grant TA role to:' | ||
|
|
33 | + = text_field_tag 'login',nil, class: 'form-control' | ||
|
|
34 | + .form-group | ||
|
|
35 | + = submit_tag 'Grant', class: 'btn btn-primary' | ||
|
|
36 | + %br | ||
|
|
37 | + %table.table.table-condense.table-hover.table-striped.table-bordered | ||
|
|
38 | + %thead{:class => 'info-head'} | ||
|
|
39 | + %th # | ||
|
|
40 | + %th Login | ||
|
|
41 | + %th Full name | ||
|
|
42 | + %th | ||
|
|
43 | + - @tas.each_with_index do |user, i| | ||
|
|
44 | + %tr | ||
|
|
45 | + %td= i+1 | ||
|
|
46 | + %td= user.login | ||
|
|
47 | + %td= user.full_name | ||
|
|
48 | + %td | ||
|
|
49 | + - if user.login!='root' | ||
|
|
50 | + = link_to '[revoke]', modify_role_user_admin_index_path( login: user.login, role: 'TA', commit: 'revoke') | ||
|
18 |
|
51 | ||
|
19 | - = form_tag :action => 'grant_admin' do |
|
||
|
20 | - = label_tag :login, 'Grant admin permission to:' |
|
||
|
21 | - = text_field_tag 'login',nil, class: 'input-field' |
|
||
|
22 | - = submit_tag 'Grant', class: 'btn btn-primary' |
|
||
|
23 |
|
52 | ||
|
24 | %hr/ |
|
53 | %hr/ |
|
25 | = link_to '[go back to index]', :action => 'index' |
|
54 | = link_to '[go back to index]', :action => 'index' |
@@ -68,98 +68,97 | |||||
|
68 | end |
|
68 | end |
|
69 | collection do |
|
69 | collection do |
|
70 | get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem' |
|
70 | get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem' |
|
71 | end |
|
71 | end |
|
72 | end |
|
72 | end |
|
73 |
|
73 | ||
|
74 | resources :grader_configuration, controller: 'configurations' do |
|
74 | resources :grader_configuration, controller: 'configurations' do |
|
75 | collection do |
|
75 | collection do |
|
76 | get 'set_exam_right(/:value)', action: 'set_exam_right', as: 'set_exam_right' |
|
76 | get 'set_exam_right(/:value)', action: 'set_exam_right', as: 'set_exam_right' |
|
77 | end |
|
77 | end |
|
78 | end |
|
78 | end |
|
79 |
|
79 | ||
|
80 | resources :users do |
|
80 | resources :users do |
|
81 | member do |
|
81 | member do |
|
82 | get 'toggle_activate', 'toggle_enable' |
|
82 | get 'toggle_activate', 'toggle_enable' |
|
83 | get 'stat' |
|
83 | get 'stat' |
|
84 | end |
|
84 | end |
|
85 | collection do |
|
85 | collection do |
|
86 | get 'profile' |
|
86 | get 'profile' |
|
87 | post 'chg_passwd' |
|
87 | post 'chg_passwd' |
|
88 | end |
|
88 | end |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | resources :submissions do |
|
91 | resources :submissions do |
|
92 | member do |
|
92 | member do |
|
93 | get 'download' |
|
93 | get 'download' |
|
94 | get 'compiler_msg' |
|
94 | get 'compiler_msg' |
|
95 | get 'rejudge' |
|
95 | get 'rejudge' |
|
96 | end |
|
96 | end |
|
97 | collection do |
|
97 | collection do |
|
98 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
98 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
99 | get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' |
|
99 | get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' |
|
100 | get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' |
|
100 | get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' |
|
101 | end |
|
101 | end |
|
102 | end |
|
102 | end |
|
103 |
|
103 | ||
|
104 |
|
104 | ||
|
105 | #user admin |
|
105 | #user admin |
|
106 | resources :user_admin do |
|
106 | resources :user_admin do |
|
107 | collection do |
|
107 | collection do |
|
108 | match 'bulk_manage', via: [:get, :post] |
|
108 | match 'bulk_manage', via: [:get, :post] |
|
109 | get 'bulk_mail' |
|
109 | get 'bulk_mail' |
|
110 | get 'user_stat' |
|
110 | get 'user_stat' |
|
111 | get 'import' |
|
111 | get 'import' |
|
112 | get 'new_list' |
|
112 | get 'new_list' |
|
113 | get 'admin' |
|
113 | get 'admin' |
|
114 | get 'active' |
|
114 | get 'active' |
|
115 | get 'mass_mailing' |
|
115 | get 'mass_mailing' |
|
116 | - get 'revoke_admin' |
|
116 | + match 'modify_role', via: [:get, :post] |
|
117 | - post 'grant_admin' |
|
||
|
118 | match 'create_from_list', via: [:get, :post] |
|
117 | match 'create_from_list', via: [:get, :post] |
|
119 | match 'random_all_passwords', via: [:get, :post] |
|
118 | match 'random_all_passwords', via: [:get, :post] |
|
120 | end |
|
119 | end |
|
121 | member do |
|
120 | member do |
|
122 | get 'clear_last_ip' |
|
121 | get 'clear_last_ip' |
|
123 | end |
|
122 | end |
|
124 | end |
|
123 | end |
|
125 |
|
124 | ||
|
126 | resources :contest_management, only: [:index] do |
|
125 | resources :contest_management, only: [:index] do |
|
127 | collection do |
|
126 | collection do |
|
128 | get 'user_stat' |
|
127 | get 'user_stat' |
|
129 | get 'clear_stat' |
|
128 | get 'clear_stat' |
|
130 | get 'clear_all_stat' |
|
129 | get 'clear_all_stat' |
|
131 | get 'change_contest_mode' |
|
130 | get 'change_contest_mode' |
|
132 | end |
|
131 | end |
|
133 | end |
|
132 | end |
|
134 |
|
133 | ||
|
135 | #get 'user_admin', to: 'user_admin#index' |
|
134 | #get 'user_admin', to: 'user_admin#index' |
|
136 | #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' |
|
135 | #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' |
|
137 | #post 'user_admin', to: 'user_admin#create' |
|
136 | #post 'user_admin', to: 'user_admin#create' |
|
138 | #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy' |
|
137 | #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy' |
|
139 |
|
138 | ||
|
140 | #singular resource |
|
139 | #singular resource |
|
141 | #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly |
|
140 | #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly |
|
142 | #report |
|
141 | #report |
|
143 | resource :report, only: [], controller: 'report' do |
|
142 | resource :report, only: [], controller: 'report' do |
|
144 | get 'login' |
|
143 | get 'login' |
|
145 | get 'multiple_login' |
|
144 | get 'multiple_login' |
|
146 | get 'problem_hof(/:id)', action: 'problem_hof', as: 'problem_hof' |
|
145 | get 'problem_hof(/:id)', action: 'problem_hof', as: 'problem_hof' |
|
147 | get 'current_score(/:group_id)', action: 'current_score', as: 'current_score' |
|
146 | get 'current_score(/:group_id)', action: 'current_score', as: 'current_score' |
|
148 | get 'max_score' |
|
147 | get 'max_score' |
|
149 | post 'show_max_score' |
|
148 | post 'show_max_score' |
|
150 | get 'stuck' |
|
149 | get 'stuck' |
|
151 | get 'cheat_report' |
|
150 | get 'cheat_report' |
|
152 | post 'cheat_report' |
|
151 | post 'cheat_report' |
|
153 | get 'cheat_scruntinize' |
|
152 | get 'cheat_scruntinize' |
|
154 | post 'cheat_scruntinize' |
|
153 | post 'cheat_scruntinize' |
|
155 | end |
|
154 | end |
|
156 | #get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
155 | #get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
157 | #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
156 | #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
158 | #get "report/login" |
|
157 | #get "report/login" |
|
159 | #get 'report/max_score', to: 'report#max_score', as: 'report_max_score' |
|
158 | #get 'report/max_score', to: 'report#max_score', as: 'report_max_score' |
|
160 | #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' |
|
159 | #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' |
|
161 |
|
160 | ||
|
162 | resource :main, only: [], controller: 'main' do |
|
161 | resource :main, only: [], controller: 'main' do |
|
163 | get 'login' |
|
162 | get 'login' |
|
164 | get 'logout' |
|
163 | get 'logout' |
|
165 | get 'list' |
|
164 | get 'list' |
@@ -180,96 +180,97 | |||||
|
180 | :description => "If true, available problem to the user will be only ones associated with the group of the user." |
|
180 | :description => "If true, available problem to the user will be only ones associated with the group of the user." |
|
181 | }, |
|
181 | }, |
|
182 |
|
182 | ||
|
183 |
|
183 | ||
|
184 | { |
|
184 | { |
|
185 | :key => 'right.whitelist_ignore', |
|
185 | :key => 'right.whitelist_ignore', |
|
186 | :value_type => 'boolean', |
|
186 | :value_type => 'boolean', |
|
187 | :default_value => 'true', |
|
187 | :default_value => 'true', |
|
188 | :description => "If true, no IP check against whitelist_ip is perform. However, when false, non-admin user must have their ip in 'whitelist_ip' to be able to login." |
|
188 | :description => "If true, no IP check against whitelist_ip is perform. However, when false, non-admin user must have their ip in 'whitelist_ip' to be able to login." |
|
189 | }, |
|
189 | }, |
|
190 |
|
190 | ||
|
191 | { |
|
191 | { |
|
192 | :key => 'right.whitelist_ip', |
|
192 | :key => 'right.whitelist_ip', |
|
193 | :value_type => 'string', |
|
193 | :value_type => 'string', |
|
194 | :default_value => '0.0.0.0/0', |
|
194 | :default_value => '0.0.0.0/0', |
|
195 | :description => "list of whitelist ip, given in comma separated CIDR notation. For example '192.168.90.0/23, 192.168.1.23/32'" |
|
195 | :description => "list of whitelist ip, given in comma separated CIDR notation. For example '192.168.90.0/23, 192.168.1.23/32'" |
|
196 | }, |
|
196 | }, |
|
197 |
|
197 | ||
|
198 | ] |
|
198 | ] |
|
199 |
|
199 | ||
|
200 |
|
200 | ||
|
201 | def create_configuration_key(key, |
|
201 | def create_configuration_key(key, |
|
202 | value_type, |
|
202 | value_type, |
|
203 | default_value, |
|
203 | default_value, |
|
204 | description='') |
|
204 | description='') |
|
205 | conf = (GraderConfiguration.find_by_key(key) || |
|
205 | conf = (GraderConfiguration.find_by_key(key) || |
|
206 | GraderConfiguration.new(:key => key, |
|
206 | GraderConfiguration.new(:key => key, |
|
207 | :value_type => value_type, |
|
207 | :value_type => value_type, |
|
208 | :value => default_value)) |
|
208 | :value => default_value)) |
|
209 | conf.description = description |
|
209 | conf.description = description |
|
210 | conf.save |
|
210 | conf.save |
|
211 | end |
|
211 | end |
|
212 |
|
212 | ||
|
213 | def seed_config |
|
213 | def seed_config |
|
214 | CONFIGURATIONS.each do |conf| |
|
214 | CONFIGURATIONS.each do |conf| |
|
215 | if conf.has_key? :description |
|
215 | if conf.has_key? :description |
|
216 | desc = conf[:description] |
|
216 | desc = conf[:description] |
|
217 | else |
|
217 | else |
|
218 | desc = '' |
|
218 | desc = '' |
|
219 | end |
|
219 | end |
|
220 | create_configuration_key(conf[:key], |
|
220 | create_configuration_key(conf[:key], |
|
221 | conf[:value_type], |
|
221 | conf[:value_type], |
|
222 | conf[:default_value], |
|
222 | conf[:default_value], |
|
223 | desc) |
|
223 | desc) |
|
224 | end |
|
224 | end |
|
225 | end |
|
225 | end |
|
226 |
|
226 | ||
|
227 | def seed_roles |
|
227 | def seed_roles |
|
|
228 | + Role.find_or_create_by(name: 'TA') | ||
|
228 | return if Role.find_by_name('admin') |
|
229 | return if Role.find_by_name('admin') |
|
229 |
|
230 | ||
|
230 | role = Role.create(:name => 'admin') |
|
231 | role = Role.create(:name => 'admin') |
|
231 | user_admin_right = Right.create(:name => 'user_admin', |
|
232 | user_admin_right = Right.create(:name => 'user_admin', |
|
232 | :controller => 'user_admin', |
|
233 | :controller => 'user_admin', |
|
233 | :action => 'all') |
|
234 | :action => 'all') |
|
234 | problem_admin_right = Right.create(:name=> 'problem_admin', |
|
235 | problem_admin_right = Right.create(:name=> 'problem_admin', |
|
235 | :controller => 'problems', |
|
236 | :controller => 'problems', |
|
236 | :action => 'all') |
|
237 | :action => 'all') |
|
237 |
|
238 | ||
|
238 | graders_right = Right.create(:name => 'graders_admin', |
|
239 | graders_right = Right.create(:name => 'graders_admin', |
|
239 | :controller => 'graders', |
|
240 | :controller => 'graders', |
|
240 | :action => 'all') |
|
241 | :action => 'all') |
|
241 |
|
242 | ||
|
242 | role.rights << user_admin_right; |
|
243 | role.rights << user_admin_right; |
|
243 | role.rights << problem_admin_right; |
|
244 | role.rights << problem_admin_right; |
|
244 | role.rights << graders_right; |
|
245 | role.rights << graders_right; |
|
245 | role.save |
|
246 | role.save |
|
246 | end |
|
247 | end |
|
247 |
|
248 | ||
|
248 | def seed_root |
|
249 | def seed_root |
|
249 | return if User.find_by_login('root') |
|
250 | return if User.find_by_login('root') |
|
250 |
|
251 | ||
|
251 | root = User.new(:login => 'root', |
|
252 | root = User.new(:login => 'root', |
|
252 | :full_name => 'Administrator', |
|
253 | :full_name => 'Administrator', |
|
253 | :alias => 'root') |
|
254 | :alias => 'root') |
|
254 | root.password = 'ioionrails'; |
|
255 | root.password = 'ioionrails'; |
|
255 |
|
256 | ||
|
256 | class << root |
|
257 | class << root |
|
257 | public :encrypt_new_password |
|
258 | public :encrypt_new_password |
|
258 | def valid?(context=nil) |
|
259 | def valid?(context=nil) |
|
259 | true |
|
260 | true |
|
260 | end |
|
261 | end |
|
261 | end |
|
262 | end |
|
262 |
|
263 | ||
|
263 | root.encrypt_new_password |
|
264 | root.encrypt_new_password |
|
264 |
|
265 | ||
|
265 | root.roles << Role.find_by_name('admin') |
|
266 | root.roles << Role.find_by_name('admin') |
|
266 |
|
267 | ||
|
267 | root.activated = true |
|
268 | root.activated = true |
|
268 | root.save |
|
269 | root.save |
|
269 | end |
|
270 | end |
|
270 |
|
271 | ||
|
271 | def seed_users_and_roles |
|
272 | def seed_users_and_roles |
|
272 | seed_roles |
|
273 | seed_roles |
|
273 | seed_root |
|
274 | seed_root |
|
274 | end |
|
275 | end |
|
275 |
|
276 |
You need to be logged in to leave comments.
Login now