Description:
remove lingering debug info
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r786:4e030454953c - - 3 files changed: 0 inserted, 6 deleted

@@ -1,168 +1,167
1 require 'ipaddr'
1 require 'ipaddr'
2
2
3 class ApplicationController < ActionController::Base
3 class ApplicationController < ActionController::Base
4 protect_from_forgery
4 protect_from_forgery
5
5
6 before_action :current_user
6 before_action :current_user
7
7
8 SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode'
8 SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode'
9 MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login'
9 MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login'
10 WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore'
10 WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore'
11 WHITELIST_IP_CONF_KEY = 'right.whitelist_ip'
11 WHITELIST_IP_CONF_KEY = 'right.whitelist_ip'
12
12
13 #report and redirect for unauthorized activities
13 #report and redirect for unauthorized activities
14 def unauthorized_redirect(notice = 'You are not authorized to view the page you requested')
14 def unauthorized_redirect(notice = 'You are not authorized to view the page you requested')
15 flash[:notice] = notice
15 flash[:notice] = notice
16 redirect_to login_main_path
16 redirect_to login_main_path
17 end
17 end
18
18
19 # Returns the current logged-in user (if any).
19 # Returns the current logged-in user (if any).
20 def current_user
20 def current_user
21 return nil unless session[:user_id]
21 return nil unless session[:user_id]
22 @current_user ||= User.find(session[:user_id])
22 @current_user ||= User.find(session[:user_id])
23 end
23 end
24
24
25 def admin_authorization
25 def admin_authorization
26 return false unless check_valid_login
26 return false unless check_valid_login
27 user = User.includes(:roles).find(session[:user_id])
27 user = User.includes(:roles).find(session[:user_id])
28 unless user.admin?
28 unless user.admin?
29 unauthorized_redirect
29 unauthorized_redirect
30 return false
30 return false
31 end
31 end
32 return true
32 return true
33 end
33 end
34
34
35 def authorization_by_roles(allowed_roles)
35 def authorization_by_roles(allowed_roles)
36 return false unless check_valid_login
36 return false unless check_valid_login
37 user = User.find(session[:user_id])
37 user = User.find(session[:user_id])
38 unless user.roles.detect { |role| allowed_roles.member?(role.name) }
38 unless user.roles.detect { |role| allowed_roles.member?(role.name) }
39 unauthorized_redirect
39 unauthorized_redirect
40 return false
40 return false
41 end
41 end
42 end
42 end
43
43
44 def testcase_authorization
44 def testcase_authorization
45 #admin always has privileged
45 #admin always has privileged
46 if @current_user.admin?
46 if @current_user.admin?
47 return true
47 return true
48 end
48 end
49
49
50 unauthorized_redirect unless GraderConfiguration["right.view_testcase"]
50 unauthorized_redirect unless GraderConfiguration["right.view_testcase"]
51 end
51 end
52
52
53
53
54 protected
54 protected
55
55
56 #redirect to root (and also force logout)
56 #redirect to root (and also force logout)
57 #if the user is not logged_in or the system is in "ADMIN ONLY" mode
57 #if the user is not logged_in or the system is in "ADMIN ONLY" mode
58 def check_valid_login
58 def check_valid_login
59 #check if logged in
59 #check if logged in
60 unless session[:user_id]
60 unless session[:user_id]
61 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
61 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
62 unauthorized_redirect('You need to login but you cannot log in at this time')
62 unauthorized_redirect('You need to login but you cannot log in at this time')
63 else
63 else
64 unauthorized_redirect('You need to login')
64 unauthorized_redirect('You need to login')
65 end
65 end
66 return false
66 return false
67 end
67 end
68
68
69 # check if run in single user mode
69 # check if run in single user mode
70 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
70 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
71 if @current_user==nil || (!@current_user.admin?)
71 if @current_user==nil || (!@current_user.admin?)
72 unauthorized_redirect('You cannot log in at this time')
72 unauthorized_redirect('You cannot log in at this time')
73 return false
73 return false
74 end
74 end
75 end
75 end
76
76
77 # check if the user is enabled
77 # check if the user is enabled
78 unless @current_user.enabled? || @current_user.admin?
78 unless @current_user.enabled? || @current_user.admin?
79 unauthorized_redirect 'Your account is disabled'
79 unauthorized_redirect 'Your account is disabled'
80 return false
80 return false
81 end
81 end
82
82
83 # check if user ip is allowed
83 # check if user ip is allowed
84 unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY]
84 unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY]
85 unless is_request_ip_allowed?
85 unless is_request_ip_allowed?
86 unauthorized_redirect 'Your IP is not allowed to login at this time.'
86 unauthorized_redirect 'Your IP is not allowed to login at this time.'
87 return false
87 return false
88 end
88 end
89 end
89 end
90
90
91 if GraderConfiguration.multicontests?
91 if GraderConfiguration.multicontests?
92 return true if @current_user.admin?
92 return true if @current_user.admin?
93 begin
93 begin
94 if @current_user.contest_stat(true).forced_logout
94 if @current_user.contest_stat(true).forced_logout
95 flash[:notice] = 'You have been automatically logged out.'
95 flash[:notice] = 'You have been automatically logged out.'
96 redirect_to :controller => 'main', :action => 'index'
96 redirect_to :controller => 'main', :action => 'index'
97 end
97 end
98 rescue
98 rescue
99 end
99 end
100 end
100 end
101 return true
101 return true
102 end
102 end
103
103
104 #redirect to root (and also force logout)
104 #redirect to root (and also force logout)
105 #if the user use different ip from the previous connection
105 #if the user use different ip from the previous connection
106 # only applicable when MULTIPLE_IP_LOGIN options is false only
106 # only applicable when MULTIPLE_IP_LOGIN options is false only
107 def authenticate_by_ip_address
107 def authenticate_by_ip_address
108 #this assume that we have already authenticate normally
108 #this assume that we have already authenticate normally
109 unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY]
109 unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY]
110 user = User.find(session[:user_id])
110 user = User.find(session[:user_id])
111 if (!user.admin? && user.last_ip && user.last_ip != request.remote_ip)
111 if (!user.admin? && user.last_ip && user.last_ip != request.remote_ip)
112 flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}"
112 flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}"
113 redirect_to :controller => 'main', :action => 'login'
113 redirect_to :controller => 'main', :action => 'login'
114 return false
114 return false
115 end
115 end
116 unless user.last_ip
116 unless user.last_ip
117 user.last_ip = request.remote_ip
117 user.last_ip = request.remote_ip
118 user.save
118 user.save
119 end
119 end
120 end
120 end
121 return true
121 return true
122 end
122 end
123
123
124 def authorization
124 def authorization
125 return false unless check_valid_login
125 return false unless check_valid_login
126 user = User.find(session[:user_id])
126 user = User.find(session[:user_id])
127 unless user.roles.detect { |role|
127 unless user.roles.detect { |role|
128 role.rights.detect{ |right|
128 role.rights.detect{ |right|
129 right.controller == self.class.controller_name and
129 right.controller == self.class.controller_name and
130 (right.action == 'all' || right.action == action_name)
130 (right.action == 'all' || right.action == action_name)
131 }
131 }
132 }
132 }
133 flash[:notice] = 'You are not authorized to view the page you requested'
133 flash[:notice] = 'You are not authorized to view the page you requested'
134 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
134 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
135 redirect_to :controller => 'main', :action => 'login'
135 redirect_to :controller => 'main', :action => 'login'
136 return false
136 return false
137 end
137 end
138 end
138 end
139
139
140 def verify_time_limit
140 def verify_time_limit
141 return true if session[:user_id]==nil
141 return true if session[:user_id]==nil
142 user = User.find(session[:user_id], :include => :site)
142 user = User.find(session[:user_id], :include => :site)
143 return true if user==nil || user.site == nil
143 return true if user==nil || user.site == nil
144 if user.contest_finished?
144 if user.contest_finished?
145 flash[:notice] = 'Error: the contest you are participating is over.'
145 flash[:notice] = 'Error: the contest you are participating is over.'
146 redirect_to :back
146 redirect_to :back
147 return false
147 return false
148 end
148 end
149 return true
149 return true
150 end
150 end
151
151
152 def is_request_ip_allowed?
152 def is_request_ip_allowed?
153 unless GraderConfiguration[WHITELIST_IGNORE_CONF_KEY]
153 unless GraderConfiguration[WHITELIST_IGNORE_CONF_KEY]
154 user_ip = IPAddr.new(request.remote_ip)
154 user_ip = IPAddr.new(request.remote_ip)
155
155
156 GraderConfiguration[WHITELIST_IP_CONF_KEY].delete(' ').split(',').each do |ips|
156 GraderConfiguration[WHITELIST_IP_CONF_KEY].delete(' ').split(',').each do |ips|
157 - puts "ip is #{ips}, user ip is #{user_ip}"
158 allow_ips = IPAddr.new(ips)
157 allow_ips = IPAddr.new(ips)
159 if allow_ips.include?(user_ip)
158 if allow_ips.include?(user_ip)
160 return true
159 return true
161 end
160 end
162 end
161 end
163 return false
162 return false
164 end
163 end
165 return true
164 return true
166 end
165 end
167
166
168 end
167 end
@@ -1,115 +1,112
1 class SubmissionsController < ApplicationController
1 class SubmissionsController < ApplicationController
2 before_action :check_valid_login
2 before_action :check_valid_login
3 before_action :submission_authorization, only: [:show, :download, :edit]
3 before_action :submission_authorization, only: [:show, :download, :edit]
4 before_action :admin_authorization, only: [:rejudge]
4 before_action :admin_authorization, only: [:rejudge]
5
5
6 # GET /submissions
6 # GET /submissions
7 # GET /submissions.json
7 # GET /submissions.json
8 # Show problem selection and user's submission of that problem
8 # Show problem selection and user's submission of that problem
9 def index
9 def index
10 @user = @current_user
10 @user = @current_user
11 @problems = @user.available_problems
11 @problems = @user.available_problems
12
12
13 if params[:problem_id]==nil
13 if params[:problem_id]==nil
14 @problem = nil
14 @problem = nil
15 @submissions = nil
15 @submissions = nil
16 else
16 else
17 @problem = Problem.find_by_id(params[:problem_id])
17 @problem = Problem.find_by_id(params[:problem_id])
18 if (@problem == nil) or (not @problem.available)
18 if (@problem == nil) or (not @problem.available)
19 redirect_to main_list_path
19 redirect_to main_list_path
20 flash[:notice] = 'Error: submissions for that problem are not viewable.'
20 flash[:notice] = 'Error: submissions for that problem are not viewable.'
21 return
21 return
22 end
22 end
23 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id).order(id: :desc)
23 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id).order(id: :desc)
24 end
24 end
25 end
25 end
26
26
27 # GET /submissions/1
27 # GET /submissions/1
28 # GET /submissions/1.json
28 # GET /submissions/1.json
29 def show
29 def show
30 @submission = Submission.find(params[:id])
30 @submission = Submission.find(params[:id])
31
31
32 #log the viewing
32 #log the viewing
33 user = User.find(session[:user_id])
33 user = User.find(session[:user_id])
34 SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin?
34 SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin?
35
35
36 @task = @submission.task
36 @task = @submission.task
37 end
37 end
38
38
39 def download
39 def download
40 @submission = Submission.find(params[:id])
40 @submission = Submission.find(params[:id])
41 send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'})
41 send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'})
42 end
42 end
43
43
44 def compiler_msg
44 def compiler_msg
45 @submission = Submission.find(params[:id])
45 @submission = Submission.find(params[:id])
46 respond_to do |format|
46 respond_to do |format|
47 format.js
47 format.js
48 end
48 end
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 - puts User.find(params[:uid]).login
79 - puts Problem.find(params[:pid]).name
80 - puts 'nil' unless @submission
81 respond_to do |format|
78 respond_to do |format|
82 format.js
79 format.js
83 end
80 end
84 end
81 end
85
82
86 # GET /submissions/:id/rejudge
83 # GET /submissions/:id/rejudge
87 def rejudge
84 def rejudge
88 @submission = Submission.find(params[:id])
85 @submission = Submission.find(params[:id])
89 @task = @submission.task
86 @task = @submission.task
90 @task.status_inqueue! if @task
87 @task.status_inqueue! if @task
91 respond_to do |format|
88 respond_to do |format|
92 format.js
89 format.js
93 end
90 end
94 end
91 end
95
92
96 protected
93 protected
97
94
98 def submission_authorization
95 def submission_authorization
99 #admin always has privileged
96 #admin always has privileged
100 if @current_user.admin?
97 if @current_user.admin?
101 return true
98 return true
102 end
99 end
103
100
104 sub = Submission.find(params[:id])
101 sub = Submission.find(params[:id])
105 if @current_user.available_problems.include? sub.problem
102 if @current_user.available_problems.include? sub.problem
106 return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user
103 return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user
107 end
104 end
108
105
109 #default to NO
106 #default to NO
110 unauthorized_redirect
107 unauthorized_redirect
111 return false
108 return false
112 end
109 end
113
110
114
111
115 end
112 end
@@ -1,71 +1,69
1 %table.table.sortable.table-striped.table-bordered.table-condensed
1 %table.table.sortable.table-striped.table-bordered.table-condensed
2 %thead
2 %thead
3 %tr
3 %tr
4 %th Login
4 %th Login
5 %th Name
5 %th Name
6 / %th Activated?
6 / %th Activated?
7 / %th Logged_in
7 / %th Logged_in
8 / %th Contest(s)
8 / %th Contest(s)
9 %th Remark
9 %th Remark
10 - @problems.each do |p|
10 - @problems.each do |p|
11 %th.text-right= p.name.gsub('_',' ')
11 %th.text-right= p.name.gsub('_',' ')
12 %th.text-right Total
12 %th.text-right Total
13 %th.text-right Passed
13 %th.text-right Passed
14 %tbody
14 %tbody
15 - sum = Array.new(@problems.count+1,0)
15 - sum = Array.new(@problems.count+1,0)
16 - nonzero = Array.new(@problems.count+1,0)
16 - nonzero = Array.new(@problems.count+1,0)
17 - full = Array.new(@problems.count+1,0)
17 - full = Array.new(@problems.count+1,0)
18 - - puts @scorearray
19 - - puts @problems.count
20 - @scorearray.each do |sc|
18 - @scorearray.each do |sc|
21 %tr
19 %tr
22 - total,num_passed = 0,0
20 - total,num_passed = 0,0
23 - sc.each_index do |i|
21 - sc.each_index do |i|
24 - if i == 0
22 - if i == 0
25 %td= link_to sc[i].login, stat_user_path(sc[i])
23 %td= link_to sc[i].login, stat_user_path(sc[i])
26 %td= sc[i].full_name
24 %td= sc[i].full_name
27 / %td= sc[i].activated
25 / %td= sc[i].activated
28 / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
26 / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
29 / %td= sc[i].contests.collect {|c| c.name}.join(', ')
27 / %td= sc[i].contests.collect {|c| c.name}.join(', ')
30 %td= sc[i].remark
28 %td= sc[i].remark
31 - else
29 - else
32 %td.text-right= sc[i][0]
30 %td.text-right= sc[i][0]
33 - total += sc[i][0]
31 - total += sc[i][0]
34 - num_passed += 1 if sc[i][1]
32 - num_passed += 1 if sc[i][1]
35 - sum[i] += sc[i][0]
33 - sum[i] += sc[i][0]
36 - nonzero[i] += 1 if sc[i][0] > 0
34 - nonzero[i] += 1 if sc[i][0] > 0
37 - full[i] += 1 if sc[i][1]
35 - full[i] += 1 if sc[i][1]
38 %td.text-right= total
36 %td.text-right= total
39 %td.text-right= num_passed
37 %td.text-right= num_passed
40 %tfoot
38 %tfoot
41 %tr
39 %tr
42 %td Summation
40 %td Summation
43 %td
41 %td
44 %td
42 %td
45 - sum.each.with_index do |s,i|
43 - sum.each.with_index do |s,i|
46 - next if i == 0
44 - next if i == 0
47 %td.text-right= number_with_delimiter(s)
45 %td.text-right= number_with_delimiter(s)
48 %td
46 %td
49 %td
47 %td
50 %tr
48 %tr
51 %td partial solver
49 %td partial solver
52 %td
50 %td
53 %td
51 %td
54 - nonzero.each.with_index do |s,i|
52 - nonzero.each.with_index do |s,i|
55 - next if i == 0
53 - next if i == 0
56 %td.text-right= number_with_delimiter(s)
54 %td.text-right= number_with_delimiter(s)
57 %td
55 %td
58 %td
56 %td
59 %tr
57 %tr
60 %td Full solver
58 %td Full solver
61 %td
59 %td
62 %td
60 %td
63 - full.each.with_index do |s,i|
61 - full.each.with_index do |s,i|
64 - next if i == 0
62 - next if i == 0
65 %td.text-right= number_with_delimiter(s)
63 %td.text-right= number_with_delimiter(s)
66 %td
64 %td
67 %td
65 %td
68
66
69
67
70 :javascript
68 :javascript
71 $.bootstrapSortable(true,'reversed')
69 $.bootstrapSortable(true,'reversed')
You need to be logged in to leave comments. Login now