| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| app/controllers/results_controller.rb | 484 | 400 | 96.49%
|
96.00%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 class ResultsController < ApplicationController |
2 before_filter :authorize_only_for_admin, |
3 :except => [:codeviewer, |
4 :edit, |
5 :update_mark, |
6 :view_marks, |
7 :create, |
8 :add_extra_mark, :next_grouping, :update_overall_comment, :expand_criteria, |
9 :collapse_criteria, :remove_extra_mark, :expand_unmarked_criteria, :update_marking_state, |
10 :download, :note_message, :render_test_result, |
11 :update_overall_remark_comment, :update_remark_request, :cancel_remark_request] |
12 before_filter :authorize_for_ta_and_admin, :only => [:edit, :update_mark, :create, :add_extra_mark, |
13 :next_grouping, :update_overall_comment, :expand_criteria, |
14 :collapse_criteria, :remove_extra_mark, :expand_unmarked_criteria, |
15 :update_marking_state, :note_message, :update_overall_remark_comment] |
16 before_filter :authorize_for_user, :only => [:codeviewer, :render_test_result, :download] |
17 before_filter :authorize_for_student, :only => [:view_marks, :update_remark_request, :cancel_remark_request] |
18 |
19 def note_message |
20 @result = Result.find(params[:id]) |
21 if params[:success] |
22 flash[:note_success] = I18n.t('notes.success') |
23 else |
24 flash[:fail_notice] = I18n.t('notes.error') |
25 end |
26 end |
27 |
28 def edit |
29 result_id = params[:id] |
30 @result = Result.find(result_id) |
31 @assignment = @result.submission.assignment |
32 @submission = @result.submission |
33 |
34 @old_result = nil |
35 if @submission.remark_submitted? |
36 @old_result = @submission.result |
37 end |
38 |
39 @annotation_categories = @assignment.annotation_categories |
40 @grouping = @result.submission.grouping |
41 @group = @grouping.group |
42 @files = @submission.submission_files.sort do |a, b| |
43 File.join(a.path, a.filename) <=> File.join(b.path, b.filename) |
44 end |
45 @test_result_files = @submission.test_results |
46 @first_file = @files.first |
47 @extra_marks_points = @result.extra_marks.points |
48 @extra_marks_percentage = @result.extra_marks.percentage |
49 @marks_map = Hash.new |
50 @old_marks_map = Hash.new |
51 @mark_criteria = @assignment.get_criteria |
52 @assignment.get_criteria.each do |criterion| |
53 mark = criterion.marks.find_or_create_by_result_id(@result.id) |
54 mark.save(:validate => false) |
55 @marks_map[criterion.id] = mark |
56 |
57 if @old_result |
58 oldmark = criterion.marks.find_or_create_by_result_id(@old_result.id) |
59 oldmark.save(false) |
60 @old_marks_map[criterion.id] = oldmark |
61 end |
62 end |
63 |
64 # Get the previous and the next submission |
65 # FIXME right now, the groupings are ordered by grouping's id. Having a |
66 # more natural grouping order would be nice. |
67 if current_user.ta? |
68 groupings = @assignment.ta_memberships.find_all_by_user_id( |
69 current_user.id, |
70 :include => [:grouping => :group], |
71 :order => 'id ASC').collect do |m| |
72 m.grouping |
73 end |
74 elsif current_user.admin? |
75 groupings = @assignment.groupings.find( |
76 :all, |
77 :include => :group, |
78 :order => 'id ASC') |
79 end |
80 |
81 # If a grouping's submission's marking_status is complete, we're not going |
82 # to include them in the next_submission/prev_submission list |
83 |
84 # If a grouping doesn't have a submission, and we are past the collection time, |
85 # we *DO* want to include them in the list. |
86 collection_time = @assignment.submission_rule.calculate_collection_time.localtime |
87 |
88 groupings.delete_if do |grouping| |
89 grouping != @grouping && ((!grouping.has_submission? && (Time.now < collection_time))) |
90 end |
91 |
92 # We sort by Group name by default |
93 groupings = groupings.sort do |a, b| |
94 a.group.group_name <=> b.group.group_name |
95 end |
96 |
97 current_grouping_index = groupings.index(@grouping) |
98 if current_grouping_index.nil? |
99 @next_grouping = groupings.first |
100 @previous_grouping = groupings.last |
101 else |
102 if !groupings[current_grouping_index + 1].nil? |
103 @next_grouping = groupings[current_grouping_index + 1] |
104 end |
105 if (current_grouping_index - 1) >= 0 |
106 @previous_grouping = groupings[current_grouping_index - 1] |
107 end |
108 end |
109 m_logger = MarkusLogger.instance |
110 m_logger.log("User '#{current_user.user_name}' viewed submission (id: #{@submission.id})" + |
111 "of assignment '#{@assignment.short_identifier}' for group '" + |
112 "#{@group.group_name}'") |
113 |
114 end |
115 |
116 def next_grouping |
117 grouping = Grouping.find(params[:id]) |
118 if grouping.has_submission? && grouping.is_collected? && grouping.current_submission_used.remark_submitted? |
119 redirect_to :action => 'edit', |
120 :id => grouping.current_submission_used.remark_result.id |
121 elsif grouping.has_submission? && grouping.is_collected? |
122 redirect_to :action => 'edit', |
123 :id => grouping.current_submission_used.result.id |
124 else |
125 redirect_to :controller => 'submissions', |
126 :action => 'collect_and_begin_grading', |
127 :id => grouping.assignment.id, |
128 :grouping_id => grouping.id |
129 end |
130 end |
131 |
132 def set_released_to_students |
133 @result = Result.find(params[:id]) |
134 released_to_students = (params[:value] == 'true') |
135 if (params[:old_id]) |
136 @old_result = Result.find(params[:old_id]) |
137 @old_result.released_to_students = released_to_students |
138 @old_result.save |
139 end |
140 @result.released_to_students = released_to_students |
141 @result.save |
142 @result.submission.assignment.set_results_average |
143 m_logger = MarkusLogger.instance |
144 assignment = @result.submission.assignment |
145 if params[:value] == 'true' |
146 m_logger.log("Marks released for assignment '#{assignment.short_identifier}', ID: '" + |
147 "#{assignment.id}' (for 1 group).") |
148 else |
149 m_logger.log("Marks unreleased for assignment '#{assignment.short_identifier}', ID: '" + |
150 "#{assignment.id}' (for 1 group).") |
151 end |
152 end |
153 |
154 #Updates the marking state |
155 def update_marking_state |
156 @result = Result.find(params[:id]) |
157 @result.marking_state = params[:value] |
158 if @result.save |
159 # If marking_state is complete, update the cached distribution |
160 if params[:value] == Result::MARKING_STATES[:complete] |
161 @result.submission.assignment.assignment_stat.refresh_grade_distribution |
162 end |
163 render :template => "results/update_marking_state" |
164 else # Failed to pass validations |
165 # Show error message |
166 render :template => "results/marker/show_result_error" |
167 return |
168 end |
169 end |
170 |
171 def download |
172 #Ensure student doesn't download a file not submitted by his own grouping |
173 if !authorized_to_download?(params[:select_file_id]) |
174 render :file => "#{::Rails.root.to_s}/public/404.html", :status => 404 |
175 return |
176 end |
177 file = SubmissionFile.find(params[:select_file_id]) |
178 begin |
179 if params[:include_annotations] == 'true' && !file.is_supported_image? |
180 file_contents = file.retrieve_file(true) |
181 else |
182 file_contents = file.retrieve_file |
183 end |
184 rescue Exception => e |
185 flash[:file_download_error] = e.message |
186 redirect_to :action => 'edit', |
187 :assignment_id => params[:assignment_id], |
188 :submission_id => file.submission, |
189 :id => file.submission.result |
190 return |
191 end |
192 filename = file.filename |
193 #Display the file in the page if it is an image/pdf, and download button |
194 #was not explicitly pressed |
195 if file.is_supported_image? && !params[:show_in_browser].nil? |
196 send_data file_contents, :type => "image", :disposition => 'inline', |
197 :filename => filename |
198 elsif file.is_pdf? && !params[:show_in_browser].nil? |
199 send_file File.join(MarkusConfigurator.markus_config_pdf_storage, |
200 file.submission.grouping.group.repository_name, file.path, |
201 filename.split('.')[0] + '.jpg'), :type => "image", |
202 :disposition => 'inline', :filename => filename |
203 else |
204 send_data file_contents, :filename => filename |
205 end |
206 end |
207 |
208 def codeviewer |
209 @assignment = Assignment.find(params[:assignment_id]) |
210 @submission_file_id = params[:submission_file_id] |
211 @focus_line = params[:focus_line] |
212 |
213 @file = SubmissionFile.find(@submission_file_id) |
214 @result = @file.submission.result |
215 # Is the current user a student? |
216 if current_user.student? |
217 # The Student does not have access to this file. Display an error. |
218 if @file.submission.grouping.membership_status(current_user).nil? |
219 render :partial => 'shared/handle_error', |
220 :locals => {:error => I18n.t('submission_file.error.no_access', |
221 :submission_file_id => @submission_file_id)} |
222 return |
223 end |
224 end |
225 |
226 @annots = @file.annotations |
227 @all_annots = @file.submission.annotations |
228 |
229 begin |
230 @file_contents = @file.retrieve_file |
231 rescue Exception => e |
232 render :partial => 'shared/handle_error', |
233 :locals => {:error => e.message} |
234 return |
235 end |
236 @code_type = @file.get_file_type |
237 render :template => 'results/common/codeviewer' |
238 end |
239 |
240 #=== Description |
241 # Action called via Rails' remote_function from the test_result_window partial |
242 # Prepares test result and updates content in window. |
243 def render_test_result |
244 @assignment = Assignment.find(params[:assignment_id]) |
245 @test_result = TestResult.find(params[:test_result_id]) |
246 |
247 # Students can use this action only, when marks have been released |
248 if current_user.student? && |
249 (@test_result.submission.grouping.membership_status(current_user).nil? || |
250 @test_result.submission.result.released_to_students == false) |
251 render :partial => 'shared/handle_error', |
252 :locals => {:error => I18n.t('test_result.error.no_access', :test_result_id => @test_result.id)} |
253 return |
254 end |
255 |
256 render :template => 'results/render_test_result', :layout => "plain" |
257 end |
258 |
259 def update_mark |
260 result_mark = Mark.find(params[:mark_id]) |
261 result_mark.mark = params[:mark] |
262 submission = result_mark.result.submission # get submission for logging |
263 group = submission.grouping.group # get group for logging |
264 assignment = submission.grouping.assignment # get assignment for logging |
265 m_logger = MarkusLogger.instance |
266 |
267 # FIXME checking both that result_mark is valid and correctly saved is |
268 # useless. The validation is done automatically before saving unless |
269 # specified otherwise. |
270 if !result_mark.valid? |
271 render :partial => 'results/marker/mark_verify_result', |
272 :locals => {:mark_id => result_mark.id, |
273 :mark_error => result_mark.errors.full_messages.join} |
274 else |
275 if !result_mark.save |
276 m_logger.log("Error while trying to update mark of submission. User: '" + |
277 "#{current_user.user_name}', Submission ID: '#{submission.id}'," + |
278 " Assignment: '#{assignment.short_identifier}', Group: '#{group.group_name}'.", |
279 MarkusLogger::ERROR) |
280 render :partial => 'shared/handle_error', |
281 :locals => {:error => I18n.t('mark.error.save') + result_mark.errors.full_messages.join} |
282 else |
283 m_logger.log("User '#{current_user.user_name}' updated mark for submission (id: " + |
284 "#{submission.id}) of assignment '#{assignment.short_identifier}' for group" + |
285 " '#{group.group_name}'.", MarkusLogger::INFO) |
286 render :partial => 'results/marker/update_mark', |
287 :locals => { :result_mark => result_mark, :mark_value => result_mark.mark} |
288 end |
289 end |
290 end |
291 |
292 def view_marks |
293 @assignment = Assignment.find(params[:assignment_id]) |
294 @grouping = current_user.accepted_grouping_for(@assignment.id) |
295 |
296 if @grouping.nil? |
297 redirect_to :controller => 'assignments', |
298 :action => 'student_interface', |
299 :id => params[:id] |
300 return |
301 end |
302 if !@grouping.has_submission? |
303 render 'results/student/no_submission' |
304 return |
305 end |
306 @submission = @grouping.current_submission_used |
307 if !@submission.has_result? |
308 render 'results/student/no_result' |
309 return |
310 end |
311 |
312 @result = @submission.result |
313 @old_result = nil |
314 if @submission.remark_submitted? |
315 @old_result = @result |
316 @result = @submission.remark_result |
317 # if remark result's marking state is 'unmarked' then the student has |
318 # saved a remark request but not submitted it yet, therefore, still editable |
319 if (@result.marking_state != Result::MARKING_STATES[:unmarked] && !@result.released_to_students) |
320 render 'results/student/no_remark_result' |
321 return |
322 end |
323 end |
324 |
325 if !@result.released_to_students |
326 render 'results/student/no_result' |
327 return |
328 end |
329 |
330 @annotation_categories = @assignment.annotation_categories |
331 @group = @grouping.group |
332 @files = @submission.submission_files |
333 @test_result_files = @submission.test_results |
334 @first_file = @files.first |
335 @extra_marks_points = @result.extra_marks.points |
336 @extra_marks_percentage = @result.extra_marks.percentage |
337 @marks_map = Hash.new |
338 @old_marks_map = Hash.new |
339 @mark_criteria = @assignment.get_criteria |
340 @assignment.get_criteria.each do |criterion| |
341 mark = criterion.marks.find_or_create_by_result_id(@result.id) |
342 mark.save(:validate => false) |
343 @marks_map[criterion.id] = mark |
344 |
345 if @old_result |
346 oldmark = criterion.marks.find_or_create_by_result_id(@old_result.id) |
347 oldmark.save(false) |
348 @old_marks_map[criterion.id] = oldmark |
349 end |
350 end |
351 m_logger = MarkusLogger.instance |
352 m_logger.log("Student '#{current_user.user_name}' viewed results for assignment " + |
353 "'#{@assignment.short_identifier}'.") |
354 end |
355 |
356 def add_extra_mark |
357 @result = Result.find(params[:id]) |
358 if request.post? |
359 @extra_mark = ExtraMark.new |
360 @extra_mark.result = @result |
361 @extra_mark.unit = ExtraMark::UNITS[:points] |
362 if !@extra_mark.update_attributes(params[:extra_mark]) |
363 render :template => 'results/marker/add_extra_mark_error' |
364 else |
365 # need to re-calculate total mark |
366 @result.update_total_mark |
367 render :template => 'results/marker/insert_extra_mark' |
368 end |
369 return |
370 end |
371 render :template => 'results/marker/add_extra_mark' |
372 end |
373 |
374 #Deletes an extra mark from the database and removes it from the html |
375 def remove_extra_mark |
376 #find the extra mark and destroy it |
377 @extra_mark = ExtraMark.find(params[:id]) |
378 @extra_mark.destroy |
379 #need to recalculate total mark |
380 @result = @extra_mark.result |
381 @result.update_total_mark |
382 render :template => 'results/marker/remove_extra_mark' |
383 end |
384 |
385 def update_overall_comment |
386 @result = Result.find(params[:id]) |
387 @result.overall_comment = params[:result][:overall_comment] |
388 @result.save |
389 end |
390 |
391 def update_overall_remark_comment |
392 @result = Result.find(params[:id]) |
393 @result.overall_comment = params[:result][:overall_comment] |
394 @result.save |
395 end |
396 |
397 def update_remark_request |
398 @assignment = Assignment.find(params[:assignment_id]) |
399 if !@assignment.past_remark_due_date? |
400 @submission = Submission.find(params[:id]) |
401 @submission.remark_request = params[:submission][:remark_request] |
402 @submission.remark_request_timestamp = Time.now |
403 @submission.save |
404 @old_result = @submission.result |
405 if !(@submission.remark_result) |
406 @submission.create_remark_result_object |
407 end |
408 if (params[:real_commit] == "Submit") |
409 @result = @submission.remark_result |
410 @result.marking_state = Result::MARKING_STATES[:partial] |
411 @old_result.released_to_students = (params[:value] == 'false') |
412 @result.save |
413 @old_result.save |
414 end |
415 end |
416 end |
417 |
418 def cancel_remark_request |
419 @submission = Submission.find(params[:submission_id]) |
420 |
421 @remark_result = @submission.remark_result |
422 @remark_result.submission_id = nil |
423 @remark_result.save |
424 |
425 @submission.remark_result_id = nil |
426 @submission.remark_request = nil |
427 @submission.save |
428 |
429 @result = @submission.result |
430 @result.released_to_students = true |
431 @result.save |
432 |
433 redirect_to :controller => 'results', |
434 :action => 'view_marks', |
435 :id => params[:id] |
436 end |
437 |
438 def expand_criteria |
439 @assignment = Assignment.find(params[:assignment_id]) |
440 @mark_criteria = @assignment.get_criteria |
441 render :partial => 'results/marker/expand_criteria', |
442 :locals => {:mark_criteria => @mark_criteria} |
443 end |
444 |
445 def collapse_criteria |
446 @assignment = Assignment.find(params[:assignment_id]) |
447 @mark_criteria = @assignment.get_criteria |
448 render :partial => 'results/marker/collapse_criteria', :locals => {:mark_criteria => @mark_criteria} |
449 end |
450 |
451 def expand_unmarked_criteria |
452 @assignment = Assignment.find(params[:assignment_id]) |
453 @result = Result.find(params[:id]) |
454 # nil_marks are the marks that have a "nil" value for Mark.mark - so they're |
455 # unmarked. |
456 @nil_marks = @result.marks.all(:conditions => {:mark => nil}) |
457 render :partial => 'results/marker/expand_unmarked_criteria', :locals => {:nil_marks => @nil_marks} |
458 end |
459 |
460 def delete_grace_period_deduction |
461 @grouping = Grouping.find(params[:id]) |
462 grace_deduction = GracePeriodDeduction.find(params[:deduction_id]) |
463 grace_deduction.destroy |
464 end |
465 |
466 private |
467 |
468 |
469 #Return true if select_file_id matches the id of a file submitted by the |
470 #current_user. This is to prevent students from downloading files that they |
471 #or their group have not submitted. Return false otherwise. |
472 def authorized_to_download?(select_file_id) |
473 #If the user is a ta or admin, return true as they are authorized. |
474 if current_user.admin? || current_user.ta? |
475 return true |
476 end |
477 sub_file = SubmissionFile.find_by_id(select_file_id) |
478 if !sub_file.nil? |
479 #Check that current_user is in fact in grouping that sub_file belongs to |
480 return !sub_file.submission.grouping.accepted_students.find(current_user).nil? |
481 end |
482 return false |
483 end |
484 end |
Generated on Tue Feb 07 00:07:35 -0500 2012 with rcov 0.9.10