mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
Protect attachments against concurrent edition of a ticket.
SVN:trunk[3221]
This commit is contained in:
@@ -243,7 +243,7 @@ EOF
|
|||||||
$sDeleteBtn = Dict::S('Attachments:DeleteBtn');
|
$sDeleteBtn = Dict::S('Attachments:DeleteBtn');
|
||||||
$oPage->add_script(
|
$oPage->add_script(
|
||||||
<<<EOF
|
<<<EOF
|
||||||
function RemoveNewAttachment(att_id)
|
function RemoveAttachment(att_id)
|
||||||
{
|
{
|
||||||
$('#attachment_'+att_id).attr('name', 'removed_attachments[]');
|
$('#attachment_'+att_id).attr('name', 'removed_attachments[]');
|
||||||
$('#display_attachment_'+att_id).hide();
|
$('#display_attachment_'+att_id).hide();
|
||||||
@@ -287,7 +287,7 @@ EOF
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=download_document&class=Attachment&id='+data.att_id+'&field=contents';
|
var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=download_document&class=Attachment&id='+data.att_id+'&field=contents';
|
||||||
$('#attachments').append('<div class="attachment" id="display_attachment_'+data.att_id+'"><a data-preview="'+data.preview+'" href="'+sDownloadLink+'"><img src="'+data.icon+'"><br/>'+data.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveNewAttachment('+data.att_id+');"/></div>');
|
$('#attachments').append('<div class="attachment" id="display_attachment_'+data.att_id+'"><a data-preview="'+data.preview+'" href="'+sDownloadLink+'"><img src="'+data.icon+'"><br/>'+data.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveAttachment('+data.att_id+');"/></div>');
|
||||||
if($sIsDeleteEnabled)
|
if($sIsDeleteEnabled)
|
||||||
{
|
{
|
||||||
$('#display_attachment_'+data.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
|
$('#display_attachment_'+data.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
|
||||||
@@ -319,7 +319,7 @@ EOF
|
|||||||
$sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
$sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
||||||
$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
|
$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
|
||||||
$sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
$sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
||||||
$oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a data-preview="'.$sPreview.'" href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/> <input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="$(\'#attachment_'.$iAttId.'\').remove();"/> </div>');
|
$oPage->add('<div class="attachment" id="display_attachment_'.$iAttId.'"><a data-preview="'.$sPreview.'" href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input id="attachment_'.$iAttId.'" type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/> <input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="RemoveAttachment('.$iAttId.');"/> </div>');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suggested attachments are listed here but treated as temporary
|
// Suggested attachments are listed here but treated as temporary
|
||||||
@@ -347,7 +347,7 @@ EOF
|
|||||||
$sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
$sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
||||||
$sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
$sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
||||||
$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
|
$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
|
||||||
$oPage->add('<div class="attachment" id="display_attachment_'.$iAttId.'"><a data-preview="'.$sPreview.'" href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/> <input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="RemoveNewAttachment('.$iAttId.');"/> </div>');
|
$oPage->add('<div class="attachment" id="display_attachment_'.$iAttId.'"><a data-preview="'.$sPreview.'" href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input id="attachment_'+data.result.att_id+'" type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/> <input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="RemoveAttachment('.$iAttId.');"/> </div>');
|
||||||
$oPage->add_ready_script("$('#attachment_plugin').trigger('add_attachment', [$iAttId, '".addslashes($sFileName)."']);");
|
$oPage->add_ready_script("$('#attachment_plugin').trigger('add_attachment', [$iAttId, '".addslashes($sFileName)."']);");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,7 +378,7 @@ $oPage->add_ready_script(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=download_document&class=Attachment&id='+data.result.att_id+'&field=contents';
|
var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=download_document&class=Attachment&id='+data.result.att_id+'&field=contents';
|
||||||
$('#attachments').append('<div class="attachment" id="display_attachment_'+data.result.att_id+'"><a data-preview="'+data.result.preview+'" href="'+sDownloadLink+'"><img src="'+data.result.icon+'"><br/>'+data.result.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.result.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveNewAttachment('+data.result.att_id+');"/></div>');
|
$('#attachments').append('<div class="attachment" id="display_attachment_'+data.result.att_id+'"><a data-preview="'+data.result.preview+'" href="'+sDownloadLink+'"><img src="'+data.result.icon+'"><br/>'+data.result.msg+'<input id="attachment_'+data.result.att_id+'" type="hidden" name="attachments[]" value="'+data.result.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveAttachment('+data.result.att_id+');"/></div>');
|
||||||
if($sIsDeleteEnabled)
|
if($sIsDeleteEnabled)
|
||||||
{
|
{
|
||||||
$('#display_attachment_'+data.result.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
|
$('#display_attachment_'+data.result.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
|
||||||
@@ -486,14 +486,15 @@ EOF
|
|||||||
{
|
{
|
||||||
$aActions = array();
|
$aActions = array();
|
||||||
$aAttachmentIds = utils::ReadParam('attachments', array());
|
$aAttachmentIds = utils::ReadParam('attachments', array());
|
||||||
|
$aRemovedAttachmentIds = utils::ReadParam('removed_attachments', array());
|
||||||
|
|
||||||
// Get all current attachments
|
// Get all current attachments
|
||||||
$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
|
$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
|
||||||
$oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
|
$oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
|
||||||
while ($oAttachment = $oSet->Fetch())
|
while ($oAttachment = $oSet->Fetch())
|
||||||
{
|
{
|
||||||
// Remove attachments that are no longer attached to the current object
|
// Remove attachments that are no longer attached to the current object
|
||||||
if (!in_array($oAttachment->GetKey(), $aAttachmentIds))
|
if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds))
|
||||||
{
|
{
|
||||||
$oAttachment->DBDelete();
|
$oAttachment->DBDelete();
|
||||||
$aActions[] = self::GetActionDescription($oAttachment, false /* false => deletion */);
|
$aActions[] = self::GetActionDescription($oAttachment, false /* false => deletion */);
|
||||||
@@ -504,7 +505,6 @@ EOF
|
|||||||
$sTempId = session_id().'_'.$iTransactionId;
|
$sTempId = session_id().'_'.$iTransactionId;
|
||||||
// The object is being created from a form, check if there are pending attachments
|
// The object is being created from a form, check if there are pending attachments
|
||||||
// for this object, but deleting the "new" ones that were already removed from the form
|
// for this object, but deleting the "new" ones that were already removed from the form
|
||||||
$aRemovedAttachmentIds = utils::ReadParam('removed_attachments', array());
|
|
||||||
$sOQL = 'SELECT Attachment WHERE temp_id = :temp_id';
|
$sOQL = 'SELECT Attachment WHERE temp_id = :temp_id';
|
||||||
$oSearch = DBObjectSearch::FromOQL($sOQL);
|
$oSearch = DBObjectSearch::FromOQL($sOQL);
|
||||||
foreach($aAttachmentIds as $iAttachmentId)
|
foreach($aAttachmentIds as $iAttachmentId)
|
||||||
|
|||||||
Reference in New Issue
Block a user