From f4d6696d2e1521aed5c888567c90e38af8fa0fd0 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 17 Jul 2014 16:06:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B5=84=E6=BA=90=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 23 ++++++++++++----------- app/controllers/stores_controller.rb | 2 +- app/helpers/stores_helper.rb | 2 ++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b283b4792..8058f0803 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -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 diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index f34e72402..ae9336161 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -38,7 +38,7 @@ class StoresController < ApplicationController LIMIT = 12 unless const_defined?(:LIMIT) def index @projects_attach = project_classification(0).take(LIMIT) - @courses_attach = Attachment.includes(:course).where("courses.is_public = ?", 1). + @courses_attach = Attachment.includes(:course).where("courses.is_public = 1"). where(container_type: 'Course'). limit(LIMIT) # @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1). diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb index 0c7fdac43..b4cd47eb1 100644 --- a/app/helpers/stores_helper.rb +++ b/app/helpers/stores_helper.rb @@ -16,6 +16,8 @@ module StoresHelper news_path(container) when 'Project' project_files_path(container) + when 'Course' + course_files_path(container) when 'Version' # version_path(container) project_files_path(container.project)