Skip to content

Commit

Permalink
Add plugin events for user accounts lifecycle
Browse files Browse the repository at this point in the history
- EVENT_MANAGE_USER_CREATE_FORM
- EVENT_MANAGE_USER_CREATE
- EVENT_MANAGE_USER_UPDATE_FORM
- EVENT_MANAGE_USER_UPDATE
- EVENT_MANAGE_USER_DELETE
- EVENT_MANAGE_USER_PAGE

Fixes #8779
  • Loading branch information
vboctor committed Jan 24, 2016
1 parent f2a8172 commit 04f1850
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/events_inc.php
Expand Up @@ -76,6 +76,16 @@
'EVENT_MANAGE_VERSION_UPDATE' => EVENT_TYPE_EXECUTE,
'EVENT_MANAGE_VERSION_DELETE' => EVENT_TYPE_EXECUTE,

'EVENT_MANAGE_USER_CREATE_FORM' => EVENT_TYPE_EXECUTE,
'EVENT_MANAGE_USER_CREATE' => EVENT_TYPE_EXECUTE,
'EVENT_MANAGE_USER_UPDATE_FORM' => EVENT_TYPE_EXECUTE,
'EVENT_MANAGE_USER_UPDATE' => EVENT_TYPE_EXECUTE,
'EVENT_MANAGE_USER_DELETE' => EVENT_TYPE_EXECUTE,
'EVENT_MANAGE_USER_PAGE' => EVENT_TYPE_EXECUTE,

# TODO: Should we use jquery to insert elements on view page and on forms
# rather than having events that restrict where to insert such elements?
# User account pages
'EVENT_ACCOUNT_PREF_UPDATE_FORM' => EVENT_TYPE_EXECUTE,
'EVENT_ACCOUNT_PREF_UPDATE' => EVENT_TYPE_EXECUTE,
Expand Down
4 changes: 4 additions & 0 deletions core/user_api.php
Expand Up @@ -557,6 +557,8 @@ function user_create( $p_username, $p_password, $p_email = '',
email_signup( $t_user_id, $t_confirm_hash, $p_admin_name );
}

event_signal( 'EVENT_MANAGE_USER_CREATE', array( $t_user_id ) );

return $t_cookie_string;
}

Expand Down Expand Up @@ -649,6 +651,8 @@ function user_delete( $p_user_id ) {

user_ensure_unprotected( $p_user_id );

event_signal( 'EVENT_MANAGE_USER_DELETE', array( $p_user_id ) );

# Remove associated profiles
user_delete_profiles( $p_user_id );

Expand Down
111 changes: 111 additions & 0 deletions docbook/Developers_Guide/en-US/Events_Reference_Manage.xml
Expand Up @@ -212,6 +212,117 @@
</itemizedlist>
</blockquote>
</blockquote>

<blockquote id="dev.eventref.manage.user.createform">
<title>EVENT_MANAGE_USER_CREATE_FORM (Execute)</title>

<blockquote>
<para>
This event allows plugins to do processing or display form elements on
the Create User page. It is triggered immediately before the submit
button.
</para>

<para>
Any output here should follow the format found in manage_user_create_page.php.
</para>
</blockquote>
</blockquote>

<blockquote id="dev.eventref.manage.user.create">
<title>EVENT_MANAGE_USER_CREATE (Execute)</title>

<blockquote>
<para>
This event allows plugins to do post-processing of newly-created
users. This event is triggered for each user created. The
Manage Users create form is one possible case for triggering
such events, but there can be other ways users can be created.
</para>

<itemizedlist>
<title>Parameters</title>
<listitem><para>&lt;Integer&gt;: User ID</para></listitem>
</itemizedlist>
</blockquote>
</blockquote>

<blockquote id="dev.eventref.manage.user.updateform">
<title>EVENT_MANAGE_USER_UPDATE_FORM (Execute)</title>

<blockquote>
<para>
This event allows plugins to do processing or display form
elements in the Manage User page. It is triggered immediately
before the submit button.
</para>

<para>
Any output here should follow the format found in
manage_user_edit_page.php.
</para>

<itemizedlist>
<title>Parameters</title>
<listitem><para>&lt;Integer&gt;: User ID</para></listitem>
</itemizedlist>
</blockquote>
</blockquote>

<blockquote id="dev.eventref.manage.user.update">
<title>EVENT_MANAGE_USER_UPDATE (Execute)</title>

<blockquote>
<para>
This event allows plugins to do post-processing of modified
users. This may be triggered by the Manage User page or some
other path.
</para>

<itemizedlist>
<title>Parameters</title>
<listitem><para>&lt;Integer&gt;: User ID</para></listitem>
</itemizedlist>
</blockquote>
</blockquote>

<blockquote id="dev.eventref.manage.user.delete">
<title>EVENT_MANAGE_USER_DELETE (Execute)</title>

<blockquote>
<para>
This event allows plugins to do pre-processing of user
deletion.
</para>

<itemizedlist>
<title>Parameters</title>
<listitem><para>&lt;Integer&gt;: User ID</para></listitem>
</itemizedlist>
</blockquote>
</blockquote>

<blockquote id="dev.eventref.manage.user.view">
<title>EVENT_MANAGE_USER_PAGE (Execute)</title>

<blockquote>
<para>
This event allows plugins to do processing or display information on
the View User page. It is triggered immediately after the reset password
segment.
</para>

<para>
Any output here should be contained within its own container.
</para>

<itemizedlist>
<title>Parameters</title>
<listitem><para>&lt;Integer&gt;: User ID</para></listitem>
</itemizedlist>
</blockquote>
</blockquote>

</section>

</section>
Expand Down
3 changes: 3 additions & 0 deletions manage_user_create_page.php
Expand Up @@ -113,6 +113,9 @@
<span class="checkbox"><input type="checkbox" id="user-protected" name="protected" /></span>
<span class="label-style"></span>
</div>

<?php event_signal( 'EVENT_MANAGE_USER_CREATE_FORM' ) ?>

<span class="submit-button"><input type="submit" class="button" value="<?php echo lang_get( 'create_user_button' ) ?>" /></span>
</fieldset>
</form>
Expand Down
5 changes: 5 additions & 0 deletions manage_user_edit_page.php
Expand Up @@ -172,6 +172,9 @@
echo '<span class="label-style"></span>';
echo '</div>';
} ?>

<?php event_signal( 'EVENT_MANAGE_USER_UPDATE_FORM', array( $t_user['id'] ) ); ?>

<!-- Submit Button -->
<span class="submit-button"><input type="submit" class="button" value="<?php echo lang_get( 'update_user_button' ) ?>" /></span>
</fieldset>
Expand Down Expand Up @@ -230,6 +233,8 @@
</div>
<?php } ?>

<?php event_signal( 'EVENT_MANAGE_USER_PAGE', array( $t_user_id ) ); ?>

<!-- PROJECT ACCESS (if permissions allow) and user is not ADMINISTRATOR -->
<?php if( access_has_global_level( config_get( 'manage_user_threshold' ) ) &&
!user_is_administrator( $t_user_id ) ) {
Expand Down
2 changes: 2 additions & 0 deletions manage_user_update.php
Expand Up @@ -175,6 +175,8 @@

$t_result = db_query( $t_query, $t_query_params );

event_signal( 'EVENT_MANAGE_USER_UPDATE', array( $c_user_id ) );

if( $f_send_email_notification ) {
lang_push( user_pref_get_language( $f_user_id ) );
$t_changes = '';
Expand Down

0 comments on commit 04f1850

Please sign in to comment.