From 5145c8c3238eaca1d0a6b80adc9f7c8e07d6bfef Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Tue, 13 Sep 2016 13:09:34 +0530 Subject: [PATCH] Fix #12320 : Copying a user does not copy usergroup Signed-off-by: Deven Bansod --- libraries/server_privileges.lib.php | 44 +++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 059595e619..932d7a3d13 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -2951,6 +2951,33 @@ function PMA_getUserGroupCount() return $user_group_count; } +/** + * Returns name of user group that user is part of + * + * @param string $username User name + * + * @return mixed usergroup if found or null if not found + */ +function PMA_getUserGroupForUser($username) +{ + $cfgRelation = PMA_getRelationsParam(); + $user_table = Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['users']); + $sql_query = 'SELECT `usergroup` FROM ' . $user_table + . ' WHERE `username` = \'' . $username . '\'' + . ' LIMIT 1'; + + $usergroup = $GLOBALS['dbi']->fetchValue( + $sql_query, 0, 0, $GLOBALS['controllink'] + ); + + if ($usergroup === false) { + return null; + } + + return $usergroup; +} + /** * This function return the extra data array for the ajax behavior * @@ -3129,8 +3156,15 @@ function PMA_getChangeLoginInformationHtmlForm($username, $hostname) . '' . "\n" . '' . "\n" - . '
' . "\n" + . 'value="' . htmlspecialchars($hostname) . '" />' . "\n"; + + $usergroup = PMA_getUserGroupForUser($username); + if ($usergroup !== null) { + $html_output .= '' . "\n"; + } + + $html_output .= '
' . "\n" . '' . "\n" . __('Change login information / Copy user account') . '' . "\n" @@ -4292,6 +4326,12 @@ function PMA_addUser( ); } + // Copy the user group while copying a user + $old_usergroup = + $_REQUEST['old_usergroup'] ? $_REQUEST['old_usergroup'] : null; + PMA_setUserGroup($_REQUEST['username'], $old_usergroup); + + if (isset($create_user_real)) { $queries[] = $create_user_real; }