Description:
fix allow admin to submit to any problem
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r682:405106fcdb33 - - 7 files changed: 18 inserted, 6 deleted

@@ -77,25 +77,25
77 @submission.language = language
77 @submission.language = language
78 end
78 end
79
79
80 @submission.submitted_at = Time.new.gmtime
80 @submission.submitted_at = Time.new.gmtime
81 @submission.ip_address = request.remote_ip
81 @submission.ip_address = request.remote_ip
82
82
83 if GraderConfiguration.time_limit_mode? and user.contest_finished?
83 if GraderConfiguration.time_limit_mode? and user.contest_finished?
84 @submission.errors.add(:base,"The contest is over.")
84 @submission.errors.add(:base,"The contest is over.")
85 prepare_list_information
85 prepare_list_information
86 render :action => 'list' and return
86 render :action => 'list' and return
87 end
87 end
88
88
89 - if @submission.valid?
89 + if @submission.valid?(@current_user)
90 if @submission.save == false
90 if @submission.save == false
91 flash[:notice] = 'Error saving your submission'
91 flash[:notice] = 'Error saving your submission'
92 elsif Task.create(:submission_id => @submission.id,
92 elsif Task.create(:submission_id => @submission.id,
93 :status => Task::STATUS_INQUEUE) == false
93 :status => Task::STATUS_INQUEUE) == false
94 flash[:notice] = 'Error adding your submission to task queue'
94 flash[:notice] = 'Error adding your submission to task queue'
95 end
95 end
96 else
96 else
97 prepare_list_information
97 prepare_list_information
98 render :action => 'list' and return
98 render :action => 'list' and return
99 end
99 end
100 redirect_to :action => 'list'
100 redirect_to :action => 'list'
101 end
101 end
@@ -43,24 +43,29
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 @source = ''
54 @source = ''
55 + if (params[:user_id])
56 + u = User.find(params[:user_id])
57 + @submission = Submission.find_last_by_user_and_problem(u.id,@problem.id)
58 + @source = @submission.source.to_s if @submission and @submission.source
59 + end
55 render 'edit'
60 render 'edit'
56 end
61 end
57
62
58 # GET /submissions/1/edit
63 # GET /submissions/1/edit
59 def edit
64 def edit
60 @submission = Submission.find(params[:id])
65 @submission = Submission.find(params[:id])
61 @source = @submission.source.to_s
66 @source = @submission.source.to_s
62 @problem = @submission.problem
67 @problem = @submission.problem
63 @lang_id = @submission.language.id
68 @lang_id = @submission.language.id
64 end
69 end
65
70
66
71
@@ -128,35 +128,39
128
128
129 def assign_language
129 def assign_language
130 self.language = Submission.find_language_in_source(self.source,
130 self.language = Submission.find_language_in_source(self.source,
131 self.source_filename)
131 self.source_filename)
132 end
132 end
133
133
134 # validation codes
134 # validation codes
135 def must_specify_language
135 def must_specify_language
136 return if self.source==nil
136 return if self.source==nil
137
137
138 # for output_only tasks
138 # for output_only tasks
139 return if self.problem!=nil and self.problem.output_only
139 return if self.problem!=nil and self.problem.output_only
140 -
140 +
141 if self.language==nil
141 if self.language==nil
142 errors.add('source',"Cannot detect language. Did you submit a correct source file?") unless self.language!=nil
142 errors.add('source',"Cannot detect language. Did you submit a correct source file?") unless self.language!=nil
143 end
143 end
144 end
144 end
145
145
146 def must_have_valid_problem
146 def must_have_valid_problem
147 return if self.source==nil
147 return if self.source==nil
148 if self.problem==nil
148 if self.problem==nil
149 errors.add('problem',"must be specified.")
149 errors.add('problem',"must be specified.")
150 - elsif (!self.problem.available) and (self.new_record?)
150 + else
151 - errors.add('problem',"must be valid.")
151 + #admin always have right
152 + return if self.user.admin?
153 +
154 + #check if user has the right to submit the problem
155 + errors.add('problem',"must be valid.") if (!self.user.available_problem.include?(self.problem)) and (self.new_record?)
152 end
156 end
153 end
157 end
154
158
155 # callbacks
159 # callbacks
156 def assign_latest_number_if_new_recond
160 def assign_latest_number_if_new_recond
157 return if !self.new_record?
161 return if !self.new_record?
158 latest = Submission.find_last_by_user_and_problem(self.user_id, self.problem_id)
162 latest = Submission.find_last_by_user_and_problem(self.user_id, self.problem_id)
159 self.number = (latest==nil) ? 1 : latest.number + 1;
163 self.number = (latest==nil) ? 1 : latest.number + 1;
160 end
164 end
161
165
162 end
166 end
@@ -283,24 +283,25
283 return contest_problems
283 return contest_problems
284 end
284 end
285
285
286 def solve_all_available_problems?
286 def solve_all_available_problems?
287 available_problems.each do |p|
287 available_problems.each do |p|
288 u = self
288 u = self
289 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
289 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
290 return false if !p or !sub or sub.points < p.full_score
290 return false if !p or !sub or sub.points < p.full_score
291 end
291 end
292 return true
292 return true
293 end
293 end
294
294
295 + #get a list of available problem
295 def available_problems
296 def available_problems
296 if not GraderConfiguration.multicontests?
297 if not GraderConfiguration.multicontests?
297 if GraderConfiguration.use_problem_group?
298 if GraderConfiguration.use_problem_group?
298 return available_problems_in_group
299 return available_problems_in_group
299 else
300 else
300 return Problem.available_problems
301 return Problem.available_problems
301 end
302 end
302 else
303 else
303 contest_problems = []
304 contest_problems = []
304 pin = {}
305 pin = {}
305 contests.enabled.each do |contest|
306 contests.enabled.each do |contest|
306 contest.problems.available.each do |problem|
307 contest.problems.available.each do |problem|
@@ -35,25 +35,25
35 Test?
35 Test?
36 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user uses test interface on this problem?' } [?]
36 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user uses test interface on this problem?' } [?]
37 - if GraderConfiguration.multicontests?
37 - if GraderConfiguration.multicontests?
38 %th Contests
38 %th Contests
39 - for problem in @problems
39 - for problem in @problems
40 %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"}
40 %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"}
41 - @problem=problem
41 - @problem=problem
42 %td= problem.name #in_place_editor_field :problem, :name, {}, :rows=>1
42 %td= problem.name #in_place_editor_field :problem, :name, {}, :rows=>1
43 %td
43 %td
44 = problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1
44 = problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1
45 = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem
45 = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem
46 %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1
46 %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1
47 - %td= link_to "Submit", direct_edit_problem_submissions_path(problem), class: 'btn btn-xs btn-primary'
47 + %td= link_to "Submit", direct_edit_problem_submissions_path(problem,@current_user.id), class: 'btn btn-xs btn-primary'
48 %td= problem.date_added
48 %td= problem.date_added
49 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
49 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
50 %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}")
50 %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}")
51 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
51 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
52 - if GraderConfiguration.multicontests?
52 - if GraderConfiguration.multicontests?
53 %td
53 %td
54 = problem.contests.collect { |c| c.name }.join(', ')
54 = problem.contests.collect { |c| c.name }.join(', ')
55 %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn-info btn-xs btn-block'
55 %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn-info btn-xs btn-block'
56 %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn-info btn-xs btn-block'
56 %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn-info btn-xs btn-block'
57 %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn-info btn-xs btn-block'
57 %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn-info btn-xs btn-block'
58 %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :delete, class: 'btn btn-danger btn-xs btn-block'
58 %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :delete, class: 'btn btn-danger btn-xs btn-block'
59 %br/
59 %br/
@@ -2,38 +2,40
2 %br
2 %br
3
3
4 %textarea#text_sourcecode{style: "display:none"}~ @source
4 %textarea#text_sourcecode{style: "display:none"}~ @source
5 .container
5 .container
6 .row
6 .row
7 .col-md-12
7 .col-md-12
8 .alert.alert-info
8 .alert.alert-info
9 Write your code in the following box, choose language, and click submit button when finished
9 Write your code in the following box, choose language, and click submit button when finished
10 .row
10 .row
11 .col-md-8
11 .col-md-8
12 %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'}
12 %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'}
13 .col-md-4
13 .col-md-4
14 + - # submission form
14 = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do
15 = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do
15
16
16 = hidden_field_tag 'editor_text', @source
17 = hidden_field_tag 'editor_text', @source
17 = hidden_field_tag 'submission[problem_id]', @problem.id
18 = hidden_field_tag 'submission[problem_id]', @problem.id
18 .form-group
19 .form-group
19 = label_tag "Task:"
20 = label_tag "Task:"
20 = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true
21 = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true
21
22
22 .form-group
23 .form-group
23 = label_tag 'Language'
24 = label_tag 'Language'
24 = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px"
25 = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px"
25 .form-group
26 .form-group
26 = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit',
27 = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit',
27 data: {confirm: "Submitting this source code for task #{@problem.long_name}?"}
28 data: {confirm: "Submitting this source code for task #{@problem.long_name}?"}
29 + - # latest submission status
28 .panel.panel-info
30 .panel.panel-info
29 .panel-heading
31 .panel-heading
30 Latest Submission Status
32 Latest Submission Status
31 = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission
33 = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission
32 .panel-body
34 .panel-body
33 - if @submission
35 - if @submission
34 = render :partial => 'submission_short',
36 = render :partial => 'submission_short',
35 :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id }
37 :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id }
36 .row
38 .row
37 .col-md-12
39 .col-md-12
38 %h2 Console
40 %h2 Console
39 %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20}
41 %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20}
@@ -64,25 +64,25
64 get 'stat'
64 get 'stat'
65 end
65 end
66 end
66 end
67
67
68 resources :submissions do
68 resources :submissions do
69 member do
69 member do
70 get 'download'
70 get 'download'
71 get 'compiler_msg'
71 get 'compiler_msg'
72 get 'rejudge'
72 get 'rejudge'
73 end
73 end
74 collection do
74 collection do
75 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
75 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
76 - get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
76 + get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
77 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
77 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
78 end
78 end
79 end
79 end
80
80
81
81
82
82
83 #main
83 #main
84 get "main/list"
84 get "main/list"
85 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
85 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
86
86
87 #user admin
87 #user admin
88 get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
88 get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
You need to be logged in to leave comments. Login now