Redesign the database and table privileges pages

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-05-08 21:04:44 -03:00
parent a256228264
commit 624126edc8
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
5 changed files with 153 additions and 175 deletions

View File

@ -8,6 +8,7 @@ phpMyAdmin - ChangeLog
- issue Make database and web server info separately configurable on `$cfg['ShowServerInfo']`
- issue Add a configuration option to (dis)allow shared bookmarks: `$cfg['AllowSharedBookmarks'] = true;`
- issue Redesign the User Groups form page
- issue Redesign the database and table privileges pages
5.2.2 (not yet released)
- issue #17028 Fix total count of rows in not accurate

View File

@ -1,14 +1,14 @@
{% if is_superuser %}
<form id="usersForm" action="{{ url('/server/privileges') }}">
{{ get_hidden_inputs(db) }}
<div class="container">
{% if is_superuser %}
<h2>
{{ get_icon('b_usrcheck') }}
{{ 'Users having access to "%s"'|trans|format('<a href="' ~ database_url ~ get_common({'db': db}, '&') ~ '">' ~ db|escape('html') ~ '</a>')|raw }}
</h2>
<div class="w-100">
<fieldset class="pma-fieldset">
<legend>
{{ get_icon('b_usrcheck') }}
{{ 'Users having access to "%s"'|trans|format('<a href="' ~ database_url ~ get_common({'db': db}, '&') ~ '">' ~ db|escape('html') ~ '</a>')|raw }}
</legend>
<form id="usersForm" action="{{ url('/server/privileges') }}" class="card mb-3">
{{ get_hidden_inputs(db) }}
<div class="card-body">
<div class="table-responsive jsresponsive">
<table class="table table-striped table-hover w-auto">
<thead>
@ -92,10 +92,10 @@
</a>
</td>
</tr>
{% if privileges_amount > 1 %}
<tr class="noclick">
{% endif %}
{% endfor %}
{% if privileges_amount > 1 %}
<tr class="noclick">
{% endif %}
{% endfor %}
{% else %}
<tr>
<td colspan="7">
@ -107,7 +107,7 @@
</table>
</div>
<div class="float-start">
<div>
<img class="selectallarrow" src="{{ 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' %}">
@ -117,25 +117,20 @@
{{ get_icon('b_tblexport', 'Export'|trans) }}
</button>
</div>
</fieldset>
</div>
</form>
{% else %}
{{ 'Not enough privilege to view users.'|trans|error }}
{% endif %}
</div>
</form>
{% else %}
{{ 'Not enough privilege to view users.'|trans|error }}
{% endif %}
{% if is_createuser %}
<div class="row">
<div class="col-12">
<fieldset class="pma-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
}) }}">
{{ get_icon('b_usradd', 'Add user account'|trans) }}
</a>
</fieldset>
{% if is_createuser %}
<div>
<a class="btn btn-primary" id="add_user_anchor" href="{{ url('/server/privileges', {
'adduser': true,
'dbname': db
}) }}">
{{ get_icon('b_usradd', 'Add user account'|trans) }}
</a>
</div>
</div>
{% endif %}
{% endif %}
</div>

View File

@ -1,145 +1,141 @@
{% if is_superuser %}
<form id="usersForm" action="{{ url('/server/privileges') }}">
{{ get_hidden_inputs(db, table) }}
<div class="container">
{% if is_superuser %}
<h2>
{{ get_icon('b_usrcheck') }}
{{ 'Users having access to "%s"'|trans|format('<a href="' ~ table_url ~ get_common({
'db': db,
'table': table
}, '&') ~ '">' ~ db|escape('html') ~ '.' ~ table|escape('html') ~ '</a>')|raw }}
</h2>
<fieldset class="pma-fieldset">
<legend>
{{ get_icon('b_usrcheck') }}
{{ 'Users having access to "%s"'|trans|format('<a href="' ~ table_url ~ get_common({
'db': db,
'table': table
}, '&') ~ '">' ~ db|escape('html') ~ '.' ~ table|escape('html') ~ '</a>')|raw }}
</legend>
<div class="table-responsive-md jsresponsive">
<table class="table table-striped table-hover w-auto">
<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>
<tbody>
{% for privilege in privileges %}
{% set privileges_amount = privilege.privileges|length %}
<form id="usersForm" action="{{ url('/server/privileges') }}" class="card mb-3">
{{ get_hidden_inputs(db, table) }}
<div class="card-body">
<div class="table-responsive-md jsresponsive">
<table class="table table-striped table-hover w-auto">
<thead>
<tr>
<td{% if privileges_amount > 1 %} class="align-middle" rowspan="{{ privileges_amount }}"{% endif %}>
<input type="checkbox" class="checkall" name="selected_usr[]" id="checkbox_sel_users_{{ loop.index0 }}" value="
{{- privilege.user ~ '&amp;#27;' ~ privilege.host }}">
</td>
<td{% if privileges_amount > 1 %} class="align-middle" rowspan="{{ privileges_amount }}"{% endif %}>
{% if privilege.user is empty %}
<span class="text-danger">{% trans 'Any' %}</span>
{% else %}
{{ privilege.user }}
{% endif %}
</td>
<td{% if privileges_amount > 1 %} class="align-middle" rowspan="{{ privileges_amount }}"{% endif %}>
{{ privilege.host }}
</td>
{% for priv in privilege.privileges %}
<td>
{% if priv.type == 'g' %}
{% trans 'global' %}
{% elseif priv.type == 'd' %}
{% if priv.database == db|replace({'_': '\\_', '%': '\\%'}) %}
{% trans 'database-specific' %}
{% else %}
{% trans 'wildcard' %}: <code>{{ priv.database }}</code>
{% endif %}
{% elseif priv.type == 't' %}
{% trans 'table-specific' %}
{% elseif priv.type == 'r' %}
{% trans 'routine' %}
<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>
<tbody>
{% for privilege in privileges %}
{% set privileges_amount = privilege.privileges|length %}
<tr>
<td{% if privileges_amount > 1 %} class="align-middle" rowspan="{{ privileges_amount }}"{% endif %}>
<input type="checkbox" class="checkall" name="selected_usr[]" id="checkbox_sel_users_{{ loop.index0 }}" value="
{{- privilege.user ~ '&amp;#27;' ~ privilege.host }}">
</td>
<td{% if privileges_amount > 1 %} class="align-middle" rowspan="{{ privileges_amount }}"{% endif %}>
{% if privilege.user is empty %}
<span class="text-danger">{% trans 'Any' %}</span>
{% else %}
{{ privilege.user }}
{% endif %}
</td>
<td>
<code>
{% if priv.type == 'r' %}
{{ priv.routine }}
({{ priv.privileges|join(', ')|upper }})
{% else %}
{{ priv.privileges|join(', ')|raw }}
<td{% if privileges_amount > 1 %} class="align-middle" rowspan="{{ privileges_amount }}"{% endif %}>
{{ privilege.host }}
</td>
{% for priv in privilege.privileges %}
<td>
{% if priv.type == 'g' %}
{% trans 'global' %}
{% elseif priv.type == 'd' %}
{% if priv.database == db|replace({'_': '\\_', '%': '\\%'}) %}
{% trans 'database-specific' %}
{% else %}
{% trans 'wildcard' %}: <code>{{ priv.database }}</code>
{% endif %}
{% elseif priv.type == 't' %}
{% trans 'table-specific' %}
{% elseif priv.type == 'r' %}
{% trans 'routine' %}
{% endif %}
</code>
</td>
<td>
{{ priv.has_grant ? 'Yes'|trans : 'No'|trans }}
</td>
<td>
{% if is_grantuser %}
<a class="edit_user_anchor" href="{{ url('/server/privileges', {
</td>
<td>
<code>
{% if priv.type == 'r' %}
{{ priv.routine }}
({{ priv.privileges|join(', ')|upper }})
{% else %}
{{ priv.privileges|join(', ')|raw }}
{% endif %}
</code>
</td>
<td>
{{ priv.has_grant ? 'Yes'|trans : 'No'|trans }}
</td>
<td>
{% if is_grantuser %}
<a class="edit_user_anchor" href="{{ url('/server/privileges', {
'username': privilege.user,
'hostname': privilege.host,
'dbname': priv.database != '*' ? priv.database,
'tablename': priv.table is defined and priv.table != '*' ? priv.table,
'routinename': priv.routine ?? ''
}) }}">
{{ get_icon('b_usredit', 'Edit privileges'|trans) }}
</a>
{% endif %}
</td>
<td class="text-center">
<a class="export_user_anchor ajax" href="{{ url('/server/privileges', {
'username': privilege.user,
'hostname': privilege.host,
'dbname': priv.database != '*' ? priv.database,
'tablename': priv.table is defined and priv.table != '*' ? priv.table,
'routinename': priv.routine ?? ''
'export': true,
'initial': ''
}) }}">
{{ get_icon('b_usredit', 'Edit privileges'|trans) }}
{{ get_icon('b_tblexport', 'Export'|trans) }}
</a>
{% endif %}
</td>
<td class="text-center">
<a class="export_user_anchor ajax" href="{{ url('/server/privileges', {
'username': privilege.user,
'hostname': privilege.host,
'export': true,
'initial': ''
}) }}">
{{ get_icon('b_tblexport', 'Export'|trans) }}
</a>
</td>
</tr>
</td>
</tr>
{% if privileges_amount > 1 %}
<tr class="noclick">
{% endif %}
{% endfor %}
{% else %}
<tr>
<td colspan="7">
{% trans 'No user found.' %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<tr>
<td colspan="7">
{% trans 'No user found.' %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="float-start">
<img class="selectallarrow" src="{{ image('arrow_' ~ text_dir ~ '.png') }}" alt="
<div>
<img class="selectallarrow" src="{{ 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>
<button class="btn btn-link mult_submit" type="submit" name="submit_mult" value="export" title="{% trans 'Export' %}">
{{ get_icon('b_tblexport', 'Export'|trans) }}
</button>
<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>
<button class="btn btn-link mult_submit" type="submit" name="submit_mult" value="export" title="{% trans 'Export' %}">
{{ get_icon('b_tblexport', 'Export'|trans) }}
</button>
</div>
</div>
</fieldset>
</form>
{% else %}
{{ 'Not enough privilege to view users.'|trans|error }}
{% endif %}
</form>
{% else %}
{{ 'Not enough privilege to view users.'|trans|error }}
{% endif %}
{% if is_createuser %}
<div class="row">
<div class="col-12">
<fieldset class="pma-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,
'tablename': table
}) }}">
{{ get_icon('b_usradd', 'Add user account'|trans) }}
</a>
</fieldset>
{% if is_createuser %}
<div>
<a class="btn btn-primary" id="add_user_anchor" href="{{ url('/server/privileges', {
'adduser': true,
'dbname': db,
'tablename': table
}) }}">
{{ get_icon('b_usradd', 'Add user account'|trans) }}
</a>
</div>
</div>
{% endif %}
{% endif %}
</div>

View File

@ -15,7 +15,6 @@ use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Url;
use function __;
use function _pgettext;
/** @covers \PhpMyAdmin\Controllers\Database\PrivilegesController */
class PrivilegesControllerTest extends AbstractTestCase
@ -106,12 +105,6 @@ class PrivilegesControllerTest extends AbstractTestCase
__('Action'),
$actual,
);
//_pgettext('Create new user', 'New')
$this->assertStringContainsString(
_pgettext('Create new user', 'New'),
$actual,
);
}
public function testWithInvalidDatabaseName(): void

View File

@ -13,7 +13,6 @@ use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Url;
use function __;
use function _pgettext;
/** @covers \PhpMyAdmin\Controllers\Table\PrivilegesController */
class PrivilegesControllerTest extends AbstractTestCase
@ -92,12 +91,6 @@ class PrivilegesControllerTest extends AbstractTestCase
__('No user found'),
$actual,
);
//_pgettext('Create new user', 'New')
$this->assertStringContainsString(
_pgettext('Create new user', 'New'),
$actual,
);
}
public function testWithInvalidDatabaseName(): void