Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/support/3.2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
accognet committed Feb 27, 2024
2 parents f3f8601 + 9c35cdd commit 2cafa78
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 20 deletions.
12 changes: 7 additions & 5 deletions application/ui.htmleditorwidget.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ public function Display(WebPage $oPage, $aArgs = array())
// To change the default settings of the editor,
// a) edit the file /js/ckeditor/config.js
// b) or override some of the configuration settings, using the second parameter of ckeditor()
$sJSDefineWidth = '';
$aConfig = utils::GetCkeditorPref();
$sWidthSpec = addslashes(trim($this->m_oAttDef->GetWidth()));
if ($sWidthSpec != '')
{
$aConfig['width'] = $sWidthSpec;
if ($sWidthSpec != '') {
/*NΒ°6543 - the function min allow to keep text inside the column when width is defined*/
$aConfig['width'] = "min($sWidthSpec,100%)";
$sJSDefineWidth = '$("#cke_'.$iId.' iframe").contents().find("body").css("width", "'.$sWidthSpec.'")';
}
$sHeightSpec = addslashes(trim($this->m_oAttDef->GetHeight()));
if ($sHeightSpec != '')
{
if ($sHeightSpec != '') {
$aConfig['height'] = $sHeightSpec;
}
$sConfigJS = json_encode($aConfig);
Expand Down Expand Up @@ -111,6 +112,7 @@ public function Display(WebPage $oPage, $aArgs = array())
else
{
oMe.data('ckeditorInstance').setReadOnly(oMe.prop('disabled'));
$sJSDefineWidth
}
};
setTimeout(delayedSetReadOnly, 50);
Expand Down
1 change: 0 additions & 1 deletion core/attributedef.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4535,7 +4535,6 @@ public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
$sStyle = '';
if (count($aStyles) > 0)
{
$aStyles[] = 'overflow:auto';
$sStyle = 'style="'.implode(';', $aStyles).'"';
}

Expand Down
2 changes: 1 addition & 1 deletion core/cmdbobject.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ protected function RecordObjDeletion($objkey)
$oMyChangeOp->Set("objclass", MetaModel::GetRootClass(get_class($this)));
$oMyChangeOp->Set("objkey", $objkey);
$oMyChangeOp->Set("fclass", get_class($this));
$oMyChangeOp->Set("fname", substr($this->GetRawName(), 0, 255)); // Protect against very long friendly names
$oMyChangeOp->SetTrim("fname", $this->GetRawName()); // Protect against very long friendly names
$iId = $oMyChangeOp->DBInsertNoReload();
}

Expand Down
27 changes: 20 additions & 7 deletions css/backoffice/components/_field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,29 @@ $ibo-field--enable-bulk--checkbox--margin-left: $ibo-spacing-300 !default;
}
}
}

/*NΒ°6543 - We need the rule to keep text inside the column when width is defined*/
&[data-attribute-type="AttributeHtml"],
&[data-attribute-type="AttributeText"] {
&[data-attribute-flag-read-only="true"] {
display: grid;

> .ibo-field--value {
max-width: 100%;
overflow: auto;
}
}
}
}

/* Large field = Label on top, value below */
.ibo-field-large {
display: block;
/* Large field = Label on top, value below */
.ibo-field-large {
display: block;

.ibo-field--label {
position: relative; /* Necessary for fullscreen toggler */
display: flex;
align-items: center;
.ibo-field--label {
position: relative; /* Necessary for fullscreen toggler */
display: flex;
align-items: center;
max-width: initial;
width: 100%;
}
Expand Down
7 changes: 7 additions & 0 deletions css/backoffice/components/datatable/_datatable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ $ibo-fieldsorter--selected--background-color: $ibo-color-blue-200 !default;
.ibo-datatable--row-actions-toolbar{
justify-content: end;
}
/* NΒ°6543 - We need the rule to keep text inside the column when width is defined */
> [data-attribute-type="AttributeHtml"],
> [data-attribute-type="AttributeText"] {
max-width: 100%;
overflow: auto;
}

}
}

Expand Down
49 changes: 49 additions & 0 deletions tests/php-unit-tests/unitary-tests/core/CMDBObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

use CMDBObject;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use CoreException;
use Exception;
use MetaModel;


/**
* @since 2.7.7 3.0.2 3.1.0 NΒ°3717 tests history objects creation
*
Expand Down Expand Up @@ -168,6 +170,53 @@ public function testCurrentChangeUnderImpersonation($sTrackInfo=null, $sExpected
CMDBObject::SetTrackInfo($sInitialTrackInfo);
}

/**
* Data provider for test deletion
* NΒ°5547 - Object deletion fails if friendlyname too long
*
* @return array data
*/
public function RecordObjDeletionProvider()
{
return [
'friendlyname longer than 255 characters which will be truncated on a multi-bytes characters' => [
str_repeat('e', 250),
'πŸ˜πŸ˜‚πŸ€£πŸ˜ƒπŸ˜„πŸ˜…πŸ˜†πŸ˜—πŸ₯°πŸ˜˜πŸ˜πŸ˜ŽπŸ˜‹πŸ˜ŠπŸ˜‰πŸ˜™πŸ˜š',
],
'friendlyname longer than 255 characters which will be truncated after a single byte characters' => [
'πŸ˜πŸ˜‚πŸ€£πŸ˜ƒπŸ˜„πŸ˜…πŸ˜†πŸ˜—πŸ₯°πŸ˜˜πŸ˜πŸ˜ŽπŸ˜‹πŸ˜ŠπŸ˜‰πŸ˜™πŸ˜š',
str_repeat('e', 250),
],
];
}

/**
* NΒ°5547 - Object deletion fails if friendlyname too long
*
* @dataProvider RecordObjDeletionProvider
*
*/
public function testRecordObjDeletion( string $sFirstName, string $sName)
{
$oPerson = MetaModel::NewObject('Person', [
'first_name' => $sFirstName,
'name' => $sName,
'org_id' => 1,
]);
$oPerson->DBWrite();

$bDeletionOK = true;
try {
$oDeletionPlan = $this->InvokeNonPublicMethod(CMDBObject::class, 'RecordObjDeletion', $oPerson, [$oPerson->GetKey()]);
}
catch (CoreException $e) {
$bDeletionOK = false;
}
// We don't need to test the result (truncated string), it's already done in \DBObject::SetTrim() with NΒ°3448
$this->assertTrue($bDeletionOK);
}


private function ReplaceByFriendlyNames($sMessage, $oAdminUser, $oImpersonatedUser) : string {
$sNewMessage = str_replace('AdminSurName AdminName', $oAdminUser->GetFriendlyName(), $sMessage);
$sNewMessage = str_replace('ImpersonatedSurName ImpersonatedName', $oImpersonatedUser->GetFriendlyName(), $sNewMessage);
Expand Down
64 changes: 58 additions & 6 deletions tests/php-unit-tests/unitary-tests/core/DBObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,54 @@ private function CreatePersonInstance()
return $oPerson;
}

/**
* Data provider for test deletion
* NΒ°5547 - Object deletion fails if friendlyname too long
*
* @return array data
*/
public function getDeletionLongValueProvider()
{
return [
'friendlyname longer than 255 chracters with smiley' => [
'0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq',
'πŸ˜πŸ˜‚πŸ€£πŸ˜ƒπŸ˜„πŸ˜…πŸ˜†πŸ˜—πŸ₯°πŸ˜˜πŸ˜πŸ˜ŽπŸ˜‹πŸ˜ŠπŸ˜‰πŸ˜™πŸ˜š',
],
'the same friendlyname in other order with error before fix 5547 ' => [
'πŸ˜πŸ˜‚πŸ€£πŸ˜ƒπŸ˜„πŸ˜…πŸ˜†πŸ˜—πŸ₯°πŸ˜˜πŸ˜πŸ˜ŽπŸ˜‹πŸ˜ŠπŸ˜‰πŸ˜™πŸ˜š',
'0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq',
],
];
}

/**
* NΒ°5547 - Object deletion fails if friendlyname too long
*
* @covers DBObject::DBIncrement
*
* @dataProvider getDeletionLongValueProvider
*
*/
public function testDeletionLongValue(string $sName, string $sFirstName)
{
// Create a UserRequest with 2 contacts
$oPerson = MetaModel::NewObject('Person', [
'name' => $sName,
'first_name' => $sFirstName,
'org_id' => 1,
]);
$oPerson->DBWrite();

$bDeletionOK = true;
try {
$oDeletionPlan = $oPerson->DBDelete();
}
catch (CoreException $e) {
$bDeletionOK = false;
}
$this->assertTrue($bDeletionOK);
}

public function ResetReloadCount()
{
$this->aReloadCount = [];
Expand Down Expand Up @@ -1211,8 +1259,14 @@ public function testConstructorMemoryFootprint():void
$fTotalDuration = microtime(true) - $fStart;
echo 'Total duration: '.sprintf('%.3f s', $fTotalDuration)."\n\n";
}

public function CheckLongValueInAttributeProvider() {
/**
* Data provider for test deletion
* NΒ°5547 - Object deletion fails if friendlyname too long
*
* @return array data
*/
public function DeletionLongValueProvider()
{
return [
// UserRequest.title is an AttributeString (maxsize = 255)
'title 250 chars' => ['title', 250],
Expand All @@ -1234,11 +1288,9 @@ public function CheckLongValueInAttributeProvider() {
/**
* Test check long field with non ascii characters
*
* @covers DBObject::Set
* @covers DBObject::CheckToWrite
* @covers DBObject::SetTrim
* @covers DBObject::DBDelete
*
* @dataProvider CheckLongValueInAttributeProvider
* @dataProvider DeletionLongValueProvider
*
* @since 3.1.2 NΒ°3448 - Framework field size check not correctly implemented for multi-bytes languages/strings
*/
Expand Down

0 comments on commit 2cafa78

Please sign in to comment.