N°3423 - Allow AttributeImage / AttributeDocument content to be cached by the browser (portal)

This commit is contained in:
Eric
2021-01-21 15:15:45 +01:00
parent 8f1d9fba57
commit 154156f4a1
8 changed files with 61 additions and 18 deletions

View File

@@ -149,7 +149,7 @@ class ormDocument
*/
public function GetDisplayURL($sClass, $Id, $sAttCode)
{
$sSignature = md5($this->GetData());
$sSignature = $this->GetSignature();
// TODO: When refactoring this with the URLMaker system, mind to also change calls in the portal (look for the "p_object_document_display" route)
return utils::GetAbsoluteUrlAppRoot() . "pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode&s=$sSignature&cache=86400";
}
@@ -161,7 +161,7 @@ class ormDocument
public function GetDownloadURL($sClass, $Id, $sAttCode)
{
// Compute a signature to reset the cache anytime the data changes (this is acceptable if used only with icon files)
$sSignature = md5($this->GetData());
$sSignature = $this->GetSignature();
// TODO: When refactoring this with the URLMaker system, mind to also change calls in the portal (look for the "p_object_document_display" route)
return utils::GetAbsoluteUrlAppRoot() . "pages/ajax.document.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode&s=$sSignature&cache=86400";
}
@@ -221,4 +221,12 @@ class ormDocument
$oPage->p($e->getMessage());
}
}
/**
* @return string
*/
public function GetSignature(): string
{
return md5($this->GetData());
}
}

View File

@@ -1159,7 +1159,8 @@ class UserRights
else
{
if (ContextTag::Check(ContextTag::TAG_PORTAL)) {
$sPictureUrl = utils::GetAbsoluteUrlAppRoot().'pages/exec.php/object/document/display/'.$sContactClass.'/'.$oContact->GetKey().'/'.static::DEFAULT_CONTACT_PICTURE_ATTCODE.'?exec_module=itop-portal-base&exec_page=index.php&portal_id='.PORTAL_ID;
$sSignature = $oPicture->GetSignature();
$sPictureUrl = utils::GetAbsoluteUrlAppRoot().'pages/exec.php/object/document/display/'.$sContactClass.'/'.$oContact->GetKey().'/'.static::DEFAULT_CONTACT_PICTURE_ATTCODE.'?cache=86400&s='.$sSignature.'&exec_module=itop-portal-base&exec_page=index.php&portal_id='.PORTAL_ID;
}
else {
$sPictureUrl = $oPicture->GetDisplayURL($sContactClass, $oContact->GetKey(), static::DEFAULT_CONTACT_PICTURE_ATTCODE);

View File

@@ -691,15 +691,17 @@ class ManageBrickController extends BrickController
}
elseif ($oAttDef instanceof AttributeImage)
{
/** @var \ormDocument $oOrmDoc */
$oOrmDoc = $oCurrentRow->Get($sItemAttr);
if (is_object($oOrmDoc) && !$oOrmDoc->IsEmpty())
{
$sUrl = $oUrlGenerator->generate('p_object_document_display', array(
$sUrl = $oUrlGenerator->generate('p_object_document_display', [
'sObjectClass' => get_class($oCurrentRow),
'sObjectId' => $oCurrentRow->GetKey(),
'sObjectField' => $sItemAttr,
'cache' => 86400,
));
's' => $oOrmDoc->GetSignature(),
]);
}
else
{

View File

@@ -1322,15 +1322,17 @@ class ObjectController extends BrickController
}
elseif ($oAttDef instanceof AttributeImage)
{
/** @var \ormDocument $oOrmDoc */
$oOrmDoc = $oObject->Get($oAttDef->GetCode());
if (is_object($oOrmDoc) && !$oOrmDoc->IsEmpty())
{
$sUrl = $oUrlGenerator->generate('p_object_document_display', array(
$sUrl = $oUrlGenerator->generate('p_object_document_display', [
'sObjectClass' => get_class($oObject),
'sObjectId' => $oObject->GetKey(),
'sObjectField' => $oAttDef->GetCode(),
'cache' => 86400,
));
's' => $oOrmDoc->GetSignature(),
]);
}
else
{

View File

@@ -373,8 +373,14 @@ class UserProfileBrickController extends BrickController
$aFormData['error'] = $e->GetMessage();
}
// TODO: This should be changed when refactoring the ormDocument GetDisplayUrl() and GetDownloadUrl() in iTop 3.0
$aFormData['picture_url'] = $oUrlGenerator->generate('p_object_document_display', array('sObjectClass' => get_class($oCurContact), 'sObjectId' => $oCurContact->GetKey(), 'sObjectField' => $sPictureAttCode, 'cache' => 86400, 't' => time()));
$oOrmDoc = $oCurContact->Get($sPictureAttCode);
$aFormData['picture_url'] = $oUrlGenerator->generate('p_object_document_display', [
'sObjectClass' => get_class($oCurContact),
'sObjectId' => $oCurContact->GetKey(),
'sObjectField' => $sPictureAttCode,
'cache' => 86400,
's' => $oOrmDoc->GetSignature(),
]);
$aFormData['validation'] = array(
'valid' => true,
'messages' => array(),

View File

@@ -908,8 +908,21 @@ class ObjectFormManager extends FormManager
if ($this->oContainer !== null)
{
// Override hardcoded URLs in ormDocument pointing to back office console
$sDisplayUrl = $this->oContainer->get('url_generator')->generate('p_object_document_display', array('sObjectClass' => get_class($this->oObject), 'sObjectId' => $this->oObject->GetKey(), 'sObjectField' => $sAttCode, 'cache' => 86400));
$sDownloadUrl = $this->oContainer->get('url_generator')->generate('p_object_document_download', array('sObjectClass' => get_class($this->oObject), 'sObjectId' => $this->oObject->GetKey(), 'sObjectField' => $sAttCode, 'cache' => 86400));
$oOrmDoc = $this->oObject->Get($sAttCode);
$sDisplayUrl = $this->oContainer->get('url_generator')->generate('p_object_document_display', [
'sObjectClass' => get_class($this->oObject),
'sObjectId' => $this->oObject->GetKey(),
'sObjectField' => $sAttCode,
'cache' => 86400,
's' => $oOrmDoc->GetSignature(),
]);
$sDownloadUrl = $this->oContainer->get('url_generator')->generate('p_object_document_download', [
'sObjectClass' => get_class($this->oObject),
'sObjectId' => $this->oObject->GetKey(),
'sObjectField' => $sAttCode,
'cache' => 86400,
's' => $oOrmDoc->GetSignature(),
]);
/** @var \Combodo\iTop\Form\Field\BlobField $oField */
$oField->SetDisplayUrl($sDisplayUrl)
->SetDownloadUrl($sDownloadUrl);

View File

@@ -360,12 +360,14 @@ class BrowseBrickHelper
{
if (is_object($tmpAttValue) && !$tmpAttValue->IsEmpty())
{
$tmpAttValue = $this->oUrlGenerator->generate('p_object_document_display', array(
$oOrmDoc = $tmpAttValue;
$tmpAttValue = $this->oUrlGenerator->generate('p_object_document_display', [
'sObjectClass' => $sCurrentObjectClass,
'sObjectId' => $sCurrentObjectId,
'sObjectField' => $aLevelsProperties[$key][$sOptionalAttribute],
'cache' => 86400,
));
's' => $oOrmDoc->GetSignature(),
]);
}
else
{
@@ -410,12 +412,13 @@ class BrowseBrickHelper
$oOrmDoc = $value->Get($aField['code']);
if (is_object($oOrmDoc) && !$oOrmDoc->IsEmpty())
{
$sUrl = $this->oUrlGenerator->generate('p_object_document_display', array(
$sUrl = $this->oUrlGenerator->generate('p_object_document_display', [
'sObjectClass' => $sCurrentObjectClass,
'sObjectId' => $sCurrentObjectId,
'sObjectField' => $aField['code'],
'cache' => 86400,
));
's' => $oOrmDoc->GetSignature(),
]);
}
else
{
@@ -530,12 +533,14 @@ class BrowseBrickHelper
{
if (is_object($tmpAttValue) && !$tmpAttValue->IsEmpty())
{
$tmpAttValue = $this->oUrlGenerator->generate('p_object_document_display', array(
$oOrmDoc = $tmpAttValue;
$tmpAttValue = $this->oUrlGenerator->generate('p_object_document_display', [
'sObjectClass' => get_class($aCurrentRowValues[0]),
'sObjectId' => $aCurrentRowValues[0]->GetKey(),
'sObjectField' => $aLevelsProperties[$aCurrentRowKeys[0]][$sOptionalAttribute],
'cache' => 86400,
));
's' => $oOrmDoc->GetSignature(),
]);
}
else
{

View File

@@ -112,7 +112,13 @@ class CombodoCurrentContactPhotoUrl
if (is_object($oImage) && !$oImage->IsEmpty())
{
// TODO: This should be changed when refactoring the ormDocument GetDisplayUrl() and GetDownloadUrl() in iTop 3.0
$sContactPhotoUrl = $this->oContainer->get('url_generator')->generate('p_object_document_display', array('sObjectClass' => get_class($oContact), 'sObjectId' => $oContact->GetKey(), 'sObjectField' => $sPictureAttCode, 'cache' => 86400));
$sContactPhotoUrl = $this->oContainer->get('url_generator')->generate('p_object_document_display', [
'sObjectClass' => get_class($oContact),
'sObjectId' => $oContact->GetKey(),
'sObjectField' => $sPictureAttCode,
'cache' => 86400,
's' => $oImage->GetSignature(),
]);
}
else
{