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

Add EVENTs to get additionals user attributes from LDAP and show them #1660

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions account_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
<?php echo get_enum_element( 'access_levels', current_user_get_access_level() ); ?>
</td>
</tr>
<?php event_signal( 'EVENT_USER_ADDITIONAL_ATTRIBUTES', $u_username ); ?>
</fieldset>
</table>
</div>
Expand Down
7 changes: 6 additions & 1 deletion core/events_inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@

'EVENT_USER_AVATAR' => EVENT_TYPE_FIRST,

'EVENT_USER_ADDITIONAL_ATTRIBUTES' => EVENT_TYPE_OUTPUT,

# Bug filter events
'EVENT_FILTER_FIELDS' => EVENT_TYPE_DEFAULT,
'EVENT_FILTER_COLUMNS' => EVENT_TYPE_DEFAULT,
Expand Down Expand Up @@ -158,5 +160,8 @@
# Authentication Events
'EVENT_AUTH_USER_FLAGS' => EVENT_TYPE_FIRST,

'EVENT_CRONJOB' => EVENT_TYPE_EXECUTE
'EVENT_CRONJOB' => EVENT_TYPE_EXECUTE,

# LDAP Events
'EVENT_LDAP_USER_FIELDS' => EVENT_TYPE_DEFAULT
) );
15 changes: 15 additions & 0 deletions core/ldap_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ function ldap_cache_user_data( $p_username ) {
config_get_global( 'ldap_realname_field' )
);

# add attrs specified by plugins
$t_all_plugin_fields_event = event_signal( 'EVENT_LDAP_USER_FIELDS' );
foreach( $t_all_plugin_fields_event as $t_plugin => $t_all_plugin_fields_event2 ) {
foreach( $t_all_plugin_fields_event2 as $t_callback => $t_all_plugin_fields ) {
if( is_array( $t_all_plugin_fields ) ) {
foreach( $t_all_plugin_fields as $t_plugin_field ) {
if( ! in_array( $t_plugin_field, $t_search_attrs, true ) ) {
array_push( $t_search_attrs, $t_plugin_field );
log_event( LOG_LDAP, 'Attribute = %d, added (by %d plugin)', $t_plugin_field, $t_plugin );
}
}
}
}
}

log_event( LOG_LDAP, 'Searching for ' . $t_search_filter );
$t_sr = @ldap_search( $t_ds, $t_ldap_root_dn, $t_search_filter, $t_search_attrs );
if( $t_sr === false ) {
Expand Down
42 changes: 42 additions & 0 deletions docbook/Developers_Guide/en-US/Events_Reference_Account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,48 @@
</blockquote>
</blockquote>

<blockquote id="dev.eventref.user.additional.attributes">
<title>EVENT_USER_ADDITIONAL_ATTRIBUTES (Output)</title>

<blockquote>
<para>
This event allows plugins to display additional attributes on
the Account page. It is triggered immediately after the last
core element.
</para>

<para>
Any output here should be defining appropriate rows and columns for the
surrounding <filename>&lt;table&gt;</filename> elements.
</para>

<itemizedlist>
<title>Parameters</title>
<listitem><para>&lt;String&gt;: User Name</para></listitem>
</itemizedlist>

<itemizedlist>
<title>Return Value</title>
<listitem><para>&lt;String&gt;: HTML code to output.</para></listitem>
</itemizedlist>
</blockquote>
</blockquote>

<blockquote id="dev.eventref.user.fields">
<title>EVENT_LDAP_USER_FIELDS (Default)</title>

<blockquote>
<para>
This event allow to add LDAP fields in cached user attributes
</para>

<itemizedlist>
<title>Return Value</title>
<listitem><para>&lt;Array&gt;: List of LDAP fields</para></listitem>
</itemizedlist>
</blockquote>
</blockquote>

</section>

</section>
Expand Down
1 change: 1 addition & 0 deletions view_user_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
</td>
</tr>
<?php } ?>
<?php event_signal( 'EVENT_USER_ADDITIONAL_ATTRIBUTES', $u_username ); ?>
</fieldset>
</table>
</div>
Expand Down