Skip to content

Commit 8ac7387

Browse files
committed
Fix permission of viewing submission
1 parent b40f88e commit 8ac7387

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

app/controllers/submissions_controller.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class SubmissionsController < ApplicationController
66
before_action :set_submission, only: [:rejudge, :show, :edit, :update, :destroy]
77
before_action :set_compiler, only: [:new, :create, :edit, :update]
88
before_action :check_compiler, only: [:create, :update]
9-
before_action :set_problem, only: [:show]
109
before_action :set_show_detail, only: [:show]
1110
layout :set_contest_layout, only: [:show, :index, :new, :edit]
1211
helper_method :td_list_to_arr
@@ -167,7 +166,7 @@ def set_submissions
167166
if @problem
168167
unless current_user&.admin
169168
if @problem.visible_contest?
170-
if params[:contest_id].blank? or not (@contest.problem_ids.include?(@problem.id) and Time.now >= @contest.start_time and Time.now <= @contest.end_time)
169+
if params[:contest_id].blank? or not (@contest.problem_ids.include?(@problem.id) and Time.now >= @contest.start_time)
171170
redirect_back fallback_location: root_path, :notice => 'Insufficient User Permissions.'
172171
end
173172
elsif @problem.visible_invisible?
@@ -214,7 +213,15 @@ def set_submissions
214213

215214
def set_submission
216215
@submission = Submission.find(params[:id])
216+
@problem = @submission.problem
217217
@contest = @submission.contest
218+
unless current_user&.admin
219+
if @problem.visible_contest?
220+
raise_not_found if not @contest
221+
elsif @problem.visible_invisible?
222+
raise_not_found
223+
end
224+
end
218225
if @contest
219226
raise_not_found if params[:contest_id] && @contest.id != params[:contest_id].to_i
220227
unless current_user&.admin?
@@ -226,10 +233,6 @@ def set_submission
226233
end
227234
end
228235

229-
def set_problem
230-
@problem = @submission.problem
231-
end
232-
233236
def set_show_detail
234237
@show_detail = current_user&.admin? || @contest.blank? || @contest.show_detail_result? || Time.now > @contest.end_time
235238
end

0 commit comments

Comments
 (0)