|
|
|
@ -27,7 +27,7 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
accept_api_auth :show, :download, :upload
|
|
|
|
|
require 'iconv'
|
|
|
|
|
include AttachmentsHelper
|
|
|
|
|
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
respond_to do |format|
|
|
|
|
@ -65,36 +65,7 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
def download
|
|
|
|
|
# modify by nwb
|
|
|
|
|
# 下载添加权限设置
|
|
|
|
|
candown = false
|
|
|
|
|
if @attachment.container.class.to_s != "HomeworkAttach" && (@attachment.container.has_attribute?(:project) || @attachment.container.has_attribute?(:project_id)) && @attachment.container.project
|
|
|
|
|
project = @attachment.container.project
|
|
|
|
|
candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
|
|
|
|
|
elsif @attachment.container.is_a?(Project)
|
|
|
|
|
project = @attachment.container
|
|
|
|
|
candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
|
|
|
|
|
elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
|
|
|
|
|
@attachment.container.board.project
|
|
|
|
|
project = @attachment.container.board.project
|
|
|
|
|
candown = User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
|
|
|
|
|
elsif (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) && @attachment.container.course
|
|
|
|
|
course = @attachment.container.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) || (course.is_public==1 && @attachment.is_public == 1)
|
|
|
|
|
elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
|
|
|
|
|
@attachment.container.board.course
|
|
|
|
|
course = @attachment.container.board.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
|
|
|
|
|
elsif @attachment.container_type == "Bid" && @attachment.container && @attachment.container.courses.first
|
|
|
|
|
course = @attachment.container.courses.first
|
|
|
|
|
candown = User.current.member_of_course?(course) || (course.is_public == 1 && @attachment.is_public == 1)
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
candown = @attachment.is_public == 1
|
|
|
|
|
end
|
|
|
|
|
candown = attachment_candown @attachment
|
|
|
|
|
if candown || User.current.admin? || User.current.id == @attachment.author_id
|
|
|
|
|
@attachment.increment_download
|
|
|
|
|
if stale?(:etag => @attachment.digest)
|
|
|
|
|