# HG changeset patch # User Nattee Niparnan # Date 2017-09-17 07:48:36 # Node ID 405106fcdb339be641d7204471278e15b7a65e90 # Parent bc0fcfe3abaab2dec7f1568c78de35f3d7f2d79e fix allow admin to submit to any problem diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -86,7 +86,7 @@ render :action => 'list' and return end - if @submission.valid? + if @submission.valid?(@current_user) if @submission.save == false flash[:notice] = 'Error saving your submission' elsif Task.create(:submission_id => @submission.id, diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -52,6 +52,11 @@ def direct_edit_problem @problem = Problem.find(params[:problem_id]) @source = '' + if (params[:user_id]) + u = User.find(params[:user_id]) + @submission = Submission.find_last_by_user_and_problem(u.id,@problem.id) + @source = @submission.source.to_s if @submission and @submission.source + end render 'edit' end diff --git a/app/models/submission.rb b/app/models/submission.rb --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -137,7 +137,7 @@ # for output_only tasks return if self.problem!=nil and self.problem.output_only - + if self.language==nil errors.add('source',"Cannot detect language. Did you submit a correct source file?") unless self.language!=nil end @@ -147,8 +147,12 @@ return if self.source==nil if self.problem==nil errors.add('problem',"must be specified.") - elsif (!self.problem.available) and (self.new_record?) - errors.add('problem',"must be valid.") + else + #admin always have right + return if self.user.admin? + + #check if user has the right to submit the problem + errors.add('problem',"must be valid.") if (!self.user.available_problem.include?(self.problem)) and (self.new_record?) end end diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -292,6 +292,7 @@ return true end + #get a list of available problem def available_problems if not GraderConfiguration.multicontests? if GraderConfiguration.use_problem_group? diff --git a/app/views/problems/index.html.haml b/app/views/problems/index.html.haml --- a/app/views/problems/index.html.haml +++ b/app/views/problems/index.html.haml @@ -44,7 +44,7 @@ = problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1 = link_to_description_if_any "[#{t 'main.problem_desc'}] ".html_safe, problem %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1 - %td= link_to "Submit", direct_edit_problem_submissions_path(problem), class: 'btn btn-xs btn-primary' + %td= link_to "Submit", direct_edit_problem_submissions_path(problem,@current_user.id), class: 'btn btn-xs btn-primary' %td= problem.date_added %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}") %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}") diff --git a/app/views/submissions/edit.html.haml b/app/views/submissions/edit.html.haml --- a/app/views/submissions/edit.html.haml +++ b/app/views/submissions/edit.html.haml @@ -11,6 +11,7 @@ .col-md-8 %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'} .col-md-4 + - # submission form = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do = hidden_field_tag 'editor_text', @source @@ -25,6 +26,7 @@ .form-group = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit', data: {confirm: "Submitting this source code for task #{@problem.long_name}?"} + - # latest submission status .panel.panel-info .panel-heading Latest Submission Status diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -73,7 +73,7 @@ end collection do get 'prob/:problem_id', to: 'submissions#index', as: 'problem' - get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' + get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' end end