|
|
|
@ -55,32 +55,33 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
candown = false
|
|
|
|
|
if @attachment.container.has_attribute?(:project) && @attachment.container.project
|
|
|
|
|
project = @attachment.container.project
|
|
|
|
|
candown= User.current.member_of?(project)
|
|
|
|
|
candown= User.current.member_of?(project) || (project.is_public==1 && @attachment.is_public == 1)
|
|
|
|
|
elsif @attachment.container.is_a?(Project)
|
|
|
|
|
project = @attachment.container
|
|
|
|
|
candown= User.current.member_of?(project)
|
|
|
|
|
candown= User.current.member_of?(project) || (project.is_public==1 && @attachment.is_public == 1)
|
|
|
|
|
elsif @attachment.container.has_attribute?(:course) && @attachment.container.course
|
|
|
|
|
course = @attachment.container.course
|
|
|
|
|
candown= User.current.member_of_course?(course)
|
|
|
|
|
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
|
|
|
|
|
elsif @attachment.container.is_a?(Course)
|
|
|
|
|
course = @attachment.container
|
|
|
|
|
candown= User.current.member_of_course?(course)
|
|
|
|
|
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
|
|
|
|
|
elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3
|
|
|
|
|
candown = true
|
|
|
|
|
end
|
|
|
|
|
if candown || User.current.admin?
|
|
|
|
|
@attachment.increment_download
|
|
|
|
|
|
|
|
|
|
if stale?(:etag => @attachment.digest)
|
|
|
|
|
# images are sent inline
|
|
|
|
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
|
|
|
|
:type => detect_content_type(@attachment),
|
|
|
|
|
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
render_403 :message => :notice_not_authorized
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if stale?(:etag => @attachment.digest)
|
|
|
|
|
# images are sent inline
|
|
|
|
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
|
|
|
|
:type => detect_content_type(@attachment),
|
|
|
|
|
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
|
|
|
|
end
|
|
|
|
|
rescue => e
|
|
|
|
|
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
|
|
|
|
|
end
|
|
|
|
|