文件的删除限制加大

如果文件有了历史版本 数据记录不能被删除
如果文件被发送过,或者有了历史版本,硬盘上的文件和数据记录就不能被删除
This commit is contained in:
lizanle 2015-12-30 18:24:07 +08:00
parent c34127f21f
commit a85a3339bb
3 changed files with 12 additions and 2 deletions

View File

@ -355,8 +355,9 @@ class Attachment < ActiveRecord::Base
end end
end end
#有了历史记录的数据记录是不能被删除的。
def destroyable 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 Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0
end end
# Returns file's location on disk # Returns file's location on disk

View File

@ -7,7 +7,7 @@
<% attachments.each do |attach| %> <% attachments.each do |attach| %>
<ul class="resourcesList" onmouseover="if($('#contextMenu').css('display') != 'block')$(this).children().css('background-color', '#e1e1e1')" onmouseout=" if($('#contextMenu').css('display') == 'none')$(this).children().css('background-color', 'white')"> <ul class="resourcesList" onmouseover="if($('#contextMenu').css('display') != 'block')$(this).children().css('background-color', '#e1e1e1')" onmouseout=" if($('#contextMenu').css('display') == 'none')$(this).children().css('background-color', 'white')">
<li class="resourcesListCheckbox fl"> <li class="resourcesListCheckbox fl">
<input name="checkbox1[]" type="checkbox" data-deleteble="<%= User.current.id ==attach.author_id ? 'Y' : 'N' %>" onclick="checkAllBox($(this));" value="<%= attach.id%>" class="resourcesCheckbox" /> <input name="checkbox1[]" type="checkbox" data-has-history="<%= attach.attachment_histories.count == 0 ? 'Y' : 'N' %>" data-deleteble="<%= User.current.id ==attach.author_id ? 'Y' : 'N' %>" onclick="checkAllBox($(this));" value="<%= attach.id%>" class="resourcesCheckbox" />
</li> </li>
<li class="resourcesListName fl"> <li class="resourcesListName fl">
<!--<a href="javascript:void(0);" class="resourcesBlack"><%#=truncate(attach.filename,:length=>18)%></a>--> <!--<a href="javascript:void(0);" class="resourcesBlack"><%#=truncate(attach.filename,:length=>18)%></a>-->

View File

@ -308,10 +308,15 @@
//批量删除 //批量删除
function batch_delete(){ function batch_delete(){
var data = $("#resources_list_form").serialize(); var data = $("#resources_list_form").serialize();
if($("input[type=checkbox][data-has-history=Y]:checked").length != 0){
alert("您只能删除没有历史记录的资源,请重新选择后再删除。");
return;
}
if($("input[type=checkbox][data-deleteble=N]:checked").length != 0){ if($("input[type=checkbox][data-deleteble=N]:checked").length != 0){
alert("您只能删除自己上传的资源,请重新选择后再删除。"); alert("您只能删除自己上传的资源,请重新选择后再删除。");
return; return;
} }
if(data != "" && confirm('确认要删除这些资源吗?')) { if(data != "" && confirm('确认要删除这些资源吗?')) {
$.post( $.post(
'<%= user_resource_delete_user_path(@user)%>', '<%= user_resource_delete_user_path(@user)%>',
@ -455,6 +460,10 @@
line.children().css("background-color", 'white'); line.children().css("background-color", 'white');
id = line.children().last().html(); id = line.children().last().html();
user_id = line.children().eq(5).html(); user_id = line.children().eq(5).html();
if(line.children().first().children().data('hasHistory') == 'Y'){
alert('该资源存在历史版本,不能删除');
return;
}
if(user_id === '<%= User.current.id%>') { if(user_id === '<%= User.current.id%>') {
if (confirm('确定要删除资源"' + line.children().eq(1).children().attr('title').trim() + '"么?')) { if (confirm('确定要删除资源"' + line.children().eq(1).children().attr('title').trim() + '"么?')) {
$.ajax({ $.ajax({