Extract HTML from new user ajax call
Server\Privileges::getExtraDataForAjaxBehavior Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
b075f07b02
commit
5cc67095fe
@ -1647,22 +1647,6 @@ class Privileges
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns user group edit link
|
||||
*
|
||||
* @param string $username User name
|
||||
*
|
||||
* @return string HTML code with link
|
||||
*/
|
||||
public function getUserGroupEditLink($username)
|
||||
{
|
||||
return '<a class="edit_user_group_anchor ajax"'
|
||||
. ' href="' . Url::getFromRoute('/server/privileges', ['username' => $username])
|
||||
. '">'
|
||||
. Util::getIcon('b_usrlist', __('Edit user group'))
|
||||
. '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of defined user groups
|
||||
*
|
||||
@ -1737,6 +1721,8 @@ class Privileges
|
||||
$hostname,
|
||||
$username
|
||||
) {
|
||||
global $is_grantuser;
|
||||
|
||||
if (isset($GLOBALS['dbname'])) {
|
||||
//if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
|
||||
if (preg_match('/(?<!\\\\)(?:_|%)/', $GLOBALS['dbname'])) {
|
||||
@ -1757,79 +1743,21 @@ class Privileges
|
||||
}
|
||||
|
||||
if (isset($_POST['change_copy'])) {
|
||||
/**
|
||||
* generate html on the fly for the new user that was just created.
|
||||
*/
|
||||
$new_user_string = '<tr>' . "\n"
|
||||
. '<td> <input type="checkbox" name="selected_usr[]" '
|
||||
. 'id="checkbox_sel_users_"'
|
||||
. 'value="'
|
||||
. htmlspecialchars($username)
|
||||
. '&#27;' . htmlspecialchars($hostname) . '">'
|
||||
. '</td>' . "\n"
|
||||
. '<td><label for="checkbox_sel_users_">'
|
||||
. (empty($_POST['username'])
|
||||
? '<span style="color: #FF0000">' . __('Any') . '</span>'
|
||||
: htmlspecialchars($username) ) . '</label></td>' . "\n"
|
||||
. '<td>' . htmlspecialchars($hostname) . '</td>' . "\n";
|
||||
|
||||
$new_user_string .= '<td>';
|
||||
|
||||
if (! empty($password) || isset($_POST['pma_pw'])) {
|
||||
$new_user_string .= __('Yes');
|
||||
} else {
|
||||
$new_user_string .= '<span style="color: #FF0000">'
|
||||
. __('No')
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
$new_user_string .= '</td>' . "\n";
|
||||
$new_user_string .= '<td>'
|
||||
. '<code>' . implode(', ', $this->extractPrivInfo(null, true)) . '</code>'
|
||||
. '</td>'; //Fill in privileges here
|
||||
|
||||
// if $cfg['Servers'][$i]['users'] and $cfg['Servers'][$i]['usergroups'] are
|
||||
// enabled
|
||||
$cfgRelation = $this->relation->getRelationsParam();
|
||||
if (! empty($cfgRelation['users']) && ! empty($cfgRelation['usergroups'])) {
|
||||
$new_user_string .= '<td class="usrGroup"></td>';
|
||||
}
|
||||
|
||||
$new_user_string .= '<td>';
|
||||
if (isset($_POST['Grant_priv']) && $_POST['Grant_priv'] == 'Y') {
|
||||
$new_user_string .= __('Yes');
|
||||
} else {
|
||||
$new_user_string .= __('No');
|
||||
}
|
||||
$new_user_string .= '</td>';
|
||||
|
||||
if ($GLOBALS['is_grantuser']) {
|
||||
$new_user_string .= '<td>'
|
||||
. $this->getUserLink('edit', $username, $hostname)
|
||||
. '</td>' . "\n";
|
||||
}
|
||||
|
||||
if ($cfgRelation['menuswork'] && $user_group_count > 0) {
|
||||
$new_user_string .= '<td>'
|
||||
. $this->getUserGroupEditLink($username)
|
||||
. '</td>' . "\n";
|
||||
}
|
||||
|
||||
$new_user_string .= '<td>'
|
||||
. $this->getUserLink(
|
||||
'export',
|
||||
$username,
|
||||
$hostname,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
isset($_GET['initial']) ? $_GET['initial'] : ''
|
||||
)
|
||||
. '</td>' . "\n";
|
||||
|
||||
$new_user_string .= '</tr>';
|
||||
|
||||
$extra_data['new_user_string'] = $new_user_string;
|
||||
$user = [
|
||||
'name' => $username,
|
||||
'host' => $hostname,
|
||||
'has_password' => ! empty($password) || isset($_POST['pma_pw']),
|
||||
'privileges' => implode(', ', $this->extractPrivInfo(null, true)),
|
||||
'has_group' => ! empty($cfgRelation['users']) && ! empty($cfgRelation['usergroups']),
|
||||
'has_group_edit' => $cfgRelation['menuswork'] && $user_group_count > 0,
|
||||
'has_grant' => isset($_POST['Grant_priv']) && $_POST['Grant_priv'] == 'Y',
|
||||
];
|
||||
$extra_data['new_user_string'] = $this->template->render('server/privileges/new_user_ajax', [
|
||||
'user' => $user,
|
||||
'is_grantuser' => $is_grantuser,
|
||||
'initial' => $_GET['initial'] ?? '',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Generate the string for this alphabet's initial, to update the user
|
||||
|
||||
66
templates/server/privileges/new_user_ajax.twig
Normal file
66
templates/server/privileges/new_user_ajax.twig
Normal file
@ -0,0 +1,66 @@
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_" value="
|
||||
{{- user.name ~ '&#27;' ~ user.host }}">
|
||||
</td>
|
||||
<td>
|
||||
<label for="checkbox_sel_users_">
|
||||
{% if user.name is empty %}
|
||||
<span class="text-danger">{% trans 'Any' %}</span>
|
||||
{% else %}
|
||||
{{ user.name }}
|
||||
{% endif %}
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
{{ user.host }}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.has_password %}
|
||||
{% trans 'Yes' %}
|
||||
{% else %}
|
||||
<span class="text-danger">{% trans 'No' %}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<code>
|
||||
{{ user.privileges|raw }}
|
||||
</code>
|
||||
</td>
|
||||
{% if user.has_group %}
|
||||
<td class="usrGroup"></td>
|
||||
{% endif %}
|
||||
<td>
|
||||
{{ user.has_grant ? 'Yes'|trans : 'No'|trans }}
|
||||
</td>
|
||||
{% if is_grantuser %}
|
||||
<td>
|
||||
<a class="edit_user_anchor" href="{{ url('/server/privileges', {
|
||||
'username': user.name,
|
||||
'hostname': user.host,
|
||||
'dbname': '',
|
||||
'tablename': '',
|
||||
'routinename': ''
|
||||
}) }}">
|
||||
{{ get_icon('b_usredit', 'Edit privileges'|trans) }}
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
{% if user.has_group_edit %}
|
||||
<td>
|
||||
<a class="edit_user_group_anchor ajax" href="{{ url('/server/privileges', {'username': user.name}) }}">
|
||||
{{ get_icon('b_usrlist', 'Edit user group'|trans) }}
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
<td>
|
||||
<a class="export_user_anchor ajax" href="{{ url('/server/privileges', {
|
||||
'username': user.name,
|
||||
'hostname': user.host,
|
||||
'export': true,
|
||||
'initial': initial
|
||||
}) }}">
|
||||
{{ get_icon('b_tblexport', 'Export'|trans) }}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
Loading…
Reference in New Issue
Block a user