From 595f6805f95d179944cd3609b8bc284ee950d4f1 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 12 Dec 2014 16:28:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E6=98=AF=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index ecf6fe049..34dfca75f 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -203,7 +203,11 @@ class AttachmentsController < ApplicationController if @attachment.container.respond_to?(:init_journal) @attachment.container.init_journal(User.current) end - @attachment.destroy + if @attachment.container + @attachment.container.attachments.delete(@attachment) + else + @attachment.destroy + end respond_to do |format| if !@attachment.container.nil? && From 363e6812549a815f2f2da19317febd6a8dd8156a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 12 Dec 2014 16:52:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=87=BA=E9=94=99=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 34dfca75f..952dcdf44 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -87,8 +87,9 @@ class AttachmentsController < ApplicationController 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 - candown = User.current.member_of_course?(@attachment.container.courses.first) || (course.is_public == 1 && @attachment.is_public == 1) + 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 From c0a0c41e14f3ed95a2c81c3dc5922be9c36962d2 Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 12 Dec 2014 16:53:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=A7=81=E6=9C=89=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E5=85=AC=E5=BC=80=E8=B5=84=E6=BA=90=E8=83=BD=E4=B8=8B?= =?UTF-8?q?=E8=BD=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 6 ++--- app/helpers/files_helper.rb | 35 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 41518e2f1..2f33ab554 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -71,9 +71,9 @@ class FilesController < ApplicationController @searched_attach = paginateHelper @result,10 end - rescue Exception => e - #render 'stores' - redirect_to stores_url + #rescue Exception => e + # #render 'stores' + # redirect_to search_course_files_url end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 2cd6b4400..2ec7e6f45 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -107,13 +107,46 @@ module FilesHelper def visable_attachemnts_insite attachments,course result = [] 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 end end result 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 \ No newline at end of file