Permalink
Browse files

Added capability to completely remove user from an organization

  • Loading branch information...
1 parent f0bec81 commit 9a9b3076f2abc1a1809cc5bc1a46918259e5ff4d @winskie winskie committed Jan 11, 2017
@@ -4565,6 +4565,34 @@ function echo_user_edit_membership_js( $edited_Organization )
/**
+ * Initialize JavaScript for AJAX loading of popup window to confirm removal of user from organization
+ *
+ * @param object Organization
+ */
+function echo_user_remove_membership_js( $edited_Organization )
+{
+ global $admin_url, $current_User;
+
+ if( ! $current_User->check_perm( 'orgs', 'edit', false, $edited_Organization ) )
+ { // User must has an edit perm to remove user in organization:
+ return;
+ }
+
+ // Initialize JavaScript to build and open window:
+ echo_modalwindow_js();
+
+ // Initialize variables for the file "evo_user_deldata.js":
+ echo '<script type="text/javascript">
+ var evo_js_lang_loading = \''.TS_('Loading...').'\';
+ var evo_js_lang_remove_user_membership = \''.TS_('WARNING').'\';
+ var evo_js_lang_remove = \''.TS_('Continue').'\';
+ var evo_js_user_org_ajax_url = \''.$admin_url.'\';
+ var evo_js_crumb_organization = \''.get_crumb( 'organization' ).'\';
+ </script>';
+}
+
+
+/**
* Check invitation code and display error on incorrect code
* This function is used on registration form
*
@@ -6025,6 +6053,10 @@ function user_td_org_actions( $org_ID, $user_ID )
'onclick' => 'return user_edit( '.$org_ID.', '.$user_ID.' );'
);
$r .= action_icon( T_('Edit membership...'), 'edit', '#', NULL, NULL, NULL, $link_params );
+ $link_params = array(
+ 'onclick' => 'return user_remove( '.$org_ID.', '.$user_ID.' );'
+ );
+ $r .= action_icon( T_('Remove user from organization'), 'delete', '#', NULL, NULL, NULL, $link_params );
}
else
{
@@ -252,6 +252,41 @@
header_redirect( '?ctrl=organizations&action=edit&org_ID='.$edited_Organization->ID.'&filter=refresh', 303 ); // Will EXIT
// We have EXITed already at this point!!
break;
+
+ case 'unlink_user':
+ // Remove user from organization:
+
+ // Check that this action request is not a CSRF hacked request:
+ $Session->assert_received_crumb( 'organization' );
+
+ // Check permission:
+ $current_User->check_perm( 'orgs', 'edit', true, $edited_Organization );
+
+ $user_login = param( 'user_login', 'string', NULL );
+ param_check_not_empty( 'user_login', T_('Please enter the login of the user you wish to add.') );
+ if( ! empty( $user_login ) )
+ { // If the login is entered:
+ $UserCache = & get_UserCache();
+ $login_User = & $UserCache->get_by_login( $user_login );
+ if( empty( $login_User ) )
+ { // Wrong entered login:
+ param_error( 'user_login', sprintf( T_('User &laquo;%s&raquo; does not exist!'), $user_login ) );
+ }
+ }
+
+ if( ! param_errors_detected() )
+ { // Link user only when request has no errors:
+ $result = $DB->query( 'DELETE FROM T_users__user_org WHERE uorg_user_ID = '.$login_User->ID.' AND uorg_org_ID = '.$edited_Organization->ID );
+ if( $result )
+ { // Display a message after successful linking:
+ $Messages->add( sprintf( T_('%s removed removed from the organization.'), $login_User->get( 'preferredname') ), 'success');
+ }
+ }
+
+ // Redirect so that a reload doesn't write to the DB twice:
+ header_redirect( '?ctrl=organizations&action=edit&org_ID='.$edited_Organization->ID.'&filter=refresh', 303 ); // Will EXIT
+ // We have EXITed already at this point!!
+ break;
}
if( $display_mode != 'js')
@@ -308,6 +343,7 @@
// Init JS for form to add user to organization:
echo_user_add_organization_js( $edited_Organization );
echo_user_edit_membership_js( $edited_Organization );
+ echo_user_remove_membership_js( $edited_Organization );
break;
case 'add_user':
@@ -330,6 +366,14 @@
$AdminUI->disp_view( 'users/views/_organization_user_edit.form.php' );
break;
+ case 'remove_user':
+ if( $display_mode == 'js' )
+ {
+ $debug = false;
+ $debug_jslog = false;
+ }
+ $AdminUI->disp_view( 'users/views/_organization_user_remove.form.php' );
+ break;
default:
// No specific request, list all organizations:
@@ -0,0 +1,45 @@
+<?php
+/**
+ * This file implements the dialog to confirm removal of user from organization.
+ *
+ * This file is part of the evoCore framework - {@link http://evocore.net/}
+ * See also {@link https://github.com/b2evolution/b2evolution}.
+ *
+ * @license GNU GPL v2 - {@link http://b2evolution.net/about/gnu-gpl-license}
+ *
+ * @copyright (c)2003-2016 by Francois Planque - {@link http://fplanque.com/}
+ */
+if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
+
+
+/**
+ * @var Organization
+ */
+global $edited_Organization;
+
+$Form = new Form( NULL, 'orguser_removemembership' );
+
+$Form->begin_form( 'fform' );
+
+ $Form->add_crumb( 'organization' );
+
+ $Form->hiddens_by_key( get_memorized( 'action' ) ); // (this allows to come back to the right list order & page)
+
+ $user_ID = param( 'user_ID', 'integer' );
+ $UserCache = & get_UserCache();
+ $edited_User = & $UserCache->get_by_ID( $user_ID );
+ $org_data = $edited_User->get_organizations_data();
+
+ ?>
+ <p>This will remove <?php echo $edited_User->get( 'preferredname' );?> from the organization. Would you like to continue?</p>
+ <?php
+
+ $Form->hidden( 'user_login', $edited_User->get('login') );
+
+$buttons = array();
+if( $current_User->check_perm( 'orgs', 'edit', false, $edited_Organization ) )
+{ // Display a button to confirm removal of user from the organization
+ $buttons[] = array( 'submit', 'actionArray[unlink_user]', T_('Continue'), 'SaveButton' );
+}
+$Form->end_form( $buttons );
+?>
Oops, something went wrong.
Oops, something went wrong.
@@ -70,4 +70,31 @@ function user_edit( org_ID, user_ID )
});
return false;
+}
+
+function user_remove( org_ID, user_ID )
+{
+ openModalWindow( '<span class="loader_img loader_user_deldata absolute_center" title="' + evo_js_lang_loading + '"></span>',
+ '450px', '', true,
+ '<span class="text-danger">' + evo_js_lang_remove_user_membership + '</span>', evo_js_lang_remove, true );
+
+ jQuery.ajax(
+ {
+ type: 'POST',
+ url: evo_js_user_org_ajax_url,
+ data:
+ {
+ 'ctrl': 'organizations',
+ 'action': 'remove_user',
+ 'user_ID': user_ID,
+ 'display_mode': 'js',
+ 'crumb_user': evo_js_crumb_organization,
+ },
+ success: function( result )
+ {
+ openModalWindow( result, '450px', '', true, '<span class="text-danger">' + evo_js_lang_remove_user_membership + '</span>', evo_js_lang_remove );
+ }
+ });
+
+ return false;
}

0 comments on commit 9a9b307

Please sign in to comment.