mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-16 13:58:45 +02:00
N°783 Attachments can now be readonly in some states. Use the new module parameter "readonly_states".
SVN:trunk[4610]
This commit is contained in:
@@ -20,6 +20,10 @@ define('ATTACHMENT_DOWNLOAD_URL', 'pages/ajax.document.php?operation=download_do
|
||||
|
||||
class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExtension
|
||||
{
|
||||
const ENUM_GUI_ALL = 'all';
|
||||
const ENUM_GUI_BACKOFFICE = 'backoffice';
|
||||
const ENUM_GUI_PORTALS = 'portals';
|
||||
|
||||
protected static $m_bIsModified = false;
|
||||
|
||||
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
|
||||
@@ -243,7 +247,7 @@ EOF
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>'.Dict::S('Attachments:FieldsetTitle').'</legend>');
|
||||
|
||||
if ($bEditMode)
|
||||
if ($bEditMode && !static::IsReadonlyState($oObject, $oObject->GetState(), static::ENUM_GUI_BACKOFFICE) )
|
||||
{
|
||||
$sIsDeleteEnabled = $this->m_bDeleteEnabled ? 'true' : 'false';
|
||||
$iTransactionId = $oPage->GetTransactionId();
|
||||
@@ -642,7 +646,66 @@ EOF
|
||||
$oChangeOp->Set('filename', $sFileName);
|
||||
}
|
||||
return $oChangeOp;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Returns if Attachments should be readonly for $oObject in the $sState state for the $sGUI GUI
|
||||
*
|
||||
* @param DBObject $oObject
|
||||
* @param string $sState
|
||||
* @param string $sGUI
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsReadonlyState(DBObject $oObject, $sState, $sGUI = self::ENUM_GUI_ALL)
|
||||
{
|
||||
$aParamDefaultValue = array(
|
||||
static::ENUM_GUI_ALL => array(
|
||||
'Ticket' => array('closed')
|
||||
)
|
||||
);
|
||||
|
||||
$bReadonly = false;
|
||||
$sClass = get_class($oObject);
|
||||
$aReadonlyStatus = MetaModel::GetModuleSetting('itop-attachments', 'readonly_states', $aParamDefaultValue);
|
||||
if(!empty($aReadonlyStatus))
|
||||
{
|
||||
// Merging GUIs entries
|
||||
$aEntries = array();
|
||||
// - All
|
||||
if( array_key_exists(static::ENUM_GUI_ALL, $aReadonlyStatus) )
|
||||
{
|
||||
$aEntries = array_merge_recursive($aEntries, $aReadonlyStatus[static::ENUM_GUI_ALL]);
|
||||
}
|
||||
// - Backoffice & Portals
|
||||
foreach( array(static::ENUM_GUI_BACKOFFICE, static::ENUM_GUI_PORTALS) as $sEnumGUI)
|
||||
{
|
||||
if( in_array($sGUI, array(static::ENUM_GUI_ALL, $sEnumGUI)) )
|
||||
{
|
||||
if( array_key_exists($sEnumGUI, $aReadonlyStatus) )
|
||||
{
|
||||
$aEntries = array_merge_recursive($aEntries, $aReadonlyStatus[$sEnumGUI]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aParentClasses = array_reverse( MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL) );
|
||||
foreach($aParentClasses as $sParentClass)
|
||||
{
|
||||
if( array_key_exists($sParentClass, $aEntries) )
|
||||
{
|
||||
// If we found an ancestor of the object's class, we stop looking event if the current state is not specified
|
||||
if( in_array($oObject->GetState(), $aEntries[$sParentClass]) )
|
||||
{
|
||||
$bReadonly = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bReadonly;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,7 @@ use \DBObjectSearch;
|
||||
use \DBObjectSetComparator;
|
||||
use \InlineImage;
|
||||
use \AttributeDateTime;
|
||||
use \AttachmentPlugIn;
|
||||
use \Combodo\iTop\Form\FormManager;
|
||||
use \Combodo\iTop\Form\Form;
|
||||
use \Combodo\iTop\Form\Field\FileUploadField;
|
||||
@@ -52,7 +53,9 @@ class ObjectFormManager extends FormManager
|
||||
const ENUM_MODE_CREATE = 'create';
|
||||
const ENUM_MODE_APPLY_STIMULUS = 'apply_stimulus';
|
||||
|
||||
/** @var \Silex\Application $oApp */
|
||||
protected $oApp;
|
||||
/** @var \DBObject $oObject */
|
||||
protected $oObject;
|
||||
protected $sMode;
|
||||
protected $sActionRulesToken;
|
||||
@@ -658,9 +661,9 @@ class ObjectFormManager extends FormManager
|
||||
}
|
||||
|
||||
// Checking if the instance has attachments
|
||||
if (class_exists('Attachment'))
|
||||
if (class_exists('Attachment') && class_exists('AttachmentPlugIn'))
|
||||
{
|
||||
// Checking if the object is allowed for attchments
|
||||
// Checking if the object is allowed for attachments
|
||||
$bClassAllowed = false;
|
||||
$aAllowedClasses = MetaModel::GetModuleSetting('itop-attachments', 'allowed_classes', array('Ticket'));
|
||||
foreach ($aAllowedClasses as $sAllowedClass)
|
||||
@@ -683,7 +686,8 @@ class ObjectFormManager extends FormManager
|
||||
->SetAllowDelete($this->oApp['combodo.portal.instance.conf']['properties']['attachments']['allow_delete'])
|
||||
->SetObject($this->oObject);
|
||||
|
||||
if (($this->sMode === static::ENUM_MODE_VIEW) || ($oForm->GetEditableFieldCount() === 0))
|
||||
// Checking if we can edit attachments in the current state
|
||||
if (($this->sMode === static::ENUM_MODE_VIEW) || AttachmentPlugIn::IsReadonlyState($this->oObject, $this->oObject->GetState(), AttachmentPlugIn::ENUM_GUI_PORTALS) === true)
|
||||
{
|
||||
$oField->SetReadOnly(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user