Extract HTML from database privileges page

Server\Privileges::getHtmlForSpecificDbPrivileges

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2019-09-12 11:38:16 -03:00
parent 94b43e3fac
commit 9dda538c80
2 changed files with 78 additions and 55 deletions

View File

@ -1501,60 +1501,19 @@ class Privileges
*
* @return string
*/
public function getHtmlForSpecificDbPrivileges($db)
public function getHtmlForSpecificDbPrivileges(string $db): string
{
$html_output = '';
global $cfg, $pmaThemeImage, $text_dir, $is_createuser;
$scriptName = Util::getScriptNameForOption(
$cfg['DefaultTabDatabase'],
'database'
);
$tableBody = '';
if ($this->dbi->isSuperuser()) {
// check the privileges for a particular database.
$html_output = '<form id="usersForm" action="' . Url::getFromRoute('/server/privileges') . '">';
$html_output .= Url::getHiddenInputs($db);
$html_output .= '<div class="width100">';
$html_output .= '<fieldset>';
$scriptName = Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabDatabase'],
'database'
);
$html_output .= '<legend>' . "\n"
. Util::getIcon('b_usrcheck')
. ' '
. sprintf(
__('Users having access to "%s"'),
'<a href="' . $scriptName
. Url::getCommon(['db' => $db], strpos($scriptName, '?') === false ? '?' : '&') . '">'
. htmlspecialchars($db)
. '</a>'
)
. "\n"
. '</legend>' . "\n";
$html_output .= '<div class="responsivetable jsresponsive">';
$html_output .= '<table id="dbspecificuserrights" class="data">';
$html_output .= $this->getHtmlForPrivsTableHead();
$privMap = $this->getPrivMap($db);
$html_output .= $this->getHtmlTableBodyForSpecificDbOrTablePrivs($privMap, $db);
$html_output .= '</table>';
$html_output .= '</div>';
$html_output .= '<div class="floatleft">';
$html_output .= $this->template->render('select_all', [
'pma_theme_image' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'form_name' => "usersForm",
]);
$html_output .= Util::getButtonOrImage(
'submit_mult',
'mult_submit',
__('Export'),
'b_tblexport',
'export'
);
$html_output .= '</fieldset>';
$html_output .= '</div>';
$html_output .= '</form>';
} else {
$html_output .= $this->getHtmlForViewUsersError();
$tableBody = $this->getHtmlTableBodyForSpecificDbOrTablePrivs($privMap, $db);
}
$response = Response::getInstance();
@ -1563,13 +1522,18 @@ class Privileges
) {
$message = Message::success(__('User has been added.'));
$response->addJSON('message', $message);
$response->addJSON('user_form', $html_output);
exit;
} else {
// Offer to create a new user for the current database
$html_output .= $this->getAddUserHtmlFieldset($db);
}
return $html_output;
return $this->template->render('server/privileges/database', [
'is_superuser' => $this->dbi->isSuperuser(),
'db' => $db,
'database_url' => $scriptName,
'pma_theme_image' => $pmaThemeImage,
'text_dir' => $text_dir,
'table_body' => $tableBody,
'is_createuser' => $is_createuser,
]);
}
/**

View File

@ -0,0 +1,59 @@
{% if is_superuser %}
<form id="usersForm" action="{{ url('/server/privileges') }}">
{{ get_hidden_inputs(db) }}
<div class="width100">
<fieldset>
<legend>
{{ get_icon('b_usrcheck') }}
{{ 'Users having access to "%s"'|trans|format('<a href="' ~ database_url ~ get_common({'db': db}, '&') ~ '">' ~ db ~ '</a>')|raw }}
</legend>
<div class="responsivetable jsresponsive">
<table id="dbspecificuserrights" class="data">
<thead>
<tr>
<th></th>
<th>{% trans 'User name' %}</th>
<th>{% trans 'Host name' %}</th>
<th>{% trans 'Type' %}</th>
<th>{% trans 'Privileges' %}</th>
<th>{% trans 'Grant' %}</th>
<th colspan="2">{% trans 'Action' %}</th>
</tr>
</thead>
{{ table_body|raw }}
</table>
</div>
<div class="floatleft">
<img class="selectallarrow" src="{{ pma_theme_image }}arrow_{{ text_dir }}.png" alt="
{%- trans 'With selected:' %}" width="38" height="22">
<input type="checkbox" id="usersForm_checkall" class="checkall_box" title="{% trans 'Check all' %}">
<label for="usersForm_checkall">{% trans 'Check all' %}</label>
<em class="with-selected">{% trans 'With selected:' %}</em>
{{ get_button_or_image('submit_mult', 'mult_submit', 'Export'|trans, 'b_tblexport', 'export') }}
</div>
</fieldset>
</div>
</form>
{% else %}
{{ 'Not enough privilege to view users.'|trans|error }}
{% endif %}
{% if is_createuser %}
<div class="row">
<div class="col-12">
<fieldset id="fieldset_add_user">
<legend>{% trans %}New{% context %}Create new user{% endtrans %}</legend>
<a id="add_user_anchor" href="{{ url('/server/privileges', {
'adduser': true,
'dbname': db
}) }}" rel="{{ get_common({'checkprivsdb': db}) }}">
{{ get_icon('b_usradd', 'Add user account'|trans) }}
</a>
</fieldset>
</div>
</div>
{% endif %}