文件的删除限制加大
如果文件有了历史版本 数据记录不能被删除 如果文件被发送过,或者有了历史版本,硬盘上的文件和数据记录就不能被删除
This commit is contained in:
parent
0ef0045941
commit
c34127f21f
|
@ -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)
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<%end%>
|
||||
<li>
|
||||
<%= 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 %>
|
||||
</li>
|
||||
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue