mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-20 07:42:17 +02:00
N°2060 [WIP] Initialisation of the portal application:
- Refactor kernel bootstrapping: - Make bin/console from SF work - Make iTopPortalEditUrlMaker / iTopPortalViewUrlMaker work again - Add classmap to /application in composer.json
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
// Load current environment
|
||||
if (file_exists(__DIR__ . '/../../approot.inc.php'))
|
||||
{
|
||||
require_once __DIR__ . '/../../approot.inc.php'; // When in env-xxxx folder
|
||||
@@ -44,7 +45,7 @@ else
|
||||
{
|
||||
require_once __DIR__ . '/../../../approot.inc.php'; // When in datamodels/x.x folder
|
||||
}
|
||||
require_once APPROOT . '/application/startup.inc.php';
|
||||
require_once APPROOT . 'application/startup.inc.php';
|
||||
|
||||
// Protection against setup in the following configuration : ITIL Ticket with Enhanced Portal selected but neither UserRequest or Incident. Which would crash the portal.
|
||||
if (!class_exists('UserRequest') && !class_exists('Incident'))
|
||||
@@ -56,4 +57,5 @@ if (!class_exists('UserRequest') && !class_exists('Incident'))
|
||||
$sDir = basename(__DIR__);
|
||||
define('PORTAL_ID', $sDir);
|
||||
|
||||
require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/index.php';
|
||||
// Load frontal
|
||||
require_once MODULESROOT . 'itop-portal-base/index.php';
|
||||
|
||||
@@ -1,29 +1,38 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2018 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
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
/**
|
||||
* Copyright (C) 2013-2019 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
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Portal\Kernel;
|
||||
|
||||
/**
|
||||
* main.itop-portal.php
|
||||
* iTopPortalEditUrlMaker
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @author Bruno Da Silva <bruno.dasilva@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class iTopPortalEditUrlMaker implements iDBObjectURLMaker
|
||||
{
|
||||
private static $oKernel;
|
||||
|
||||
/**
|
||||
* Generate an (absolute) URL to an object, either in view or edit mode.
|
||||
* Returns null if the current user is not allowed to view / edit object.
|
||||
@@ -39,47 +48,19 @@ class iTopPortalEditUrlMaker implements iDBObjectURLMaker
|
||||
*/
|
||||
public static function PrepareObjectURL($sClass, $iId, $sMode)
|
||||
{
|
||||
require_once APPROOT . '/lib/silex/vendor/autoload.php';
|
||||
require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/providers/urlgeneratorserviceprovider.class.inc.php';
|
||||
require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/helpers/urlgeneratorhelper.class.inc.php';
|
||||
require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/providers/scopevalidatorserviceprovider.class.inc.php';
|
||||
require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/helpers/scopevalidatorhelper.class.inc.php';
|
||||
require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/helpers/securityhelper.class.inc.php';
|
||||
require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/helpers/applicationhelper.class.inc.php';
|
||||
|
||||
// Using a static var allows to preserve the object through function calls
|
||||
static $oApp = null;
|
||||
static $sPortalId = null;
|
||||
|
||||
// Initializing Silex app (partially for faster execution)
|
||||
// TODO: This should be factorised with itop-portal-base/portal/web/index.php into the ApplicationHelper class.
|
||||
if ($oApp === null)
|
||||
{
|
||||
// Retrieving portal id
|
||||
$sPortalId = basename(__DIR__);
|
||||
require_once APPROOT . 'lib/composer-vendor/autoload.php';
|
||||
require_once MODULESROOT . 'itop-portal-base/portal/config/bootstrap.php';
|
||||
|
||||
// Initializing Silex framework
|
||||
$oApp = new Silex\Application();
|
||||
// Registering optional silex components
|
||||
$oApp->register(new Combodo\iTop\Portal\Provider\UrlGeneratorServiceProvider());
|
||||
$oApp->register(new Combodo\iTop\Portal\Provider\ScopeValidatorServiceProvider(), array(
|
||||
'scope_validator.scopes_path' => utils::GetCachePath(),
|
||||
'scope_validator.scopes_filename' => $sPortalId . '.scopes.php',
|
||||
'scope_validator.instance_name' => $sPortalId
|
||||
));
|
||||
$oKernel = self::GetKernelInstance();
|
||||
$oContainer = $oKernel->getContainer();
|
||||
|
||||
// Preparing portal foundations (partially)
|
||||
// ...
|
||||
Combodo\iTop\Portal\Helper\ApplicationHelper::LoadRouters();
|
||||
Combodo\iTop\Portal\Helper\ApplicationHelper::RegisterRoutes($oApp);
|
||||
// ...
|
||||
/** @var string $sPortalId */
|
||||
$sPortalId = $oContainer->getParameter('combodo.portal.instance.id');
|
||||
|
||||
// Loading portal scopes from the module design
|
||||
Combodo\iTop\Portal\Helper\ApplicationHelper::LoadScopesConfiguration($oApp, new ModuleDesign($sPortalId));
|
||||
}
|
||||
|
||||
/** @var \Combodo\iTop\Portal\Helper\UrlGenerator $oUrlGenerator */
|
||||
$oUrlGenerator = $oApp['url_generator'];
|
||||
/** @var \Combodo\iTop\Portal\Routing\UrlGenerator $oUrlGenerator */
|
||||
$oUrlGenerator = $oContainer->get('url_generator');
|
||||
/** @var \Combodo\iTop\Portal\Helper\SecurityHelper $oSecurityHelper */
|
||||
$oSecurityHelper = $oContainer->get('security_helper');
|
||||
|
||||
// The object is reachable in the specified mode (edit/view)
|
||||
//
|
||||
@@ -88,7 +69,7 @@ class iTopPortalEditUrlMaker implements iDBObjectURLMaker
|
||||
switch($sMode)
|
||||
{
|
||||
case 'view':
|
||||
if(!ContextTag::Check('GUI:Portal') || Combodo\iTop\Portal\Helper\SecurityHelper::IsActionAllowed($oApp, UR_ACTION_READ, $sClass, $iId))
|
||||
if(!ContextTag::Check('GUI:Portal') || $oSecurityHelper->IsActionAllowed(UR_ACTION_READ, $sClass, $iId))
|
||||
{
|
||||
$sObjectQueryString = $oUrlGenerator->generate('p_object_view', array('sObjectClass' => $sClass, 'sObjectId' => $iId));
|
||||
}
|
||||
@@ -97,11 +78,11 @@ class iTopPortalEditUrlMaker implements iDBObjectURLMaker
|
||||
case 'edit':
|
||||
default:
|
||||
// Checking if user is allowed to edit object, if not we check if it can at least view it.
|
||||
if(!ContextTag::Check('GUI:Portal') || Combodo\iTop\Portal\Helper\SecurityHelper::IsActionAllowed($oApp, UR_ACTION_MODIFY, $sClass, $iId))
|
||||
if(!ContextTag::Check('GUI:Portal') || $oSecurityHelper->IsActionAllowed(UR_ACTION_MODIFY, $sClass, $iId))
|
||||
{
|
||||
$sObjectQueryString = $oUrlGenerator->generate('p_object_edit', array('sObjectClass' => $sClass, 'sObjectId' => $iId));
|
||||
}
|
||||
elseif(!ContextTag::Check('GUI:Portal') || Combodo\iTop\Portal\Helper\SecurityHelper::IsActionAllowed($oApp, UR_ACTION_READ, $sClass, $iId))
|
||||
elseif(!ContextTag::Check('GUI:Portal') || $oSecurityHelper->IsActionAllowed(UR_ACTION_READ, $sClass, $iId))
|
||||
{
|
||||
$sObjectQueryString = $oUrlGenerator->generate('p_object_view', array('sObjectClass' => $sClass, 'sObjectId' => $iId));
|
||||
}
|
||||
@@ -144,12 +125,31 @@ class iTopPortalEditUrlMaker implements iDBObjectURLMaker
|
||||
{
|
||||
return static::PrepareObjectURL($sClass, $iId, 'edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kernel singleton
|
||||
*
|
||||
* @return \Combodo\iTop\Portal\Kernel
|
||||
* @since 2.7.0
|
||||
*/
|
||||
private static function GetKernelInstance()
|
||||
{
|
||||
if(self::$oKernel === null)
|
||||
{
|
||||
self::$oKernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
|
||||
self::$oKernel->boot();
|
||||
}
|
||||
|
||||
return self::$oKernel;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hyperlinks to the "view" of the object (vs edition)
|
||||
* @author denis
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @author Bruno Da Silva <bruno.dasilva@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class iTopPortalViewUrlMaker extends iTopPortalEditUrlMaker
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user