Merge branch 'szzh' into develop

This commit is contained in:
sw 2014-12-12 16:54:37 +08:00
commit 520597b065
3 changed files with 45 additions and 7 deletions

View File

@ -87,8 +87,9 @@ class AttachmentsController < ApplicationController
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) 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 elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3
candown = true candown = true
elsif @attachment.container_type == "Bid" && @attachment.container && @attachment.container.courses elsif @attachment.container_type == "Bid" && @attachment.container && @attachment.container.courses.first
candown = User.current.member_of_course?(@attachment.container.courses.first) || (course.is_public == 1 && @attachment.is_public == 1) course = @attachment.container.courses.first
candown = User.current.member_of_course?(course) || (course.is_public == 1 && @attachment.is_public == 1)
else else
candown = @attachment.is_public == 1 candown = @attachment.is_public == 1
@ -203,7 +204,11 @@ class AttachmentsController < ApplicationController
if @attachment.container.respond_to?(:init_journal) if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current) @attachment.container.init_journal(User.current)
end end
if @attachment.container
@attachment.container.attachments.delete(@attachment)
else
@attachment.destroy @attachment.destroy
end
respond_to do |format| respond_to do |format|
if !@attachment.container.nil? && if !@attachment.container.nil? &&

View File

@ -71,9 +71,9 @@ class FilesController < ApplicationController
@searched_attach = paginateHelper @result,10 @searched_attach = paginateHelper @result,10
end end
rescue Exception => e #rescue Exception => e
#render 'stores' # #render 'stores'
redirect_to stores_url # redirect_to search_course_files_url
end end
end end

View File

@ -107,13 +107,46 @@ module FilesHelper
def visable_attachemnts_insite attachments,course def visable_attachemnts_insite attachments,course
result = [] result = []
attachments.each do |attachment| attachments.each do |attachment|
if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == course.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id if attachment_candown(attachment) || (attachment.container_type == "Course" && attachment.container_id == course.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id
result << attachment result << attachment
end end
end end
result result
end end
def attachment_candown attachment
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
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
candown
end
end end