Merge pull request #12553 from devenbansod/fix_12320

Fix #12320 : Copying a user does not copy usergroup
This commit is contained in:
Michal Čihař 2016-09-16 10:36:41 +02:00 committed by GitHub
commit b5c10991e9
2 changed files with 86 additions and 2 deletions

View File

@ -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)
. '<input type="hidden" name="old_username" '
. 'value="' . htmlspecialchars($username) . '" />' . "\n"
. '<input type="hidden" name="old_hostname" '
. 'value="' . htmlspecialchars($hostname) . '" />' . "\n"
. '<fieldset id="fieldset_change_copy_user">' . "\n"
. 'value="' . htmlspecialchars($hostname) . '" />' . "\n";
$usergroup = PMA_getUserGroupForUser($username);
if ($usergroup !== null) {
$html_output .= '<input type="hidden" name="old_usergroup" '
. 'value="' . htmlspecialchars($usergroup) . '" />' . "\n";
}
$html_output .= '<fieldset id="fieldset_change_copy_user">' . "\n"
. '<legend data-submenu-label="' . __('Login Information') . '">' . "\n"
. __('Change login information / Copy user account')
. '</legend>' . "\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;
}

View File

@ -1638,6 +1638,7 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase
{
$username = "pma_username";
$hostname = "pma_hostname";
$GLOBALS['cfgRelation']['menuswork'] = true;
$dbi_old = $GLOBALS['dbi'];
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
@ -1650,6 +1651,11 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase
$dbi->expects($this->any())->method('fetchResult')
->will($this->returnValue($fields_info));
$expected_userGroup = "pma_usergroup";
$dbi->expects($this->any())->method('fetchValue')
->will($this->returnValue($expected_userGroup));
$GLOBALS['dbi'] = $dbi;
//PMA_getChangeLoginInformationHtmlForm
@ -1677,6 +1683,12 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase
$html
);
$this->assertContains(
'<input type="hidden" name="old_usergroup" value="'
. $expected_userGroup . '" />',
$html
);
//Create a new user with the same privileges
$this->assertContains(
"Create a new user account with the same privileges",
@ -1686,6 +1698,38 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase
$GLOBALS['dbi'] = $dbi_old;
}
/**
* Test for PMA_getUserGroupForUser
*
* @return void
*/
public function testPMAGetUserGroupForUser()
{
$username = "pma_username";
$hostname = "pma_hostname";
$GLOBALS['cfgRelation']['menuswork'] = true;
$dbi_old = $GLOBALS['dbi'];
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$expected_userGroup = "pma_usergroup";
$dbi->expects($this->any())->method('fetchValue')
->will($this->returnValue($expected_userGroup));
$GLOBALS['dbi'] = $dbi;
$returned_userGroup = PMA_getUserGroupForUser($username);
$this->assertEquals(
$expected_userGroup,
$returned_userGroup
);
$GLOBALS['dbi'] = $dbi_old;
}
/**
* Test for PMA_getLinkToDbAndTable
*