N°2841 - Error when trying to delete a user with a no admin

This commit is contained in:
acognet
2021-03-18 18:19:18 +01:00
parent 46680d3854
commit c214d09e84
11 changed files with 157 additions and 110 deletions

View File

@@ -1,20 +1,7 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* 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
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
define('ADMIN_PROFILE_NAME', 'Administrator');
@@ -266,17 +253,54 @@ class URP_UserProfile extends UserRightsBaseClassGUI
public function CheckToDelete(&$oDeletionPlan)
{
if (MetaModel::GetConfig()->Get('demo_mode'))
{
if (MetaModel::GetConfig()->Get('demo_mode')) {
// Users deletion is NOT allowed in demo mode
$oDeletionPlan->AddToDelete($this, null);
$oDeletionPlan->SetDeletionIssues($this, array('deletion not allowed in demo mode.'), true);
$oDeletionPlan->ComputeResults();
return false;
}
try {
$this->CheckIfProfileIsAllowed(UR_ACTION_DELETE);
}
catch (SecurityException $e) {
// Users deletion is NOT allowed
$oDeletionPlan->AddToDelete($this, null);
$oDeletionPlan->SetDeletionIssues($this, [$e->getMessage()], true);
$oDeletionPlan->ComputeResults();
return false;
}
return parent::CheckToDelete($oDeletionPlan);
}
public function DoCheckToDelete(&$oDeletionPlan)
{
if (MetaModel::GetConfig()->Get('demo_mode')) {
// Users deletion is NOT allowed in demo mode
$oDeletionPlan->AddToDelete($this, null);
$oDeletionPlan->SetDeletionIssues($this, array('deletion not allowed in demo mode.'), true);
$oDeletionPlan->ComputeResults();
return false;
}
try {
$this->CheckIfProfileIsAllowed(UR_ACTION_DELETE);
}
catch (SecurityException $e) {
// Users deletion is NOT allowed
$oDeletionPlan->AddToDelete($this, null);
$oDeletionPlan->SetDeletionIssues($this, [$e->getMessage()], true);
$oDeletionPlan->ComputeResults();
return false;
}
return parent::DoCheckToDelete($oDeletionPlan);
}
protected function OnInsert()
{
$this->CheckIfProfileIsAllowed(UR_ACTION_CREATE);
@@ -289,7 +313,6 @@ class URP_UserProfile extends UserRightsBaseClassGUI
protected function OnDelete()
{
$this->CheckIfProfileIsAllowed(UR_ACTION_DELETE);
}
/**

View File

@@ -4961,7 +4961,7 @@ EOF
$sSubtitle = Dict::Format('UI:Delect:Confirm_Count_ObjectsOf_Class', count($aObjects),
MetaModel::GetName($sClass));
}
$oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sSubtitle));
$oP->AddUiBlock(TitleUIBlockFactory::MakeStandard(new Html($sSubtitle)));
foreach ($aObjects as $oObj) {
$aKeys[] = $oObj->GetKey();

View File

@@ -219,6 +219,7 @@ return array(
'Combodo\\iTop\\Application\\UI\\Base\\Component\\QuickCreate\\QuickCreateHelper' => $baseDir . '/sources/application/UI/Base/Component/QuickCreate/QuickCreateHelper.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Spinner\\Spinner' => $baseDir . '/sources/application/UI/Base/Component/Spinner/Spinner.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Spinner\\SpinnerUIBlockFactory' => $baseDir . '/sources/application/UI/Base/Component/Spinner/SpinnerUIBlockFactory.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Text\\Text' => $baseDir . '/sources/application/UI/Base/Component/Text/Text.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Title\\Title' => $baseDir . '/sources/application/UI/Base/Component/Title/Title.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Title\\TitleUIBlockFactory' => $baseDir . '/sources/application/UI/Base/Component/Title/TitleUIBlockFactory.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Toolbar\\Toolbar' => $baseDir . '/sources/application/UI/Base/Component/Toolbar/Toolbar.php',

View File

@@ -449,6 +449,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
'Combodo\\iTop\\Application\\UI\\Base\\Component\\QuickCreate\\QuickCreateHelper' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/QuickCreate/QuickCreateHelper.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Spinner\\Spinner' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Spinner/Spinner.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Spinner\\SpinnerUIBlockFactory' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Spinner/SpinnerUIBlockFactory.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Text\\Text' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Text/Text.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Title\\Title' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Title/Title.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Title\\TitleUIBlockFactory' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Title/TitleUIBlockFactory.php',
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Toolbar\\Toolbar' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Toolbar/Toolbar.php',

View File

@@ -1,20 +1,7 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* 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
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory;
@@ -23,7 +10,7 @@ use Combodo\iTop\Application\UI\Base\Component\Dashlet\DashletContainer;
use Combodo\iTop\Application\UI\Base\Component\Dashlet\DashletFactory;
use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Panel\Panel;
use Combodo\iTop\Application\UI\Base\Component\Title\Title;
use Combodo\iTop\Application\UI\Base\Component\Title\TitleUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\Dashboard\DashboardColumn;
use Combodo\iTop\Application\UI\Base\Layout\Dashboard\DashboardRow;
@@ -233,21 +220,19 @@ try
$oP->TrashUnexpectedOutput();
$oP->output();
exit;
}
else
{
} else {
$sTitle = Dict::S('UI:Audit:AuditErrors');
$oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, '', '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
$oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('Back to audit results'), "./audit.php?".$oAppContext->GetForLink());
$oP->AddUiBlock($oBackButton);
$oP->AddUiBlock(new Title($sTitle . $oAuditRule->Get('description')));
$sBlockId = 'audit_errors';
$oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description')));
$sBlockId = 'audit_errors';
$oP->p("<div id=\"$sBlockId\">");
$oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'csv', array('show_obsolete_data' => true));
$oBlock->Display($oP, 1);
$oP->p("</div>");
$oP->p("</div>");
// Adjust the size of the Textarea containing the CSV to fit almost all the remaining space
$oP->add_ready_script(" $('#1>textarea').height(400);"); // adjust the size of the block
$sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey();
@@ -259,49 +244,49 @@ try
break;
case 'errors':
$sTitle = Dict::S('UI:Audit:AuditErrors');
$oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, '', '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
$iCategory = utils::ReadParam('category', '');
$iRuleIndex = utils::ReadParam('rule', 0);
$oAuditCategory = MetaModel::GetObject('AuditCategory', $iCategory);
$oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set'));
$oDefinitionFilter->UpdateContextFromUser();
FilterByContext($oDefinitionFilter, $oAppContext);
$oDefinitionSet = new CMDBObjectSet($oDefinitionFilter);
$oFilter = GetRuleResultFilter($iRuleIndex, $oDefinitionFilter, $oAppContext);
$oErrorObjectSet = new CMDBObjectSet($oFilter);
$oAuditRule = MetaModel::GetObject('AuditRule', $iRuleIndex);
$oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('Back to audit results'), "./audit.php?".$oAppContext->GetForLink());
$oP->AddUiBlock($oBackButton);
$oP->AddUiBlock(new Title($sTitle . $oAuditRule->Get('description')));
$sBlockId = 'audit_errors';
$oP->p("<div id=\"$sBlockId\">");
$oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'list', array('show_obsolete_data' => true));
$oBlock->Display($oP, 1);
$oP->p("</div>");
$sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey();
$oP->add_ready_script("$('a[href*=\"pages/UI.php?operation=search\"]').attr('href', '".$sExportUrl."')");
break;
$sTitle = Dict::S('UI:Audit:AuditErrors');
$oP->SetBreadCrumbEntry('ui-tool-auditerrors', $sTitle, '', '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
$iCategory = utils::ReadParam('category', '');
$iRuleIndex = utils::ReadParam('rule', 0);
$oAuditCategory = MetaModel::GetObject('AuditCategory', $iCategory);
$oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set'));
$oDefinitionFilter->UpdateContextFromUser();
FilterByContext($oDefinitionFilter, $oAppContext);
$oDefinitionSet = new CMDBObjectSet($oDefinitionFilter);
$oFilter = GetRuleResultFilter($iRuleIndex, $oDefinitionFilter, $oAppContext);
$oErrorObjectSet = new CMDBObjectSet($oFilter);
$oAuditRule = MetaModel::GetObject('AuditRule', $iRuleIndex);
$oBackButton = ButtonUIBlockFactory::MakeIconLink('fas fa-chevron-left', Dict::S('Back to audit results'), "./audit.php?".$oAppContext->GetForLink());
$oP->AddUiBlock($oBackButton);
$oP->AddUiBlock(TitleUIBlockFactory::MakeForPage($sTitle.$oAuditRule->Get('description')));
$sBlockId = 'audit_errors';
$oP->p("<div id=\"$sBlockId\">");
$oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'list', array('show_obsolete_data' => true));
$oBlock->Display($oP, 1);
$oP->p("</div>");
$sExportUrl = utils::GetAbsoluteUrlAppRoot()."pages/audit.php?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey();
$oP->add_ready_script("$('a[href*=\"pages/UI.php?operation=search\"]').attr('href', '".$sExportUrl."')");
break;
case 'audit':
default:
$oP->SetBreadCrumbEntry('ui-tool-audit', Dict::S('Menu:Audit'), Dict::S('UI:Audit:InteractiveAudit'), '', 'fas fa-stethoscope', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
$oP->AddUiBlock(new Title(Dict::S('UI:Audit:InteractiveAudit')));
$oP->AddUiBlock(TitleUIBlockFactory::MakeForPage(Dict::S('UI:Audit:InteractiveAudit')));
$oTotalBlock = DashletFactory::MakeForDashletBadge('../images/icons/icons8-audit.svg', '#', 0, Dict::S('UI:Audit:Dashboard:ObjectsAudited'));
$oErrorBlock = DashletFactory::MakeForDashletBadge('../images/icons/icons8-delete.svg', '#', 0, Dict::S('UI:Audit:Dashboard:ObjectsInError'));
$oWorkingBlock = DashletFactory::MakeForDashletBadge('../images/icons/icons8-checkmark.svg', '#', 0, Dict::S('UI:Audit:Dashboard:ObjectsValidated'));
$aCSSClasses = ['ibo-dashlet--is-inline','ibo-dashlet-badge'];
$aCSSClasses = ['ibo-dashlet--is-inline', 'ibo-dashlet-badge'];
$oDashletContainerTotal = new DashletContainer();
$oDashletContainerError = new DashletContainer();
$oDashletContainerWorking = new DashletContainer();
$oDashletContainerTotal->AddSubBlock($oTotalBlock)->AddCSSClasses($aCSSClasses);
$oDashletContainerError->AddSubBlock($oErrorBlock)->AddCSSClasses($aCSSClasses);
$oDashletContainerWorking->AddSubBlock($oWorkingBlock)->AddCSSClasses($aCSSClasses);
$oDashboardRow = new DashboardRow();
$oDashboardColumnTotal = new DashboardColumn(false, true);

View File

@@ -1,20 +1,7 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* 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
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Application\UI\Base\Component\Button\ButtonUIBlockFactory;
@@ -22,7 +9,6 @@ use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableUIBlockFactory
use Combodo\iTop\Application\UI\Base\Component\Input\Select\Select;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\SelectOptionUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Title\Title;
use Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContentWithSideContent;
require_once('../approot.inc.php');
@@ -1053,7 +1039,7 @@ $oPage->no_cache();
$oPage->SetBreadCrumbEntry('ui-tool-datamodel', Dict::S('Menu:DataModelMenu'), Dict::S('Menu:DataModelMenu+'), '',
'fas fa-book', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
$oTitle = new Title(Dict::S('UI:Schema:Title'));
$oTitle = TitleUIBlockFactory::MakeForPage(Dict::S('UI:Schema:Title'));
$oPage->AddUiBlock($oTitle);
$oLayout->AddSideHtml("<div class='ibo-datamodel-viewer--classes-list'> ");
DisplayClassesList($oPage, $oLayout, $sContext);

View File

@@ -0,0 +1,46 @@
<?php
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Text;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* Class Text
*
* @package Combodo\iTop\Application\UI\Base\Component\Text
*/
class Text extends UIBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-text';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/text/layout';
/**@var string */
protected $sText;
/**
* Text constructor.
*
* @param string $sText
*/
public function __construct(string $sText, ?string $sId = null)
{
$this->sText = $sText;
parent::__construct($sId);
}
/**
* @return string
*/
public function GetText(): string
{
return $this->sText;
}
}

View File

@@ -1,5 +1,5 @@
<?php
/**
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -7,6 +7,7 @@
namespace Combodo\iTop\Application\UI\Base\Component\Title;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
@@ -14,7 +15,7 @@ use Combodo\iTop\Application\UI\Base\UIBlock;
*
* @package Combodo\iTop\Application\UI\Base\Component\Title
*/
class Title extends UIBlock
class Title extends UIContentBlock
{
// Overloaded constants
/** @inheritDoc */
@@ -31,8 +32,6 @@ class Title extends UIBlock
/** @var string */
public const DEFAULT_ICON_COVER_METHOD = self::ENUM_ICON_COVER_METHOD_CONTAIN;
/** @var string */
protected $sTitle;
/** @var int */
protected $iLevel;
/** @var string */
@@ -44,22 +43,14 @@ class Title extends UIBlock
/**
* @inheritDoc
*/
public function __construct(string $sTitle = '', int $iLevel = 1, ?string $sId = null)
public function __construct(UIBlock $oTitle, int $iLevel = 1, ?string $sId = null)
{
parent::__construct($sId);
$this->sTitle = $sTitle;
$this->iLevel = $iLevel;
$this->sIconUrl = null;
$this->sIconCoverMethod = static::DEFAULT_ICON_COVER_METHOD;
$this->bIsMedallion = true;
}
/**
* @return string
*/
public function GetTitle(): string
{
return $this->sTitle;
$this->AddSubBlock($oTitle);
}
/**

View File

@@ -1,5 +1,5 @@
<?php
/**
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -9,6 +9,8 @@ namespace Combodo\iTop\Application\UI\Base\Component\Title;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Text\Text;
use Combodo\iTop\Application\UI\Base\UIBlock;
class TitleUIBlockFactory extends AbstractUIBlockFactory
{
@@ -17,7 +19,7 @@ class TitleUIBlockFactory extends AbstractUIBlockFactory
public static function MakeForPage(string $sTitle, ?string $sId = null)
{
return new Title($sTitle, 1, $sId);
return new Title(new Text($sTitle), 1, $sId);
}
public static function MakeForPageWithIcon(
@@ -25,7 +27,7 @@ class TitleUIBlockFactory extends AbstractUIBlockFactory
?string $sId = null
)
{
$oTitle = new Title($sTitle, 1, $sId);
$oTitle = new Title(new Text($sTitle), 1, $sId);
$oTitle->SetIcon($sIconUrl, $sIconCoverMethod, $bIsMedallion);
return $oTitle;
@@ -33,6 +35,11 @@ class TitleUIBlockFactory extends AbstractUIBlockFactory
public static function MakeNeutral(string $sTitle, int $iLevel = 1, ?string $sId = null)
{
return new Title($sTitle, $iLevel, $sId);
return new Title(new Text($sTitle), $iLevel, $sId);
}
public static function MakeStandard(UIBlock $oTitle, int $iLevel = 1, ?string $sId = null)
{
return new Title($oTitle, $iLevel, $sId);
}
}

View File

@@ -0,0 +1,5 @@
{# @copyright Copyright (C) 2010-2021 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
{{ oUIBlock.GetText() }}
{% endapply %}

View File

@@ -8,7 +8,9 @@
<div class="ibo-title--content">
{% block iboPageTitleText %}
<h{{ oUIBlock.GetLevel() }} class="ibo-title--text title is-size-{{ oUIBlock.GetLevel() + 2 }}">
{{ oUIBlock.GetTitle() }}
{% for oSubBlock in oUIBlock.GetSubBlocks() %}
{{ render_block(oSubBlock, {aPage: aPage}) }}
{% endfor %}
</h{{ oUIBlock.GetLevel() }}>
{% endblock %}
</div>