Skip to content

Commit ccb1ca9

Browse files
committed
Merge remote-tracking branch 'origin/support/2.7' into support/3.1
2 parents 025af92 + 44290db commit ccb1ca9

File tree

3 files changed

+81
-37
lines changed

3 files changed

+81
-37
lines changed

datamodels/2.x/itop-portal-base/portal/config/routes/user_profile_brick.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
# You should have received a copy of the GNU Affero General Public License
1616
# along with iTop. If not, see <http://www.gnu.org/licenses/>
1717

18+
p_user_profile_brick_edit_person:
19+
path: '/user/edit_person'
20+
defaults:
21+
_controller: 'Combodo\iTop\Portal\Controller\UserProfileBrickController::EditPerson'
22+
1823
p_user_profile_brick:
1924
path: '/user/{sBrickId}'
2025
defaults:

datamodels/2.x/itop-portal-base/portal/src/Controller/UserProfileBrickController.php

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use Symfony\Component\HttpKernel\Exception\HttpException;
3636
use UserRights;
3737
use utils;
38-
38+
use Dict;
3939
/**
4040
* Class UserProfileBrickController
4141
*
@@ -66,34 +66,9 @@ public function DisplayAction(Request $oRequest, $sBrickId)
6666
$oRequestManipulator = $this->get('request_manipulator');
6767
/** @var \Combodo\iTop\Portal\Helper\ObjectFormHandlerHelper $ObjectFormHandler */
6868
$ObjectFormHandler = $this->get('object_form_handler');
69-
/** @var \Combodo\iTop\Portal\Brick\BrickCollection $oBrickCollection */
70-
$oBrickCollection = $this->get('brick_collection');
69+
$oBrick = $this->GetBrick($sBrickId);
7170

72-
// If the brick id was not specified, we get the first one registered that is an instance of UserProfileBrick as default
73-
if ($sBrickId === null)
74-
{
75-
/** @var \Combodo\iTop\Portal\Brick\PortalBrick $oTmpBrick */
76-
foreach ($oBrickCollection->GetBricks() as $oTmpBrick)
77-
{
78-
if ($oTmpBrick instanceof UserProfileBrick)
79-
{
80-
$oBrick = $oTmpBrick;
81-
}
82-
}
83-
84-
// We make sure a UserProfileBrick was found
85-
if (!isset($oBrick) || $oBrick === null)
86-
{
87-
$oBrick = new UserProfileBrick();
88-
//throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'UserProfileBrick : Brick could not be loaded as there was no UserProfileBrick loaded in the application.');
89-
}
90-
}
91-
else
92-
{
93-
$oBrick = $oBrickCollection->GetBrickById($sBrickId);
94-
}
95-
96-
$aData = array();
71+
$aData = array();
9772

9873
// Setting form mode regarding the demo mode parameter
9974
$bDemoMode = MetaModel::GetConfig()->Get('demo_mode');
@@ -130,10 +105,11 @@ public function DisplayAction(Request $oRequest, $sBrickId)
130105
$oCurContact = UserRights::GetContactObject();
131106
$sCurContactClass = get_class($oCurContact);
132107
$sCurContactId = $oCurContact->GetKey();
133-
108+
$aForm = $oBrick->GetForm();
109+
$aForm['submit_endpoint'] = $this->generateUrl('p_user_profile_brick_edit_person', ['sBrickId' => $sBrickId]);
134110
// Preparing forms
135111
$aData['forms']['contact'] = $ObjectFormHandler->HandleForm($oRequest, $sFormMode, $sCurContactClass, $sCurContactId,
136-
$oBrick->GetForm());
112+
$aForm);
137113
$aData['forms']['preferences'] = $this->HandlePreferencesForm($oRequest, $sFormMode);
138114
// - If user can change password, we display the form
139115
$aData['forms']['password'] = (UserRights::CanChangePassword()) ? $this->HandlePasswordForm($oRequest, $sFormMode) : null;
@@ -150,6 +126,35 @@ public function DisplayAction(Request $oRequest, $sBrickId)
150126
return $oResponse;
151127
}
152128

129+
public function EditPerson(Request $oRequest)
130+
{
131+
/** @var \Combodo\iTop\Portal\Helper\ObjectFormHandlerHelper $oObjectFormHandler */
132+
$oObjectFormHandler = $this->get('object_form_handler');
133+
/** @var \Combodo\iTop\Portal\Helper\SecurityHelper $oSecurityHelper */
134+
$oSecurityHelper = $this->get('security_helper');
135+
136+
$oCurContact = UserRights::GetContactObject();
137+
$sObjectClass = get_class($oCurContact);
138+
$sObjectId = $oCurContact->GetKey();
139+
140+
// Checking security layers
141+
// Warning : This is a dirty quick fix to allow editing its own contact information
142+
$bAllowWrite = ($sObjectClass === 'Person' && $sObjectId == UserRights::GetContactId());
143+
if (!$oSecurityHelper->IsActionAllowed(UR_ACTION_MODIFY, $sObjectClass, $sObjectId) && !$bAllowWrite) {
144+
IssueLog::Warning(__METHOD__ . ' at line ' . __LINE__ . ' : User #' . UserRights::GetUserId() . ' not allowed to modify ' . $sObjectClass . '::' . $sObjectId . ' object.');
145+
throw new HttpException(Response::HTTP_NOT_FOUND, Dict::S('UI:ObjectDoesNotExist'));
146+
}
147+
148+
$aForm = $this->GetBrick()->GetForm();
149+
$aForm['submit_endpoint'] = $this->generateUrl('p_user_profile_brick_edit_person');
150+
151+
$aData = ['sMode' => 'edit'];
152+
$aData['form'] = $oObjectFormHandler->HandleForm($oRequest, $aData['sMode'], $sObjectClass, $sObjectId, $aForm);
153+
154+
return new JsonResponse($aData);
155+
}
156+
157+
153158
/**
154159
* @param \Symfony\Component\HttpFoundation\Request $oRequest
155160
* @param string $sFormMode
@@ -394,4 +399,34 @@ public function HandlePictureForm(Request $oRequest)
394399
return $aFormData;
395400
}
396401

402+
/**
403+
* @param $sBrickId
404+
* @return \Combodo\iTop\Portal\Brick\PortalBrick|UserProfileBrick
405+
* @throws \Combodo\iTop\Portal\Brick\BrickNotFoundException
406+
*/
407+
public function GetBrick($sBrickId = null)
408+
{
409+
/** @var \Combodo\iTop\Portal\Brick\BrickCollection $oBrickCollection */
410+
$oBrickCollection = $this->get('brick_collection');
411+
412+
// If the brick id was not specified, we get the first one registered that is an instance of UserProfileBrick as default
413+
if ($sBrickId === null) {
414+
/** @var \Combodo\iTop\Portal\Brick\PortalBrick $oTmpBrick */
415+
foreach ($oBrickCollection->GetBricks() as $oTmpBrick) {
416+
if ($oTmpBrick instanceof UserProfileBrick) {
417+
$oBrick = $oTmpBrick;
418+
}
419+
}
420+
421+
// We make sure a UserProfileBrick was found
422+
if (!isset($oBrick) || $oBrick === null) {
423+
$oBrick = new UserProfileBrick();
424+
//throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'UserProfileBrick : Brick could not be loaded as there was no UserProfileBrick loaded in the application.');
425+
}
426+
} else {
427+
$oBrick = $oBrickCollection->GetBrickById($sBrickId);
428+
}
429+
return $oBrick;
430+
}
431+
397432
}

datamodels/2.x/itop-portal-base/portal/src/Helper/ObjectFormHandlerHelper.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,17 @@ public function HandleForm(Request $oRequest, $sMode, $sObjectClass, $sObjectId
242242
case static::ENUM_MODE_CREATE:
243243
case static::ENUM_MODE_EDIT:
244244
case static::ENUM_MODE_VIEW:
245-
$sFormEndpoint = $this->oUrlGenerator->generate(
246-
'p_object_'.$sMode,
247-
array(
248-
'sObjectClass' => $sObjectClass,
249-
'sObjectId' => $sObjectId,
250-
)
251-
);
245+
if(array_key_exists('submit_endpoint', $aFormProperties)) {
246+
$sFormEndpoint = $aFormProperties['submit_endpoint'];
247+
} else {
248+
$sFormEndpoint = $this->oUrlGenerator->generate(
249+
'p_object_' . $sMode,
250+
array(
251+
'sObjectClass' => $sObjectClass,
252+
'sObjectId' => $sObjectId,
253+
)
254+
);
255+
}
252256
break;
253257

254258
case static::ENUM_MODE_APPLY_STIMULUS:

0 commit comments

Comments
 (0)