Description:
prevents user from viewing own sources submitted to unavailable problems
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r305:a5e98b239050 - - 1 file changed: 3 inserted, 1 deleted
@@ -44,97 +44,99 | |||||
|
44 | # end |
|
44 | # end |
|
45 |
|
45 | ||
|
46 | @announcements = Announcement.find_for_frontpage |
|
46 | @announcements = Announcement.find_for_frontpage |
|
47 | render :action => 'login', :layout => 'empty' |
|
47 | render :action => 'login', :layout => 'empty' |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | def list |
|
50 | def list |
|
51 | prepare_list_information |
|
51 | prepare_list_information |
|
52 | end |
|
52 | end |
|
53 |
|
53 | ||
|
54 | def help |
|
54 | def help |
|
55 | @user = User.find(session[:user_id]) |
|
55 | @user = User.find(session[:user_id]) |
|
56 | end |
|
56 | end |
|
57 |
|
57 | ||
|
58 | def submit |
|
58 | def submit |
|
59 | user = User.find(session[:user_id]) |
|
59 | user = User.find(session[:user_id]) |
|
60 |
|
60 | ||
|
61 | @submission = Submission.new(params[:submission]) |
|
61 | @submission = Submission.new(params[:submission]) |
|
62 | @submission.user = user |
|
62 | @submission.user = user |
|
63 | @submission.language_id = 0 |
|
63 | @submission.language_id = 0 |
|
64 | if (params['file']) and (params['file']!='') |
|
64 | if (params['file']) and (params['file']!='') |
|
65 | @submission.source = params['file'].read |
|
65 | @submission.source = params['file'].read |
|
66 | @submission.source_filename = params['file'].original_filename |
|
66 | @submission.source_filename = params['file'].original_filename |
|
67 | end |
|
67 | end |
|
68 | @submission.submitted_at = Time.new.gmtime |
|
68 | @submission.submitted_at = Time.new.gmtime |
|
69 |
|
69 | ||
|
70 | if Configuration.time_limit_mode? and user.contest_finished? |
|
70 | if Configuration.time_limit_mode? and user.contest_finished? |
|
71 | @submission.errors.add_to_base "The contest is over." |
|
71 | @submission.errors.add_to_base "The contest is over." |
|
72 | prepare_list_information |
|
72 | prepare_list_information |
|
73 | render :action => 'list' and return |
|
73 | render :action => 'list' and return |
|
74 | end |
|
74 | end |
|
75 |
|
75 | ||
|
76 | if @submission.valid? |
|
76 | if @submission.valid? |
|
77 | if @submission.save == false |
|
77 | if @submission.save == false |
|
78 | flash[:notice] = 'Error saving your submission' |
|
78 | flash[:notice] = 'Error saving your submission' |
|
79 | elsif Task.create(:submission_id => @submission.id, |
|
79 | elsif Task.create(:submission_id => @submission.id, |
|
80 | :status => Task::STATUS_INQUEUE) == false |
|
80 | :status => Task::STATUS_INQUEUE) == false |
|
81 | flash[:notice] = 'Error adding your submission to task queue' |
|
81 | flash[:notice] = 'Error adding your submission to task queue' |
|
82 | end |
|
82 | end |
|
83 | else |
|
83 | else |
|
84 | prepare_list_information |
|
84 | prepare_list_information |
|
85 | render :action => 'list' and return |
|
85 | render :action => 'list' and return |
|
86 | end |
|
86 | end |
|
87 | redirect_to :action => 'list' |
|
87 | redirect_to :action => 'list' |
|
88 | end |
|
88 | end |
|
89 |
|
89 | ||
|
90 | def source |
|
90 | def source |
|
91 | submission = Submission.find(params[:id]) |
|
91 | submission = Submission.find(params[:id]) |
|
92 | - if submission.user_id == session[:user_id] |
|
92 | + if ((submission.user_id == session[:user_id]) and |
|
|
93 | + (submission.problem != nil) and | ||
|
|
94 | + (submission.problem.available)) | ||
|
93 | send_data(submission.source, |
|
95 | send_data(submission.source, |
|
94 | {:filename => submission.download_filename, |
|
96 | {:filename => submission.download_filename, |
|
95 | :type => 'text/plain'}) |
|
97 | :type => 'text/plain'}) |
|
96 | else |
|
98 | else |
|
97 | flash[:notice] = 'Error viewing source' |
|
99 | flash[:notice] = 'Error viewing source' |
|
98 | redirect_to :action => 'list' |
|
100 | redirect_to :action => 'list' |
|
99 | end |
|
101 | end |
|
100 | end |
|
102 | end |
|
101 |
|
103 | ||
|
102 | def compiler_msg |
|
104 | def compiler_msg |
|
103 | @submission = Submission.find(params[:id]) |
|
105 | @submission = Submission.find(params[:id]) |
|
104 | if @submission.user_id == session[:user_id] |
|
106 | if @submission.user_id == session[:user_id] |
|
105 | render :action => 'compiler_msg', :layout => 'empty' |
|
107 | render :action => 'compiler_msg', :layout => 'empty' |
|
106 | else |
|
108 | else |
|
107 | flash[:notice] = 'Error viewing source' |
|
109 | flash[:notice] = 'Error viewing source' |
|
108 | redirect_to :action => 'list' |
|
110 | redirect_to :action => 'list' |
|
109 | end |
|
111 | end |
|
110 | end |
|
112 | end |
|
111 |
|
113 | ||
|
112 | def submission |
|
114 | def submission |
|
113 | @user = User.find(session[:user_id]) |
|
115 | @user = User.find(session[:user_id]) |
|
114 | @problems = @user.available_problems |
|
116 | @problems = @user.available_problems |
|
115 | if params[:id]==nil |
|
117 | if params[:id]==nil |
|
116 | @problem = nil |
|
118 | @problem = nil |
|
117 | @submissions = nil |
|
119 | @submissions = nil |
|
118 | else |
|
120 | else |
|
119 | @problem = Problem.find_by_name(params[:id]) |
|
121 | @problem = Problem.find_by_name(params[:id]) |
|
120 | if not @problem.available |
|
122 | if not @problem.available |
|
121 | redirect_to :action => 'list' |
|
123 | redirect_to :action => 'list' |
|
122 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
124 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
123 | return |
|
125 | return |
|
124 | end |
|
126 | end |
|
125 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
127 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
126 | end |
|
128 | end |
|
127 | end |
|
129 | end |
|
128 |
|
130 | ||
|
129 | def result |
|
131 | def result |
|
130 | if !Configuration.show_grading_result |
|
132 | if !Configuration.show_grading_result |
|
131 | redirect_to :action => 'list' and return |
|
133 | redirect_to :action => 'list' and return |
|
132 | end |
|
134 | end |
|
133 | @user = User.find(session[:user_id]) |
|
135 | @user = User.find(session[:user_id]) |
|
134 | @submission = Submission.find(params[:id]) |
|
136 | @submission = Submission.find(params[:id]) |
|
135 | if @submission.user!=@user |
|
137 | if @submission.user!=@user |
|
136 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
138 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
137 | redirect_to :action => 'list' and return |
|
139 | redirect_to :action => 'list' and return |
|
138 | end |
|
140 | end |
|
139 | prepare_grading_result(@submission) |
|
141 | prepare_grading_result(@submission) |
|
140 | end |
|
142 | end |
You need to be logged in to leave comments.
Login now