Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N°7433 - Allow MFA configuration in the portal #670

Merged
merged 18 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 95 additions & 99 deletions datamodels/2.x/itop-portal-base/portal/src/Brick/UserProfileBrick.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@

namespace Combodo\iTop\Portal\Brick;

use DOMFormatException;
use Combodo\iTop\DesignElement;
use DOMFormatException;

/**
* Description of UserProfileBrick
*
* @package Combodo\iTop\Portal\Brick
* @since 2.7.0
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @since 2.7.0
* @package Combodo\iTop\Portal\Brick
*/
class UserProfileBrick extends PortalBrick
{
// Overloaded constants
const DEFAULT_PAGE_TEMPLATE_PATH = 'itop-portal-base/portal/templates/bricks/user-profile/layout.html.twig';
const DEFAULT_TILE_TEMPLATE_PATH = 'itop-portal-base/portal/templates/bricks/user-profile/tile.html.twig';
const DEFAULT_VISIBLE_NAVIGATION_MENU = false;
const DEFAULT_VISIBLE_HOME = false;
const DEFAUT_TITLE = 'Brick:Portal:UserProfile:Title';
const DEFAULT_DECORATION_CLASS_HOME = 'glyphicon glyphicon-user';
const DEFAULT_PAGE_TEMPLATE_PATH = 'itop-portal-base/portal/templates/bricks/user-profile/layout.html.twig';
const DEFAULT_TILE_TEMPLATE_PATH = 'itop-portal-base/portal/templates/bricks/user-profile/tile.html.twig';
const DEFAULT_VISIBLE_NAVIGATION_MENU = false;
const DEFAULT_VISIBLE_HOME = false;
const DEFAUT_TITLE = 'Brick:Portal:UserProfile:Title';
const DEFAULT_DECORATION_CLASS_HOME = 'glyphicon glyphicon-user';
const DEFAULT_DECORATION_CLASS_NAVIGATION_MENU = 'glyphicon glyphicon-user';

/** @var bool DEFAULT_SHOW_PICTURE_FORM */
const DEFAULT_SHOW_PICTURE_FORM = true;
/** @var bool DEFAULT_SHOW_PREFERENCES_FORM */
const DEFAULT_SHOW_PREFERENCES_FORM = true;
/** @var bool DEFAULT_SHOW_PASSWORD_FORM */
const DEFAULT_SHOW_PASSWORD_FORM = true;
const DEFAULT_SHOW_PREFERENCES_FORM = true;
/** @var bool DEFAULT_SHOW_PASSWORD_FORM */
const DEFAULT_SHOW_PASSWORD_FORM = true;

// Overloaded variables
static $sRouteName = 'p_user_profile_brick';
Expand All @@ -67,8 +67,8 @@ public function __construct()
parent::__construct();

$this->aForm = array(
'id' => 'default-user-profile',
'type' => 'zlist',
'id' => 'default-user-profile',
'type' => 'zlist',
'fields' => 'details',
'layout' => null,
);
Expand All @@ -89,67 +89,75 @@ public function GetForm()
/**
*
* @param array $aForm
*
* @return \Combodo\iTop\Portal\Brick\UserProfileBrick
*/
public function SetForm($aForm)
{
$this->aForm = $aForm;

return $this;
}

/**
* @return bool
*/
public function GetShowPictureForm()
{
return $this->bShowPictureForm;
}

/**
* @param $bShowPictureForm
* @return \Combodo\iTop\Portal\Brick\UserProfileBrick
*/
public function SetShowPictureForm($bShowPictureForm)
{
$this->bShowPictureForm = $bShowPictureForm;
return $this;
}

/**
* @return bool
*/
public function GetShowPreferencesForm()
{
return $this->bShowPreferencesForm;
}

/**
* @param $bShowPreferencesForm
* @return \Combodo\iTop\Portal\Brick\UserProfileBrick
*/
public function SetShowPreferencesForm($bShowPreferencesForm)
{
$this->bShowPreferencesForm = $bShowPreferencesForm;
return $this;
}

/**
* @return bool
*/
public function GetShowPasswordForm()
{
return $this->bShowPasswordForm;
}

/**
* @param $bShowPasswordForm
* @return \Combodo\iTop\Portal\Brick\UserProfileBrick
*/
public function SetShowPasswordForm($bShowPasswordForm)
{
$this->bShowPasswordForm = $bShowPasswordForm;
return $this;
}
/**
* @return bool
*/
public function GetShowPictureForm()
{
return $this->bShowPictureForm;
}

/**
* @param $bShowPictureForm
*
* @return \Combodo\iTop\Portal\Brick\UserProfileBrick
*/
public function SetShowPictureForm($bShowPictureForm)
{
$this->bShowPictureForm = $bShowPictureForm;

return $this;
}

/**
* @return bool
*/
public function GetShowPreferencesForm()
{
return $this->bShowPreferencesForm;
}

/**
* @param $bShowPreferencesForm
*
* @return \Combodo\iTop\Portal\Brick\UserProfileBrick
*/
public function SetShowPreferencesForm($bShowPreferencesForm)
{
$this->bShowPreferencesForm = $bShowPreferencesForm;

return $this;
}

/**
* @return bool
*/
public function GetShowPasswordForm()
{
return $this->bShowPasswordForm;
}

/**
* @param $bShowPasswordForm
*
* @return \Combodo\iTop\Portal\Brick\UserProfileBrick
*/
public function SetShowPasswordForm($bShowPasswordForm)
{
$this->bShowPasswordForm = $bShowPasswordForm;

return $this;
}

/**
* Load the brick's data from the xml passed as a ModuleDesignElement.
Expand All @@ -167,76 +175,64 @@ public function LoadFromXml(DesignElement $oMDElement)

// Checking specific elements
/** @var \Combodo\iTop\DesignElement $oBrickSubNode */
foreach ($oMDElement->GetNodes('./*') as $oBrickSubNode)
{
switch ($oBrickSubNode->nodeName)
{
foreach ($oMDElement->GetNodes('./*') as $oBrickSubNode) {
switch ($oBrickSubNode->nodeName) {
case 'form':
// Note : This is inspired by Combodo\iTop\Portal\Helper\ApplicationHelper::LoadFormsConfiguration()
// Enumerating fields
if ($oBrickSubNode->GetOptionalElement('fields') !== null)
{
if ($oBrickSubNode->GetOptionalElement('fields') !== null) {
$this->aForm['type'] = 'custom_list';
$this->aForm['fields'] = array();

/** @var \Combodo\iTop\DesignElement $oFieldNode */
foreach ($oBrickSubNode->GetOptionalElement('fields')->GetNodes('field') as $oFieldNode)
{
foreach ($oBrickSubNode->GetOptionalElement('fields')->GetNodes('field') as $oFieldNode) {
$sFieldId = $oFieldNode->getAttribute('id');
if ($sFieldId !== '')
{
if ($sFieldId !== '') {
$aField = array();
// Parsing field options like read_only, hidden and mandatory
if ($oFieldNode->GetOptionalElement('read_only'))
{
if ($oFieldNode->GetOptionalElement('read_only')) {
$aField['readonly'] = ($oFieldNode->GetOptionalElement('read_only')->GetText('true') === 'true') ? true : false;
}
if ($oFieldNode->GetOptionalElement('mandatory'))
{
if ($oFieldNode->GetOptionalElement('mandatory')) {
$aField['mandatory'] = ($oFieldNode->GetOptionalElement('mandatory')->GetText('true') === 'true') ? true : false;
}
if ($oFieldNode->GetOptionalElement('hidden'))
{
if ($oFieldNode->GetOptionalElement('hidden')) {
$aField['hidden'] = ($oFieldNode->GetOptionalElement('hidden')->GetText('true') === 'true') ? true : false;
}

$this->aForm['fields'][$sFieldId] = $aField;
}
else
{
} else {
throw new DOMFormatException('Field tag must have an id attribute', null, null, $oFieldNode);
}
}
}
// Parsing presentation
if ($oBrickSubNode->GetOptionalElement('twig') !== null)
{
if ($oBrickSubNode->GetOptionalElement('twig') !== null) {
// Extracting the twig template and removing the first and last lines (twig tags)
$sXml = $oBrickSubNode->GetOptionalElement('twig')->Dump(true);
//$sXml = $oMDElement->saveXML($oBrickSubNode->GetOptionalElement('twig'));
$sXml = preg_replace('/^.+\n/', '', $sXml);
$sXml = preg_replace('/\n.+$/', '', $sXml);

$this->aForm['layout'] = array(
'type' => (preg_match('/\{\{|\{\#|\{\%/', $sXml) === 1) ? 'twig' : 'xhtml',
'type' => (preg_match('/\{\{|\{\#|\{\%/', $sXml) === 1) ? 'twig' : 'xhtml',
'content' => $sXml,
);
}
break;

case 'show_picture_form':
case 'show_preferences_form':
case 'show_password_form':
$sConstName = 'DEFAULT_'.strtoupper($oBrickSubNode->nodeName);
$sSetterName = 'Set'.str_replace('_', '', ucwords($oBrickSubNode->nodeName, '_'));
case 'show_picture_form':
case 'show_preferences_form':
case 'show_password_form':
$sConstName = 'DEFAULT_'.strtoupper($oBrickSubNode->nodeName);
$sSetterName = 'Set'.str_replace('_', '', ucwords($oBrickSubNode->nodeName, '_'));

$bNodeValue = ($oBrickSubNode->GetText(constant('static::'.$sConstName)) === 'true') ? true : false;
$this->$sSetterName($bNodeValue);
break;
$bNodeValue = ($oBrickSubNode->GetText(constant('static::'.$sConstName)) === 'true') ? true : false;
$this->$sSetterName($bNodeValue);
break;
}
}

return $this;
}

}
Loading