将attachment_candown方法提取到application_help里面
This commit is contained in:
parent
43af61d684
commit
c4e9321e14
|
@ -27,7 +27,7 @@ class AttachmentsController < ApplicationController
|
||||||
accept_api_auth :show, :download, :upload
|
accept_api_auth :show, :download, :upload
|
||||||
require 'iconv'
|
require 'iconv'
|
||||||
include AttachmentsHelper
|
include AttachmentsHelper
|
||||||
|
include ApplicationHelper
|
||||||
|
|
||||||
def show
|
def show
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -65,36 +65,7 @@ class AttachmentsController < ApplicationController
|
||||||
def download
|
def download
|
||||||
# modify by nwb
|
# modify by nwb
|
||||||
# 下载添加权限设置
|
# 下载添加权限设置
|
||||||
candown = false
|
candown = attachment_candown @attachment
|
||||||
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
|
|
||||||
if candown || User.current.admin? || User.current.id == @attachment.author_id
|
if candown || User.current.admin? || User.current.id == @attachment.author_id
|
||||||
@attachment.increment_download
|
@attachment.increment_download
|
||||||
if stale?(:etag => @attachment.digest)
|
if stale?(:etag => @attachment.digest)
|
||||||
|
|
|
@ -30,6 +30,7 @@ class FilesController < ApplicationController
|
||||||
include FilesHelper
|
include FilesHelper
|
||||||
helper :project_score
|
helper :project_score
|
||||||
include CoursesHelper
|
include CoursesHelper
|
||||||
|
include ApplicationHelper
|
||||||
|
|
||||||
def show_attachments obj
|
def show_attachments obj
|
||||||
@attachments = []
|
@attachments = []
|
||||||
|
|
|
@ -1676,6 +1676,42 @@ module ApplicationHelper
|
||||||
courses_doing
|
courses_doing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def attachment_candown attachment
|
||||||
|
candown = false
|
||||||
|
if attachment.container
|
||||||
|
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
|
||||||
|
course = attachment.container.courses.first
|
||||||
|
candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1)
|
||||||
|
else
|
||||||
|
candown = (attachment.is_public == 1 || attachment.is_public == true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
candown
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def wiki_helper
|
def wiki_helper
|
||||||
|
|
|
@ -118,41 +118,6 @@ module FilesHelper
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachment_candown attachment
|
|
||||||
candown = false
|
|
||||||
if attachment.container
|
|
||||||
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
|
|
||||||
course = attachment.container.courses.first
|
|
||||||
candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1)
|
|
||||||
else
|
|
||||||
candown = (attachment.is_public == 1 || attachment.is_public == true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
candown
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
|
@ -21,7 +21,7 @@
|
||||||
<%= link_to_attachment file, :download => true,:text => truncate(file.filename,length: 35, omission: '...'), :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
|
<%= link_to_attachment file, :download => true,:text => truncate(file.filename,length: 35, omission: '...'), :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
|
||||||
<% if User.current.logged? %>
|
<% if User.current.logged? %>
|
||||||
<% if (manage_allowed || file.author_id == User.current.id) && project_contains_attachment?(project,file) %>
|
<% if (manage_allowed || file.author_id == User.current.id) && project_contains_attachment?(project,file) %>
|
||||||
<%= link_to(l(:label_slected_to_other_project),quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %>
|
<%= link_to(l(:label_slected_to_other_project),quote_resource_show_course_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %>
|
||||||
|
|
||||||
<% if manage_allowed && file.container_id == project.id && file.container_type == "Project" %>
|
<% if manage_allowed && file.container_id == project.id && file.container_type == "Project" %>
|
||||||
<span id="is_public_<%= file.id %>">
|
<span id="is_public_<%= file.id %>">
|
||||||
|
|
Loading…
Reference in New Issue