mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
Merge remote-tracking branch 'origin/support/2.7' into support/3.1
This commit is contained in:
@@ -15,6 +15,11 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with iTop. If not, see <http://www.gnu.org/licenses/>
|
# along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
|
p_user_profile_brick_edit_person:
|
||||||
|
path: '/user/edit_person'
|
||||||
|
defaults:
|
||||||
|
_controller: 'Combodo\iTop\Portal\Controller\UserProfileBrickController::EditPerson'
|
||||||
|
|
||||||
p_user_profile_brick:
|
p_user_profile_brick:
|
||||||
path: '/user/{sBrickId}'
|
path: '/user/{sBrickId}'
|
||||||
defaults:
|
defaults:
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use UserRights;
|
use UserRights;
|
||||||
use utils;
|
use utils;
|
||||||
|
use Dict;
|
||||||
/**
|
/**
|
||||||
* Class UserProfileBrickController
|
* Class UserProfileBrickController
|
||||||
*
|
*
|
||||||
@@ -66,34 +66,9 @@ class UserProfileBrickController extends BrickController
|
|||||||
$oRequestManipulator = $this->get('request_manipulator');
|
$oRequestManipulator = $this->get('request_manipulator');
|
||||||
/** @var \Combodo\iTop\Portal\Helper\ObjectFormHandlerHelper $ObjectFormHandler */
|
/** @var \Combodo\iTop\Portal\Helper\ObjectFormHandlerHelper $ObjectFormHandler */
|
||||||
$ObjectFormHandler = $this->get('object_form_handler');
|
$ObjectFormHandler = $this->get('object_form_handler');
|
||||||
/** @var \Combodo\iTop\Portal\Brick\BrickCollection $oBrickCollection */
|
$oBrick = $this->GetBrick($sBrickId);
|
||||||
$oBrickCollection = $this->get('brick_collection');
|
|
||||||
|
|
||||||
// If the brick id was not specified, we get the first one registered that is an instance of UserProfileBrick as default
|
$aData = array();
|
||||||
if ($sBrickId === null)
|
|
||||||
{
|
|
||||||
/** @var \Combodo\iTop\Portal\Brick\PortalBrick $oTmpBrick */
|
|
||||||
foreach ($oBrickCollection->GetBricks() as $oTmpBrick)
|
|
||||||
{
|
|
||||||
if ($oTmpBrick instanceof UserProfileBrick)
|
|
||||||
{
|
|
||||||
$oBrick = $oTmpBrick;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We make sure a UserProfileBrick was found
|
|
||||||
if (!isset($oBrick) || $oBrick === null)
|
|
||||||
{
|
|
||||||
$oBrick = new UserProfileBrick();
|
|
||||||
//throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'UserProfileBrick : Brick could not be loaded as there was no UserProfileBrick loaded in the application.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$oBrick = $oBrickCollection->GetBrickById($sBrickId);
|
|
||||||
}
|
|
||||||
|
|
||||||
$aData = array();
|
|
||||||
|
|
||||||
// Setting form mode regarding the demo mode parameter
|
// Setting form mode regarding the demo mode parameter
|
||||||
$bDemoMode = MetaModel::GetConfig()->Get('demo_mode');
|
$bDemoMode = MetaModel::GetConfig()->Get('demo_mode');
|
||||||
@@ -130,10 +105,11 @@ class UserProfileBrickController extends BrickController
|
|||||||
$oCurContact = UserRights::GetContactObject();
|
$oCurContact = UserRights::GetContactObject();
|
||||||
$sCurContactClass = get_class($oCurContact);
|
$sCurContactClass = get_class($oCurContact);
|
||||||
$sCurContactId = $oCurContact->GetKey();
|
$sCurContactId = $oCurContact->GetKey();
|
||||||
|
$aForm = $oBrick->GetForm();
|
||||||
|
$aForm['submit_endpoint'] = $this->generateUrl('p_user_profile_brick_edit_person', ['sBrickId' => $sBrickId]);
|
||||||
// Preparing forms
|
// Preparing forms
|
||||||
$aData['forms']['contact'] = $ObjectFormHandler->HandleForm($oRequest, $sFormMode, $sCurContactClass, $sCurContactId,
|
$aData['forms']['contact'] = $ObjectFormHandler->HandleForm($oRequest, $sFormMode, $sCurContactClass, $sCurContactId,
|
||||||
$oBrick->GetForm());
|
$aForm);
|
||||||
$aData['forms']['preferences'] = $this->HandlePreferencesForm($oRequest, $sFormMode);
|
$aData['forms']['preferences'] = $this->HandlePreferencesForm($oRequest, $sFormMode);
|
||||||
// - If user can change password, we display the form
|
// - If user can change password, we display the form
|
||||||
$aData['forms']['password'] = (UserRights::CanChangePassword()) ? $this->HandlePasswordForm($oRequest, $sFormMode) : null;
|
$aData['forms']['password'] = (UserRights::CanChangePassword()) ? $this->HandlePasswordForm($oRequest, $sFormMode) : null;
|
||||||
@@ -150,6 +126,35 @@ class UserProfileBrickController extends BrickController
|
|||||||
return $oResponse;
|
return $oResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function EditPerson(Request $oRequest)
|
||||||
|
{
|
||||||
|
/** @var \Combodo\iTop\Portal\Helper\ObjectFormHandlerHelper $oObjectFormHandler */
|
||||||
|
$oObjectFormHandler = $this->get('object_form_handler');
|
||||||
|
/** @var \Combodo\iTop\Portal\Helper\SecurityHelper $oSecurityHelper */
|
||||||
|
$oSecurityHelper = $this->get('security_helper');
|
||||||
|
|
||||||
|
$oCurContact = UserRights::GetContactObject();
|
||||||
|
$sObjectClass = get_class($oCurContact);
|
||||||
|
$sObjectId = $oCurContact->GetKey();
|
||||||
|
|
||||||
|
// Checking security layers
|
||||||
|
// Warning : This is a dirty quick fix to allow editing its own contact information
|
||||||
|
$bAllowWrite = ($sObjectClass === 'Person' && $sObjectId == UserRights::GetContactId());
|
||||||
|
if (!$oSecurityHelper->IsActionAllowed(UR_ACTION_MODIFY, $sObjectClass, $sObjectId) && !$bAllowWrite) {
|
||||||
|
IssueLog::Warning(__METHOD__ . ' at line ' . __LINE__ . ' : User #' . UserRights::GetUserId() . ' not allowed to modify ' . $sObjectClass . '::' . $sObjectId . ' object.');
|
||||||
|
throw new HttpException(Response::HTTP_NOT_FOUND, Dict::S('UI:ObjectDoesNotExist'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$aForm = $this->GetBrick()->GetForm();
|
||||||
|
$aForm['submit_endpoint'] = $this->generateUrl('p_user_profile_brick_edit_person');
|
||||||
|
|
||||||
|
$aData = ['sMode' => 'edit'];
|
||||||
|
$aData['form'] = $oObjectFormHandler->HandleForm($oRequest, $aData['sMode'], $sObjectClass, $sObjectId, $aForm);
|
||||||
|
|
||||||
|
return new JsonResponse($aData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Symfony\Component\HttpFoundation\Request $oRequest
|
* @param \Symfony\Component\HttpFoundation\Request $oRequest
|
||||||
* @param string $sFormMode
|
* @param string $sFormMode
|
||||||
@@ -394,4 +399,34 @@ class UserProfileBrickController extends BrickController
|
|||||||
return $aFormData;
|
return $aFormData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $sBrickId
|
||||||
|
* @return \Combodo\iTop\Portal\Brick\PortalBrick|UserProfileBrick
|
||||||
|
* @throws \Combodo\iTop\Portal\Brick\BrickNotFoundException
|
||||||
|
*/
|
||||||
|
public function GetBrick($sBrickId = null)
|
||||||
|
{
|
||||||
|
/** @var \Combodo\iTop\Portal\Brick\BrickCollection $oBrickCollection */
|
||||||
|
$oBrickCollection = $this->get('brick_collection');
|
||||||
|
|
||||||
|
// If the brick id was not specified, we get the first one registered that is an instance of UserProfileBrick as default
|
||||||
|
if ($sBrickId === null) {
|
||||||
|
/** @var \Combodo\iTop\Portal\Brick\PortalBrick $oTmpBrick */
|
||||||
|
foreach ($oBrickCollection->GetBricks() as $oTmpBrick) {
|
||||||
|
if ($oTmpBrick instanceof UserProfileBrick) {
|
||||||
|
$oBrick = $oTmpBrick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We make sure a UserProfileBrick was found
|
||||||
|
if (!isset($oBrick) || $oBrick === null) {
|
||||||
|
$oBrick = new UserProfileBrick();
|
||||||
|
//throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'UserProfileBrick : Brick could not be loaded as there was no UserProfileBrick loaded in the application.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$oBrick = $oBrickCollection->GetBrickById($sBrickId);
|
||||||
|
}
|
||||||
|
return $oBrick;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,13 +242,17 @@ class ObjectFormHandlerHelper
|
|||||||
case static::ENUM_MODE_CREATE:
|
case static::ENUM_MODE_CREATE:
|
||||||
case static::ENUM_MODE_EDIT:
|
case static::ENUM_MODE_EDIT:
|
||||||
case static::ENUM_MODE_VIEW:
|
case static::ENUM_MODE_VIEW:
|
||||||
$sFormEndpoint = $this->oUrlGenerator->generate(
|
if(array_key_exists('submit_endpoint', $aFormProperties)) {
|
||||||
'p_object_'.$sMode,
|
$sFormEndpoint = $aFormProperties['submit_endpoint'];
|
||||||
array(
|
} else {
|
||||||
'sObjectClass' => $sObjectClass,
|
$sFormEndpoint = $this->oUrlGenerator->generate(
|
||||||
'sObjectId' => $sObjectId,
|
'p_object_' . $sMode,
|
||||||
)
|
array(
|
||||||
);
|
'sObjectClass' => $sObjectClass,
|
||||||
|
'sObjectId' => $sObjectId,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case static::ENUM_MODE_APPLY_STIMULUS:
|
case static::ENUM_MODE_APPLY_STIMULUS:
|
||||||
|
|||||||
Reference in New Issue
Block a user