Skip to content

Commit 7455432

Browse files
ryankshawcodekitchen
authored andcommitted
fix so google docs can preview an attachment
google docs' servers would get a 500 error when they tried to access the authenticated_s3_url of a submission Change-Id: I54fd133a3db15b60a6b4128a3b2ff65f1e5a2204 fixes: #5551 Reviewed-on: https://gerrit.instructure.com/5485 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
1 parent 53b731a commit 7455432

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

app/controllers/files_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def show
170170
@skip_crumb = true
171171
end
172172
params[:download] ||= params[:preview]
173-
@context = UserProfile.new(@context) if @context == @current_user
173+
@context = UserProfile.new(@context) if (@context == @current_user) && @current_user
174174
add_crumb(t('#crumbs.files', "Files"), named_context_url(@context, :context_files_url)) unless @skip_crumb
175175
if @attachment.deleted?
176176
# before telling them it's deleted, try to find another active attachment with the same full path

spec/integration/files_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@
6363
# ensure that the user wasn't logged in by the normal means
6464
controller.instance_variable_get(:@current_user).should be_nil
6565
end
66+
67+
it "should allow access to non-logged-in user agent if it has the right :verifier (lets google docs preview submissions in speedGrader)" do
68+
submission_model
69+
@submission.attachment = attachment_model(:uploaded_data => stub_png_data, :content_type => 'image/png')
70+
@submission.save!
71+
HostUrl.stub!(:file_host).and_return('files-test.host')
72+
get "http://test.host/users/#{@submission.user.id}/files/#{@submission.attachment.id}/download", :verifier => @submission.attachment.uuid
73+
74+
response.should be_redirect
75+
uri = URI.parse response['Location']
76+
qs = Rack::Utils.parse_nested_query(uri.query)
77+
uri.host.should == 'files-test.host'
78+
uri.path.should == "/files/#{@submission.attachment.id}/download"
79+
qs['verifier'].should == @submission.attachment.uuid
80+
location = response['Location']
81+
reset!
82+
83+
get location
84+
response.should be_success
85+
response.content_type.should == 'image/png'
86+
controller.instance_variable_get(:@current_user).should be_nil
87+
controller.instance_variable_get(:@context).should be_nil
88+
end
6689

6790
it "shouldn't use relative urls for safefiles in other contexts" do
6891
course_with_teacher_logged_in(:active_all => true)

0 commit comments

Comments
 (0)