mise en place de ssoitems (fixes ##31089)

This commit is contained in:
afornerot 2020-11-19 15:08:51 +01:00
parent e115929020
commit fb98a703c0
13 changed files with 129 additions and 15 deletions

View File

@ -86,6 +86,8 @@
<variable type='oui/non' name='ninegate_ssosynchrogroup' description="Générer automatiquement les groupes en fonction d'un attribut SSO"><value>oui</value></variable>
<variable type='string' name='ninegate_ssoreqgroup' description="Attribut SSO associé à la notion de groupe" mandatory='True'><value>user_groups</value></variable>
<variable type='oui/non' name='ninegate_ssosynchroitem' description="Associer automatiquement les items en fonction d'un attribut SSO"><value>non</value></variable>
<variable type='string' name='ninegate_ssoreqitem' description="Attribut SSO associé à la notion d'item" mandatory='True'><value></value></variable>
<variable type='oui/non' name='ninegate_syncldap' description="Synchroniser Ninegate vers votre Annuaire CadolesLDAP"><value>non</value></variable>
<variable type='string' name='ninegate_ldaptemplate' description="Modèle d'annuaire"><value>scribe</value></variable>
@ -431,6 +433,8 @@
<target type='variable'>ninegate_ssosynchrogroup</target>
<target type='variable'>ninegate_ssoreqgroup</target>
<target type='variable'>ninegate_ssosynchroitem</target>
<target type='variable'>ninegate_ssoreqitem</target>
<target type='variable'>ninegate_syncldap</target>
<target type='variable'>ninegate_ldaptemplate</target>
@ -524,6 +528,8 @@
<target type='variable'>ninegate_ssosynchrogroup</target>
<target type='variable'>ninegate_ssoreqgroup</target>
<target type='variable'>ninegate_ssosynchroitem</target>
<target type='variable'>ninegate_ssoreqitem</target>
</condition>
<condition name='hidden_if_in' source='ninegate_syncldap'>
@ -591,6 +597,13 @@
<target type='variable'>ninegate_ssoreqgroup</target>
</condition>
<!-- AFFICHAGE EN FONCTION DE SSO SYNCHRO ITEM -->
<condition name='hidden_if_in' source='ninegate_ssosynchroitem'>
<param>non</param>
<target type='variable'>ninegate_ssoreqitem</target>
</condition>
<!-- AFFICHAGE EN FONCTION DE CADOLESLDAP -->
<fill name='calc_val' target='ninegate_pwdadmin'>
<param type='eole' hidden='False'>cadolesldap_pwdadmin</param>

View File

@ -150,6 +150,19 @@ class SecurityController extends Controller
// Sauvegarde des attributes en session
$this->get('session')->set('attributes', $attributes);
// Sauvegarde des ssoitems en session
$ssoitems=[];
if($this->getParameter('ssosynchroitem')) {
$user_attr_cas_item=$this->getParameter('user_attr_cas_item');
if(array_key_exists($user_attr_cas_item,$attributes)) {
if(!is_array($attributes[$user_attr_cas_item])) {
$attributes[$user_attr_cas_item]=[$attributes[$user_attr_cas_item]];
}
$ssoitems=$attributes[$user_attr_cas_item];
}
}
$this->get('session')->set('ssoitems', $ssoitems);
// Autoconnexion
// Récupérer le token de l'utilisateur
$token = new UsernamePasswordToken($user, null, "main", $user->getRoles());

View File

@ -61,7 +61,7 @@ class TestRestCommand extends Command
// only = liste des informations désirés = user, items, bookmarks, groups, alerts, calendars
$apiurl = $url."/rest/user/".$login;
$this->writeln($apiurl);
$response = \Unirest\Request::post($apiurl,$headers,["key"=>$masterapikey,"only"=>"user,items,bookmarks"]);
$response = \Unirest\Request::post($apiurl,$headers,["key"=>$masterapikey,"only"=>"user,items,bookmarks","ssoitems"=>"ninegate,toto"]);
dump($response->body);
$this->writeln('');

View File

@ -26,7 +26,7 @@ class CoreController extends Controller
$itemcategorys=null;
if($item_activate) {
$em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys);
$em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,$this->get('session')->get('ssoitems'));
return $this->render('CadolesPortalBundle:Page:noportal.html.twig',[
'useheader' => true,
'usemenu' => false,

View File

@ -35,10 +35,14 @@ class RestController extends Controller
// key = clé d'accès de l'api
// only = paramétre optionnel
// only = liste des informations désirés = user, items, bookmarks, groups, alerts, calendars
// ssoitems = paramétre optionnel
// ssoitems = liste des items issu du ssoitems
public function userAction($login, Request $request)
{
$key=$request->get('key');
$only=($request->get('only')?explode(",",$request->get('only')):"");
$ssoitems=($request->get('ssoitems')?explode(",",$request->get('ssoitems')):"");
// Vérification de la clé
$realkey = $this->getParameter("apikeyninegate");
@ -73,7 +77,7 @@ class RestController extends Controller
$itemcategorys=null;
$weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/";
$em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,4);
$em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,$ssoitems,4);
//$this->getDoctrine()->getRepository("CadolesPortalBundle:Page")->getPagesUser($user,null,$entity,$pagesuser,$pagesadmin,$groupsshared);
// Construction de la réponse
@ -147,7 +151,7 @@ class RestController extends Controller
}
if($only==""||in_array("alerts",$only)) {
$alerts=$em->getRepository("CadolesPortalBundle:Alert")->getUserAlerts($user,null,null);
$alerts=$em->getRepository("CadolesPortalBundle:Alert")->getUserAlerts($user,null,null,$ssoitems);
foreach($alerts as $alert) {
$tmp=[];
$tmp["id"] = $alert->getId();

View File

@ -67,7 +67,12 @@ class ItemController extends Controller
$data = new Item();
// Création du formulaire
$form = $this->createForm(ItemType::class,$data,array("mode"=>"submit","labelniveau01" => $this->GetParameter("labelsniveau01"),));
$form = $this->createForm(ItemType::class,$data,array(
"mode" => "submit",
"labelniveau01" => $this->GetParameter("labelsniveau01"),
"ssosynchroitem" => $this->GetParameter("ssosynchroitem"),
"user_attr_cas_item" => $this->GetParameter("user_attr_cas_item")
));
// Récupération des data du formulaire
$form->handleRequest($request);
@ -113,9 +118,11 @@ class ItemController extends Controller
// Création du formulaire
$form = $this->createForm(ItemType::class,$data,array(
"mode" => "update",
"idicon" => ($data->getIcon()?$data->getIcon()->getId():null),
"labelniveau01" => $this->GetParameter("labelsniveau01"),
"mode" => "update",
"idicon" => ($data->getIcon()?$data->getIcon()->getId():null),
"labelniveau01" => $this->GetParameter("labelsniveau01"),
"ssosynchroitem" => $this->GetParameter("ssosynchroitem"),
"user_attr_cas_item" => $this->GetParameter("user_attr_cas_item")
));
// Récupération des data du formulaire

View File

@ -599,7 +599,7 @@ class PagewidgetController extends Controller
}
// Profilage
$itemsordered = $this->em->getRepository("CadolesPortalBundle:Item")->getUserItems($this->user,$bookmarks,$items,$itemcategorys,$iditemcategory,$withbookmark,false);
$itemsordered = $this->em->getRepository("CadolesPortalBundle:Item")->getUserItems($this->user,$bookmarks,$items,$itemcategorys,$iditemcategory,$this->get('session')->get('ssoitems'),$withbookmark,false);
}
// Render
@ -637,7 +637,7 @@ class PagewidgetController extends Controller
}
// Profilage
$itemsordered = $this->em->getRepository("CadolesPortalBundle:Item")->getUserItems($this->user,$bookmarks,$items,$itemcategorys,null,0,true);
$itemsordered = $this->em->getRepository("CadolesPortalBundle:Item")->getUserItems($this->user,$bookmarks,$items,$itemcategorys,null,$this->get('session')->get('ssoitems'),0,true);
}
// Render
@ -671,7 +671,7 @@ class PagewidgetController extends Controller
}
// Profilage
$alertsordered=$this->em->getRepository("CadolesPortalBundle:Alert")->getUserAlerts($this->user,$idalertcategory,$alertcategoryfilter);
$alertsordered=$this->em->getRepository("CadolesPortalBundle:Alert")->getUserAlerts($this->user,$idalertcategory,$alertcategoryfilter,$this->get('session')->get('ssoitems'));
}
// Render

View File

@ -102,6 +102,13 @@ class Item
*/
private $roles;
/**
* @var string
*
* @ORM\Column(name="ssoitem", type="string", nullable=true)
*/
private $ssoitem;
/**
* @ORM\ManyToOne(targetEntity="Icon", inversedBy="items")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
@ -619,4 +626,28 @@ class Item
{
return $this->alerts;
}
/**
* Set ssoitem
*
* @param string $ssoitem
*
* @return Item
*/
public function setSsoitem($ssoitem)
{
$this->ssoitem = $ssoitem;
return $this;
}
/**
* Get ssoitem
*
* @return string
*/
public function getSsoitem()
{
return $this->ssoitem;
}
}

View File

@ -133,6 +133,13 @@ class ItemType extends AbstractType
])
->add('idicon', HiddenType::class,['mapped'=> false,'data' => $options["idicon"]]);
if($options["ssosynchroitem"]) {
$builder->add("ssoitem", TextType::class, [
"label" => "Visible si attribut SSO ".$options["user_attr_cas_item"]." égale à",
"disabled" => ($options["mode"]=="delete"?true:false),
]);
}
}
public function configureOptions(OptionsResolver $resolver)
@ -142,6 +149,8 @@ class ItemType extends AbstractType
'mode' => "string",
'idicon' => "string",
'labelniveau01' => "string",
'ssosynchroitem' => "string",
'user_attr_cas_item' => "string",
]);
}
}

View File

@ -40,7 +40,7 @@ class AlertRepository extends EntityRepository
;
}
public function getUserAlerts($user,$idalertcategory,$alertcategoryfilter) {
public function getUserAlerts($user,$idalertcategory,$alertcategoryfilter,$ssoitems) {
// Profilage
$roles=($user?$user->getRoles():["ROLE_ANONYME"]);
$niveau01=($user?$user->getNiveau01():null);
@ -122,7 +122,7 @@ class AlertRepository extends EntityRepository
$bookmarks=null;
$items=null;
$itemcategorys=null;
$this->_em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,4);
$this->getEntityManager()->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,$ssoitems,4);
foreach($items as $item) {
$qb = $this->createQueryBuilder('a');
$qb->select('alert')

View File

@ -7,7 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection;
class ItemRepository extends EntityRepository
{
public function getUserItems($user,&$bookmarks,&$itemsordered,&$itemcategorys,$iditemcategory=null,$withbookmark=1,$fgessential=false) {
public function getUserItems($user,&$bookmarks,&$itemsordered,&$itemcategorys,$iditemcategory=null,$ssoitems,$withbookmark=1,$fgessential=false) {
// Profilage
$roles=($user?$user->getRoles():["ROLE_ANONYME"]);
$groups=($user?$user->getGroups():[]);
@ -106,6 +106,31 @@ class ItemRepository extends EntityRepository
}
}
// Récupération des items par ssoitem
foreach($ssoitems as $ssoitem) {
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('item')
->from("CadolesPortalBundle:Item", 'item')
->where("item.ssoitem=:ssoitem ")
->setParameter("ssoitem",$ssoitem);
if($iditemcategory && $itemcategoryfilter) {
$qb->andWhere("item.itemcategory=:itemcategory")
->setParameter("itemcategory",$itemcategoryfilter);
}
if($fgessential) {
$qb->andWhere("item.essential=:flag")
->setParameter("flag",true);
}
$itemsssoitems=$qb->getQuery()->getResult();
foreach($itemsssoitems as $itemssoitem) {
if(!$bookmarksitems->contains($itemssoitem) && !$items->contains($itemssoitem)) $items->add($itemssoitem);
}
}
// Trie des items
$itemsordered = $items->getIterator();
$itemsordered->uasort(function ($first, $second) {

View File

@ -61,6 +61,10 @@
{{ form_row(form.roles) }}
{{ form_row(form.niveau01s) }}
{{ form_row(form.groups) }}
{% if form.ssoitem is defined %}
{{ form_row(form.ssoitem) }}
{% endif %}
{{ form_row(form.color) }}
<div id="diviconsel" class="col-md-12 text-left" style="height:140px; padding:20px; text-align:center; background-color: {{ item.color ? "#"~item.color : '#'~color['main'] }};">

View File

@ -495,10 +495,18 @@ parameters:
ssosynchrogroup: true
user_attr_cas_group: %%ninegate_ssoreqgroup
%else
ssosynchrogroup: fase
ssosynchrogroup: false
user_attr_cas_group:
%end if
%if %%getVar("ninegate_ssosynchroitem", 'non') == "oui"
ssosynchroitem: true
user_attr_cas_item: %%ninegate_ssoreqitem
%else
ssosynchroitem: false
user_attr_cas_item:
%end if
%if %%is_defined("ninegate_smtpport")
mailer_port: '%%ninegate_smtpport'
mailer_encryption: %%ninegate_smtpencryption