LSaddon::dyngroup: Add showDyngroupMembers view function

This commit is contained in:
Benjamin Renard 2024-06-19 17:54:39 +02:00
parent 4235c05b12
commit 41af4f9305
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
9 changed files with 262 additions and 1 deletions

View file

@ -29,6 +29,9 @@
// Dynamic group object type
define('DYNGROUP_OBJECT_TYPE', 'LSdyngroup');
// Dynamic group member object type
define('DYNGROUP_MEMBER_OBJECT_TYPE', 'LSpeople');
/*
* Members DN attributes
*/

View file

@ -40,6 +40,16 @@ $GLOBALS['LSobjects']['LSdyngroup'] = array (
'label' => 'Dynamic groups',
'customActions' => array (
'showDyngroupMembers' => array (
'label' => 'Show members',
'icon' => 'group',
'function' => 'showDyngroupMembers',
'noConfirmation' => true,
'disableOnSuccessMsg' => true,
'rights' => array (
'admin',
),
),
'showTechInfo' => array (
'function' => 'showTechInfo',
'label' => 'Show technical information',

View file

@ -0,0 +1,11 @@
#showDyngroupMembers {
margin-left: 1em;
}
#showDyngroupMembers table.LStable tr.error {
background-color: var(--error-color);
}
#showDyngroupMembers table.LStable .center {
text-align: center;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

View file

@ -361,6 +361,68 @@ function triggerUpdateDynGroupsMembersCacheOnUserChanges(&$user, &$changed_attrs
return !$error;
}
/**
* Show dyngroup members
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param LSldapObject $ldapObject The LSldapObject
*
* @return array|false array of memberUid URI attribute values or false in case of error
*/
function showDyngroupMembers($ldapObject) {
$member_dns = ensureIsArray($ldapObject -> attrs[ DYNGROUP_MEMBER_DN_ATTRIBUTE ] -> getValue());
$cache_member_dns = ensureIsArray($ldapObject -> attrs[ DYNGROUP_MEMBER_DN_STATIC_ATTRIBUTE ] -> getValue());
$member_uids = ensureIsArray($ldapObject -> attrs[ DYNGROUP_MEMBER_UID_ATTRIBUTE ] -> getValue());
$cache_member_uids = ensureIsArray($ldapObject -> attrs[ DYNGROUP_MEMBER_UID_STATIC_ATTRIBUTE ] -> getValue());
sort($member_dns);
sort($cache_member_dns);
sort($member_uids);
sort($cache_member_uids);
LStemplate :: assign('member_dns', $member_dns);
LStemplate :: assign('cache_member_dns', $cache_member_dns);
LStemplate :: assign('member_uids', $member_uids);
LStemplate :: assign('cache_member_uids', $cache_member_uids);
if (
defined('DYNGROUP_MEMBER_OBJECT_TYPE')
&& LSsession :: loadLSobject(constant('DYNGROUP_MEMBER_OBJECT_TYPE'))
) {
$member_type = constant('DYNGROUP_MEMBER_OBJECT_TYPE');
$uid2dn = (
LSconfig :: get("LSobjects.$member_type.rdn")."=%{uid},".
LSconfig :: get("LSobjects.$member_type.container_dn").",".
LSsession :: getTopDn()
);
LStemplate :: assign('member_object_type', $member_type);
LStemplate :: assign('uid2dn', $uid2dn);
}
else {
LStemplate :: assign('member_object_type', null);
}
LStemplate :: assign('pagetitle', getFData(_('%{name}: members'), $ldapObject -> getDisplayName()));
$LSview_actions=array();
$LSview_actions['return'] = array (
'label' => _('Go back'),
'url' => 'object/'.$ldapObject->getType().'/'.urlencode($ldapObject->getDn()),
'action' => 'view'
);
LStemplate :: assign('LSview_actions', $LSview_actions);
if (LSsession :: loadLSclass('LSform')) {
LSform :: loadDependenciesDisplayView();
}
LStemplate :: addCssFile('showDyngroupMembers.css');
LSsession :: setTemplate('showDyngroupMembers.tpl');
// Display template
LSsession :: displayTemplate();
exit();
}
if (php_sapi_name() != 'cli')
return true;

View file

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: LdapSaisie\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2024-06-05 12:29+0200\n"
"PO-Revision-Date: 2024-06-19 17:52+0200\n"
"Last-Translator: Benjamin Renard <brenard@easter-eggs.com>\n"
"Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise."
"org>\n"
@ -322,6 +322,7 @@ msgstr "Vos modifications ont été enregistrées."
#: includes/addons/LSaddons.mail.php:565
#: includes/addons/LSaddons.showSupportInfo.php:78
#: includes/addons/LSaddons.dyngroup.php:408
#: includes/addons/LSaddons.accesslog.php:248
#: includes/addons/LSaddons.showTechInfo.php:128
msgid "Go back"
@ -407,6 +408,10 @@ msgstr ""
"délai de quelques minutes pourra être nécessaire pour que vos modifications "
"soient prises en compte sur ces groupes."
#: includes/addons/LSaddons.dyngroup.php:404
msgid "%{name}: members"
msgstr "%{name} : membres"
#: includes/addons/LSaddons.posix.php:27
msgid "POSIX Support: The constant %{const} is not defined."
msgstr "Support POSIX : La constante %{const} n'est pas définie."
@ -3727,6 +3732,11 @@ msgstr "Identifiant"
msgid "Imported objects"
msgstr "Objets importés"
#: templates/default/showDyngroupMembers.tpl:12
#: templates/default/showDyngroupMembers.tpl:68
msgid "In cache"
msgstr "En cache"
#: templates/default/recoverpassword.tpl:13 templates/default/login.tpl:12
msgid "LDAP server"
msgstr "Serveur LDAP"
@ -3747,6 +3757,16 @@ msgstr "Légende :"
msgid "Logout"
msgstr "Déconnexion"
#: templates/default/showDyngroupMembers.tpl:63
#: templates/default/showDyngroupMembers.tpl:67
msgid "Members's DN"
msgstr "DNs des membres"
#: templates/default/showDyngroupMembers.tpl:7
#: templates/default/showDyngroupMembers.tpl:11
msgid "Members's UID"
msgstr "UID des membres"
#: templates/default/LSmail.tpl:28
msgid "Message"
msgstr "Message"
@ -3776,6 +3796,14 @@ msgstr "Aucun champ."
msgid "No imported object"
msgstr "Aucun objet importé"
#: templates/default/showDyngroupMembers.tpl:113
msgid "No member's DN."
msgstr "Aucun DN de membre."
#: templates/default/showDyngroupMembers.tpl:57
msgid "No member's UID."
msgstr "Aucun UID de membre."
#: templates/default/import.tpl:65
msgid "No value"
msgstr "Aucune valeur"

View file

@ -250,6 +250,7 @@ msgstr ""
#: includes/addons/LSaddons.mail.php:565
#: includes/addons/LSaddons.showSupportInfo.php:78
#: includes/addons/LSaddons.dyngroup.php:408
#: includes/addons/LSaddons.accesslog.php:248
#: includes/addons/LSaddons.showTechInfo.php:128
msgid "Go back"
@ -320,6 +321,10 @@ msgid ""
"necessary to handle your changes on this groups."
msgstr ""
#: includes/addons/LSaddons.dyngroup.php:404
msgid "%{name}: members"
msgstr ""
#: includes/addons/LSaddons.posix.php:27
msgid "POSIX Support: The constant %{const} is not defined."
msgstr ""
@ -3203,6 +3208,11 @@ msgstr ""
msgid "Imported objects"
msgstr ""
#: templates/default/showDyngroupMembers.tpl:12
#: templates/default/showDyngroupMembers.tpl:68
msgid "In cache"
msgstr ""
#: templates/default/recoverpassword.tpl:13 templates/default/login.tpl:12
msgid "LDAP server"
msgstr ""
@ -3223,6 +3233,16 @@ msgstr ""
msgid "Logout"
msgstr ""
#: templates/default/showDyngroupMembers.tpl:63
#: templates/default/showDyngroupMembers.tpl:67
msgid "Members's DN"
msgstr ""
#: templates/default/showDyngroupMembers.tpl:7
#: templates/default/showDyngroupMembers.tpl:11
msgid "Members's UID"
msgstr ""
#: templates/default/LSmail.tpl:28
msgid "Message"
msgstr ""
@ -3252,6 +3272,14 @@ msgstr ""
msgid "No imported object"
msgstr ""
#: templates/default/showDyngroupMembers.tpl:113
msgid "No member's DN."
msgstr ""
#: templates/default/showDyngroupMembers.tpl:57
msgid "No member's UID."
msgstr ""
#: templates/default/import.tpl:65
msgid "No value"
msgstr ""

View file

@ -0,0 +1,119 @@
{extends file='ls:base_connected.tpl'}
{block name="content"}
<div id='showDyngroupMembers'>
<h1>{$pagetitle}</h1>
{include file='ls:LSview_actions.tpl'}
<h2>{tr msg="Members's UID"}</h2>
<table class="LStable">
<thead>
<tr>
<th>{tr msg="Members's UID"}</th>
<th>{tr msg="In cache"}</th>
</tr>
</thead>
<tbody>
{if $member_uids || $cache_member_uids}
{foreach $member_uids as $uid}
{if in_array($uid, $cache_member_uids)}
<tr>
<td>
{if $member_object_type}
<a href="object/{$member_object_type}/{getFData format=$uid2dn data=$uid|escape:'url'}">{$uid}</a>
{else}
{$uid}
{/if}
</td>
<td class="center">✓</td>
</tr>
{else}
<tr class="error">
<td>
{if $member_object_type}
<a href="object/{$member_object_type}/{getFData format=$uid2dn data=$uid|escape:'url'}">{$uid}</a>
{else}
{$uid}
{/if}
</td>
<td class="center">X</td>
</tr>
{/if}
{/foreach}
{foreach $cache_member_uids as $uid}
{if in_array($uid, $member_uids)}{continue}{/if}
<tr class="error">
<td class="center">X</td>
<td>
{if $member_object_type}
<a href="object/{$member_object_type}/{getFData format=$uid2dn data=$uid|escape:'url'}">{$uid}</a>
{else}
{$uid}
{/if}
</td>
</tr>
{/foreach}
{else}
<tr>
<td colspan="2">{tr msg="No member's UID."}</td>
</tr>
{/if}
</tbody>
</table>
<h2>{tr msg="Members's DN"}</h2>
<table class="LStable">
<thead>
<tr>
<th>{tr msg="Members's DN"}</th>
<th>{tr msg="In cache"}</th>
</tr>
</thead>
<tbody>
{if $member_dns || $cache_member_dns}
{foreach $member_dns as $dn}
{if in_array($dn, $cache_member_dns)}
<tr>
<td>
{if $member_object_type}
<a href="object/{$member_object_type}/{$dn|escape:'url'}">{$dn}</a>
{else}
{$dn}
{/if}
</td>
<td class="center">✓</td>
</tr>
{else}
<tr class="error">
<td>
{if $member_object_type}
<a href="object/{$member_object_type}/{$dn|escape:'url'}">{$dn}</a>
{else}
{$dn}
{/if}
</td>
<td class="center">X</td>
</tr>
{/if}
{/foreach}
{foreach $cache_member_dns as $dn}
{if in_array($dn, $member_dns)}{continue}{/if}
<tr class="error">
<td class="center">X</td>
<td>
{if $member_object_type}
<a href="object/{$member_object_type}/{$dn|escape:'url'}">{$dn}</a>
{else}
{$dn}
{/if}
</td>
</tr>
{/foreach}
{else}
<tr>
<td colspan="2">{tr msg="No member's DN."}</td>
</tr>
{/if}
</tbody>
</table>
</div>
{/block}