3535use Symfony \Component \HttpKernel \Exception \HttpException ;
3636use UserRights ;
3737use 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}
0 commit comments