N°5916 - Generic message on Link Uniqueness rules (#487)

This commit is contained in:
bdalsass
2023-04-28 14:45:09 +02:00
committed by GitHub
parent de35d941c1
commit d91fafb2af
3 changed files with 121 additions and 5 deletions

View File

@@ -2152,8 +2152,14 @@ abstract class DBObject implements iDisplay
$sMessageKey = "Class:$sClass/UniquenessRule:$sUniquenessRuleId";
$sTemplate = Dict::S($sMessageKey, '');
if (empty($sTemplate))
{
if (empty($sTemplate)) {
// Generic (class independent) uniqueness rule
$sUniquenessRuleGenericMessage = $this->GetUniquenessRuleGenericMessage($sCurrentClass, $sUniquenessRuleId);
if ($sUniquenessRuleGenericMessage !== null) {
return $sUniquenessRuleGenericMessage;
}
// we could add also a specific message if user is admin ("dict key is missing")
return Dict::Format('Core:UniquenessDefaultError', $sUniquenessRuleId);
}
@@ -2164,9 +2170,67 @@ abstract class DBObject implements iDisplay
}
/**
*
* @internal
*
* GetUniquenessRuleGenericMessage.
*
* @param string $sCurrentClass
* @param string $sUniquenessRuleId
*
* @return string|null
* @since 3.1.0
*/
private function GetUniquenessRuleGenericMessage(string $sCurrentClass, string $sUniquenessRuleId): ?string
{
// Dict placeholders data
$aPlaceholdersData = [];
try {
// Retrieve class uniqueness rules
$aUniquenessRules = MetaModel::GetUniquenessRules($sCurrentClass);
// Retrieve rule properties
if (!array_key_exists($sUniquenessRuleId, $aUniquenessRules)) {
return null;
}
$aUniquenessRuleProperties = $aUniquenessRules[$sUniquenessRuleId];
// Check generic message existence
$sMessageKey = "Class:cmdbAbstractObject/UniquenessRule:$sUniquenessRuleId";
if (!Dict::Exists($sMessageKey)) {
return null;
}
// Retrieve rule attributes
if (array_key_exists('attributes', $aUniquenessRuleProperties)) {
// Retrieve attributes
$aAttributes = $aUniquenessRuleProperties['attributes'];
// Compute attributes data...
foreach ($aAttributes as $sAttCode) {
$oAttDef = MetaModel::GetAttributeDef($sCurrentClass, $sAttCode);
if ($oAttDef instanceof AttributeExternalKey) {
$aPlaceholdersData[] = $oAttDef->GetTargetClass();
$aPlaceholdersData[] = MetaModel::GetObject($oAttDef->GetTargetClass(), $this->Get($sAttCode))->Get('friendlyname');
} else {
$aPlaceholdersData[] = $oAttDef->GetLabel();
$aPlaceholdersData[] = $oAttDef->GetLabel($this->Get($sAttCode));
}
}
}
return Dict::Format($sMessageKey, ...$aPlaceholdersData);
}
catch (Exception $e) {
ExceptionLog::LogException($e);
return null;
}
}
/**
*
* @internal
*
* @param string $sUniquenessRuleId uniqueness rule ID
* @param array $aUniquenessRuleProperties uniqueness rule properties
*

View File

@@ -0,0 +1,26 @@
<?php
/**
* Localized data
*
* @copyright Copyright (C) 2010-2023 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http://www.gnu.org/licenses/>
*/
Dict::Add('EN US', 'English', 'English', [
'Class:cmdbAbstractObject/UniquenessRule:no_duplicate' => '%1$s: %2$s is already linked to %3$s: %4$s, duplicates are not allowed on this relation.',
]);

View File

@@ -0,0 +1,26 @@
<?php
/**
* Localized data
*
* @copyright Copyright (C) 2010-2023 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http://www.gnu.org/licenses/>
*/
Dict::Add('FR FR', 'French', 'Français', [
'Class:cmdbAbstractObject/UniquenessRule:no_duplicate' => '%1$s : %2$s est déjà lié à %3$s : %4$s, les doublons ne sont pas autorisés sur cette relation.',
]);