Skip to content

Commit

Permalink
Merge pull request #374 from autolab/hotfix_tiny_fixes
Browse files Browse the repository at this point in the history
Small Fixes
  • Loading branch information
Yiming Zong committed Mar 8, 2015
2 parents 9ea569b + f0823d3 commit 2e7f949
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/controllers/assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
class AssessmentsController < ApplicationController
include ActiveSupport::Callbacks

autolabRequire File.join(Rails.root, 'app/controllers/assessment/handin.rb')
autolabRequire Rails.root.join("app", "controllers", "assessment", "handin.rb")
include AssessmentHandin

autolabRequire File.join(Rails.root, 'app/controllers/assessment/handout.rb')
autolabRequire Rails.root.join("app", "controllers", "assessment", "handout.rb")
include AssessmentHandout

autolabRequire File.join(Rails.root, 'app/controllers/assessment/grading.rb')
autolabRequire Rails.root.join("app", "controllers", "assessment", "grading.rb")
include AssessmentGrading

autolabRequire File.join(Rails.root, 'app/controllers/assessment/autograde.rb')
autolabRequire Rails.root.join("app", "controllers", "assessment", "autograde.rb")
include AssessmentAutograde

before_action :get_assessment, except: [ :index, :new, :create, :installQuiz, :installAssessment,
Expand Down Expand Up @@ -850,7 +850,7 @@ def edit

action_auth_level :update, :instructor
def update
flash[:success] = "Saved!" if @assessment.update(edit_assessment_params)
flash[:success] = "Saved!" if @assessment.update!(edit_assessment_params)

redirect_to action: :edit and return
end
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'archive.rb'
require 'pdf.rb'

class SubmissionsController < ApplicationController

Expand Down Expand Up @@ -240,6 +241,11 @@ def view
end
return unless file

filename = @submission.handin_file_path
if PDF.is_pdf?(file) then
send_data(file, type: "application/pdf", disposition: "inline", filename: File.basename(filename)) and return
end

begin
@data = @submission.annotated_file(file, @filename, params[:header_position])
rescue
Expand Down Expand Up @@ -298,7 +304,7 @@ def view
if params[:header_position] then
redirect_to [:list_archive, @course, @assessment, @submission] and return
else
redirect_to [:history, @course, @assessment] and return
redirect_to [:history, @course, @assessment, cud_id: @submission.course_user_datum_id] and return
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/course_user_datum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def can_sudo_to?(cud)
end

def student?
!(instructor? || course_assistant? || user.administrator?)
!(instructor? || course_assistant?)
end

def CA_of?(student)
Expand Down
10 changes: 10 additions & 0 deletions lib/pdf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module PDF
def self.is_pdf?(file)
return false unless file
# all PDFs have '%PDF-<major-version>.<minor-version>' in them somewhere.
# this is used instead of MIME type detection because it should work
# for PDFs inside of Archives as well.
# the scrub call prevents invalid byte sequence errors.
return (file.scrub("*") =~ /\%PDF-\d+\.?\d+/)
end
end

0 comments on commit 2e7f949

Please sign in to comment.