From c34127f21f73794ae38e44dabc40c8bef7603452 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 30 Dec 2015 18:04:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=99=90=E5=88=B6=E5=8A=A0=E5=A4=A7=20=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9C=89=E4=BA=86=E5=8E=86=E5=8F=B2=E7=89=88?= =?UTF-8?q?=E6=9C=AC=20=E6=95=B0=E6=8D=AE=E8=AE=B0=E5=BD=95=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E8=A2=AB=E5=88=A0=E9=99=A4=20=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=A2=AB=E5=8F=91=E9=80=81=E8=BF=87=EF=BC=8C?= =?UTF-8?q?=E6=88=96=E8=80=85=E6=9C=89=E4=BA=86=E5=8E=86=E5=8F=B2=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E7=A1=AC=E7=9B=98=E4=B8=8A=E7=9A=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=92=8C=E6=95=B0=E6=8D=AE=E8=AE=B0=E5=BD=95=E5=B0=B1?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=A2=AB=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 7 ++++++- app/views/files/_course_list.html.erb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ae23428f1..b6253de7a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -349,11 +349,16 @@ class Attachment < ActiveRecord::Base # Deletes the file from the file system if it's not referenced by other attachments def delete_from_disk - if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? + #资源存在,且历史记录为0 且 该资源没有存在任何拷贝才能删除资源 + if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0 && Attachment.where('copy_from = ?',self.id) .count == 0 delete_from_disk! end end + def destroyable + Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0 && Attachment.where('copy_from = ?',self.id) .count == 0 + end + # Returns file's location on disk def diskfile File.join(self.class.storage_path, disk_directory.to_s, disk_filename.to_s) diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 653877260..e2d321b51 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -52,7 +52,7 @@ <%end%>
  • <%= link_to( '删除资源', attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course"%> + :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %>
  • <% end %>