Description:
fix access right control bugs
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r683:d4ac431eeeb6 - - 2 files changed: 9 inserted, 7 deleted

@@ -1,15 +1,15
1 class SubmissionsController < ApplicationController
1 class SubmissionsController < ApplicationController
2 before_action :authenticate
2 before_action :authenticate
3 - before_action :submission_authorization, only: [:show, :direct_edit_submission, :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
@@ -42,28 +42,31
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)
55 + unauthorized_redirect
56 + return
57 + end
54 @source = ''
58 @source = ''
55 - if (params[:user_id])
59 + if (params[:view_latest])
56 - u = User.find(params[:user_id])
60 + sub = Submission.find_last_by_user_and_problem(@current_user.id,@problem.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
61 @source = @submission.source.to_s if @submission and @submission.source
59 end
62 end
60 render 'edit'
63 render 'edit'
61 end
64 end
62
65
63 # GET /submissions/1/edit
66 # GET /submissions/1/edit
64 def edit
67 def edit
65 @submission = Submission.find(params[:id])
68 @submission = Submission.find(params[:id])
66 @source = @submission.source.to_s
69 @source = @submission.source.to_s
67 @problem = @submission.problem
70 @problem = @submission.problem
68 @lang_id = @submission.language.id
71 @lang_id = @submission.language.id
69 end
72 end
@@ -90,24 +93,23
90 end
93 end
91 end
94 end
92
95
93 protected
96 protected
94
97
95 def submission_authorization
98 def submission_authorization
96 #admin always has privileged
99 #admin always has privileged
97 if @current_user.admin?
100 if @current_user.admin?
98 return true
101 return true
99 end
102 end
100
103
101 sub = Submission.find(params[:id])
104 sub = Submission.find(params[:id])
102 - if sub.problem.available?
105 + if @current_user.available_problems.include? sub.problem
103 - puts "sub = #{sub.user.id}, current = #{@current_user.id}"
104 return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user
106 return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user
105 end
107 end
106
108
107 #default to NO
109 #default to NO
108 unauthorized_redirect
110 unauthorized_redirect
109 return false
111 return false
110 end
112 end
111
113
112
114
113 end
115 end
@@ -143,24 +143,24
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 else
150 else
151 #admin always have right
151 #admin always have right
152 return if self.user.admin?
152 return if self.user.admin?
153
153
154 #check if user has the right to submit the problem
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?)
155 + errors.add('problem',"must be valid.") if (!self.user.available_problems.include?(self.problem)) and (self.new_record?)
156 end
156 end
157 end
157 end
158
158
159 # callbacks
159 # callbacks
160 def assign_latest_number_if_new_recond
160 def assign_latest_number_if_new_recond
161 return if !self.new_record?
161 return if !self.new_record?
162 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)
163 self.number = (latest==nil) ? 1 : latest.number + 1;
163 self.number = (latest==nil) ? 1 : latest.number + 1;
164 end
164 end
165
165
166 end
166 end
You need to be logged in to leave comments. Login now