mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-21 08:12:26 +02:00
N°2060 [WIP] Initialisation of the portal application:
- Simplify PortalUrlMaker to avoid necessity to copy most of the code. Drawback: BC break, check migration notes.
- Fix multiple portal instances (in the same running process)
- Refactor portal constants into env. vars
- Fix cache path for services (ScopeValidator & LifecycleValidator)
- Change evalution order of the portal id ($_ENV['PORTAL_ID'] > $_GET('portal_id'] > PORTAL_ID)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2019 Combodo SARL
|
||||
*
|
||||
@@ -20,7 +19,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Portal\Kernel;
|
||||
use Combodo\iTop\Portal\UrlMaker\AbstractPortalUrlMaker;
|
||||
|
||||
require_once APPROOT.'/lib/composer-vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* iTopPortalEditUrlMaker
|
||||
@@ -29,119 +30,10 @@ use Combodo\iTop\Portal\Kernel;
|
||||
* @author Bruno Da Silva <bruno.dasilva@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class iTopPortalEditUrlMaker implements iDBObjectURLMaker
|
||||
class iTopPortalEditUrlMaker extends AbstractPortalUrlMaker
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @param string $sClass The class of the object
|
||||
* @param int $iId The identifier of the object
|
||||
* @param string $sMode edit|view
|
||||
*
|
||||
* @return string | null
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static function PrepareObjectURL($sClass, $iId, $sMode)
|
||||
{
|
||||
require_once APPROOT . 'lib/composer-vendor/autoload.php';
|
||||
require_once MODULESROOT . 'itop-portal-base/portal/config/bootstrap.php';
|
||||
|
||||
$oKernel = self::GetKernelInstance();
|
||||
$oContainer = $oKernel->getContainer();
|
||||
|
||||
/** @var string $sPortalId */
|
||||
$sPortalId = $oContainer->getParameter('combodo.portal.instance.id');
|
||||
|
||||
/** @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)
|
||||
//
|
||||
// Note: Scopes only apply when URL check is triggered from the portal GUI.
|
||||
$sObjectQueryString = null;
|
||||
switch($sMode)
|
||||
{
|
||||
case 'view':
|
||||
if(!ContextTag::Check('GUI:Portal') || $oSecurityHelper->IsActionAllowed(UR_ACTION_READ, $sClass, $iId))
|
||||
{
|
||||
$sObjectQueryString = $oUrlGenerator->generate('p_object_view', array('sObjectClass' => $sClass, 'sObjectId' => $iId));
|
||||
}
|
||||
break;
|
||||
|
||||
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') || $oSecurityHelper->IsActionAllowed(UR_ACTION_MODIFY, $sClass, $iId))
|
||||
{
|
||||
$sObjectQueryString = $oUrlGenerator->generate('p_object_edit', array('sObjectClass' => $sClass, 'sObjectId' => $iId));
|
||||
}
|
||||
elseif(!ContextTag::Check('GUI:Portal') || $oSecurityHelper->IsActionAllowed(UR_ACTION_READ, $sClass, $iId))
|
||||
{
|
||||
$sObjectQueryString = $oUrlGenerator->generate('p_object_view', array('sObjectClass' => $sClass, 'sObjectId' => $iId));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$sPortalAbsoluteUrl = utils::GetAbsoluteUrlModulePage($sPortalId, 'index.php');
|
||||
if($sObjectQueryString === null)
|
||||
{
|
||||
$sUrl = null;
|
||||
}
|
||||
elseif (strpos($sPortalAbsoluteUrl, '?') !== false)
|
||||
{
|
||||
// Removing generated url query parameters so it can be replaced with those from the absolute url
|
||||
// Mostly necessary when iTop instance has multiple portals
|
||||
if(strpos($sObjectQueryString, '?') !== false)
|
||||
{
|
||||
$sObjectQueryString = substr($sObjectQueryString, 0, strpos($sObjectQueryString, '?'));
|
||||
}
|
||||
|
||||
$sUrl = substr($sPortalAbsoluteUrl, 0, strpos($sPortalAbsoluteUrl, '?')).$sObjectQueryString.substr($sPortalAbsoluteUrl, strpos($sPortalAbsoluteUrl, '?'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$sUrl = $sPortalAbsoluteUrl.$sObjectQueryString;
|
||||
}
|
||||
|
||||
return $sUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sClass
|
||||
* @param $iId
|
||||
*
|
||||
* @return null|string
|
||||
*
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static function MakeObjectURL($sClass, $iId)
|
||||
{
|
||||
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;
|
||||
}
|
||||
/** @var string PORTAL_ID */
|
||||
const PORTAL_ID = 'itop-portal';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,6 +45,9 @@ class iTopPortalEditUrlMaker implements iDBObjectURLMaker
|
||||
*/
|
||||
class iTopPortalViewUrlMaker extends iTopPortalEditUrlMaker
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function MakeObjectURL($sClass, $iId)
|
||||
{
|
||||
return static::PrepareObjectURL($sClass, $iId, 'view');
|
||||
|
||||
Reference in New Issue
Block a user