diff --git a/libraries/classes/Controllers/Database/PrivilegesController.php b/libraries/classes/Controllers/Database/PrivilegesController.php
index 2f08cd48eb..bc2f3ab4b4 100644
--- a/libraries/classes/Controllers/Database/PrivilegesController.php
+++ b/libraries/classes/Controllers/Database/PrivilegesController.php
@@ -7,14 +7,19 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Database;
+use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
+use function __;
use function mb_strtolower;
+use function ob_get_clean;
+use function ob_start;
/**
* Controller for database privileges
@@ -38,18 +43,62 @@ class PrivilegesController extends AbstractController
$this->dbi = $dbi;
}
- /**
- * @param string[] $params Request parameters
- * @psalm-param array{checkprivsdb: string} $params
- */
- public function __invoke(array $params): string
+ public function __invoke(): void
{
$GLOBALS['text_dir'] = $GLOBALS['text_dir'] ?? null;
+
+ $checkUserPrivileges = new CheckUserPrivileges($this->dbi);
+ $checkUserPrivileges->getPrivileges();
+
+ $this->addScriptFiles(['server/privileges.js', 'vendor/zxcvbn-ts.js']);
+
+ /**
+ * Checks if the user is allowed to do what they try to...
+ */
+ $isGrantUser = $this->dbi->isGrantUser();
+ $isCreateUser = $this->dbi->isCreateUser();
+
+ if (! $this->dbi->isSuperUser() && ! $isGrantUser && ! $isCreateUser) {
+ $this->render('server/sub_page_header', [
+ 'type' => 'privileges',
+ 'is_image' => false,
+ ]);
+ $this->response->addHTML(
+ Message::error(__('No Privileges'))
+ ->getDisplay()
+ );
+
+ return;
+ }
+
+ if (! $isGrantUser && ! $isCreateUser) {
+ $this->response->addHTML(Message::notice(
+ __('You do not have the privileges to administrate the users!')
+ )->getDisplay());
+ }
+
+ // Gets the database structure
+ $GLOBALS['sub_part'] = '_structure';
+ ob_start();
+
+ [
+ $GLOBALS['tables'],
+ $GLOBALS['num_tables'],
+ $GLOBALS['total_num_tables'],
+ $GLOBALS['sub_part'],,,
+ $GLOBALS['tooltip_truename'],
+ $GLOBALS['tooltip_aliasname'],
+ $GLOBALS['pos'],
+ ] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part']);
+
+ $content = ob_get_clean();
+ $this->response->addHTML($content . "\n");
+
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
- $db = $params['checkprivsdb'];
+ $db = $GLOBALS['db'];
if ($this->dbi->getLowerCaseNames() === '1') {
- $db = mb_strtolower($params['checkprivsdb']);
+ $db = mb_strtolower($GLOBALS['db']);
}
$privileges = [];
@@ -57,7 +106,7 @@ class PrivilegesController extends AbstractController
$privileges = $this->privileges->getAllPrivileges($db);
}
- return $this->template->render('database/privileges/index', [
+ $this->render('database/privileges/index', [
'is_superuser' => $this->dbi->isSuperUser(),
'db' => $db,
'database_url' => $scriptName,
@@ -66,5 +115,6 @@ class PrivilegesController extends AbstractController
'is_grantuser' => $this->dbi->isGrantUser(),
'privileges' => $privileges,
]);
+ $this->render('export_modal');
}
}
diff --git a/libraries/classes/Controllers/Server/PrivilegesController.php b/libraries/classes/Controllers/Server/PrivilegesController.php
index 61e308f59a..41f16fb5a2 100644
--- a/libraries/classes/Controllers/Server/PrivilegesController.php
+++ b/libraries/classes/Controllers/Server/PrivilegesController.php
@@ -8,7 +8,6 @@ use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationCleanup;
use PhpMyAdmin\Controllers\AbstractController;
-use PhpMyAdmin\Controllers\Database\PrivilegesController as DatabaseController;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
@@ -25,8 +24,6 @@ use function header;
use function implode;
use function is_array;
use function is_string;
-use function ob_get_clean;
-use function ob_start;
use function str_replace;
use function urlencode;
@@ -101,13 +98,7 @@ class PrivilegesController extends AbstractController
new Plugins($this->dbi)
);
- $databaseController = new DatabaseController($this->response, $this->template, $serverPrivileges, $this->dbi);
-
- if (
- (isset($_GET['viewing_mode'])
- && $_GET['viewing_mode'] === 'server')
- && $relationParameters->configurableMenusFeature !== null
- ) {
+ if ($relationParameters->configurableMenusFeature !== null) {
$this->response->addHTML('
');
$this->render('server/privileges/subnav', [
'active' => 'privileges',
@@ -368,26 +359,7 @@ class PrivilegesController extends AbstractController
/**
* Displays the links
*/
- if (isset($_GET['viewing_mode']) && $_GET['viewing_mode'] === 'db') {
- $GLOBALS['db'] = $_REQUEST['db'] = $_GET['checkprivsdb'];
-
- // Gets the database structure
- $GLOBALS['sub_part'] = '_structure';
- ob_start();
-
- [
- $GLOBALS['tables'],
- $GLOBALS['num_tables'],
- $GLOBALS['total_num_tables'],
- $GLOBALS['sub_part'],,,
- $GLOBALS['tooltip_truename'],
- $GLOBALS['tooltip_aliasname'],
- $GLOBALS['pos'],
- ] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part']);
-
- $content = ob_get_clean();
- $this->response->addHTML($content . "\n");
- } elseif (! empty($GLOBALS['message'])) {
+ if (! empty($GLOBALS['message'])) {
$this->response->addHTML(Generator::getMessage($GLOBALS['message']));
unset($GLOBALS['message']);
}
@@ -417,16 +389,6 @@ class PrivilegesController extends AbstractController
$this->response->addHTML($serverPrivileges->getHtmlForAddUser(
Util::escapeMysqlWildcards(is_string($GLOBALS['dbname']) ? $GLOBALS['dbname'] : '')
));
- } elseif (isset($_GET['checkprivsdb']) && is_string($_GET['checkprivsdb'])) {
- if ($this->response->isAjax() === true && empty($_REQUEST['ajax_page_request'])) {
- $GLOBALS['message'] = Message::success(__('User has been added.'));
- $this->response->addJSON('message', $GLOBALS['message']);
-
- return;
- }
-
- $this->response->addHTML($databaseController(['checkprivsdb' => $_GET['checkprivsdb']]));
- $this->render('export_modal');
} else {
if (isset($GLOBALS['dbname']) && ! is_array($GLOBALS['dbname'])) {
$GLOBALS['url_dbname'] = urlencode(
@@ -479,11 +441,7 @@ class PrivilegesController extends AbstractController
}
}
- if (
- ! isset($_GET['viewing_mode'])
- || $_GET['viewing_mode'] !== 'server'
- || $relationParameters->configurableMenusFeature === null
- ) {
+ if ($relationParameters->configurableMenusFeature === null) {
return;
}
diff --git a/libraries/classes/Footer.php b/libraries/classes/Footer.php
index a54bcf568a..879d467827 100644
--- a/libraries/classes/Footer.php
+++ b/libraries/classes/Footer.php
@@ -153,20 +153,6 @@ class Footer
$params['server'] = $GLOBALS['server'];
- // needed for server privileges tabs
- if (isset($_GET['viewing_mode']) && in_array($_GET['viewing_mode'], ['server', 'db'])) {
- $params['viewing_mode'] = $_GET['viewing_mode'];
- }
-
- /**
- * @todo coming from /server/privileges, here $db is not set,
- * add the following condition below when that is fixed
- * && $_GET['checkprivsdb'] == $db
- */
- if (isset($_GET['checkprivsdb'])) {
- $params['checkprivsdb'] = $_GET['checkprivsdb'];
- }
-
if (isset($_REQUEST['single_table']) && in_array($_REQUEST['single_table'], [true, false])) {
$params['single_table'] = $_REQUEST['single_table'];
}
diff --git a/libraries/classes/Menu.php b/libraries/classes/Menu.php
index 299bc986e0..6a5f6224b2 100644
--- a/libraries/classes/Menu.php
+++ b/libraries/classes/Menu.php
@@ -394,13 +394,11 @@ class Menu
$tabs['operation']['active'] = $route === '/database/operations';
if ($isSuperUser || $isCreateOrGrantUser) {
- $tabs['privileges']['route'] = '/server/privileges';
- $tabs['privileges']['args']['checkprivsdb'] = $this->db;
+ $tabs['privileges']['route'] = '/database/privileges';
// stay on database view
- $tabs['privileges']['args']['viewing_mode'] = 'db';
$tabs['privileges']['text'] = __('Privileges');
$tabs['privileges']['icon'] = 's_rights';
- $tabs['privileges']['active'] = $route === '/server/privileges';
+ $tabs['privileges']['active'] = $route === '/database/privileges';
}
$tabs['routines']['route'] = '/database/routines';
@@ -500,7 +498,6 @@ class Menu
'/server/privileges',
'/server/user-groups',
]);
- $tabs['rights']['args']['viewing_mode'] = 'server';
}
$tabs['export']['icon'] = 'b_export';
diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php
index 2678e6aa6f..df4d8a2f77 100644
--- a/libraries/classes/Server/Privileges.php
+++ b/libraries/classes/Server/Privileges.php
@@ -2101,7 +2101,6 @@ class Privileges
return $this->template->render('server/privileges/initials_row', [
'array_initials' => $arrayInitials,
'initial' => $_GET['initial'] ?? null,
- 'viewing_mode' => $_GET['viewing_mode'] ?? null,
]);
}
@@ -2901,20 +2900,16 @@ class Privileges
return '';
}
- $relParams = [];
$urlParams = ['adduser' => 1];
if (! empty($db)) {
- $urlParams['dbname'] = $relParams['checkprivsdb'] = $db;
+ $urlParams['dbname'] = $db;
}
if (! empty($table)) {
$urlParams['tablename'] = $table;
}
- return $this->template->render('server/privileges/add_user_fieldset', [
- 'url_params' => $urlParams,
- 'rel_params' => $relParams,
- ]);
+ return $this->template->render('server/privileges/add_user_fieldset', ['url_params' => $urlParams]);
}
/**
diff --git a/libraries/classes/Url.php b/libraries/classes/Url.php
index b7aa92a6dc..dfb363b7d8 100644
--- a/libraries/classes/Url.php
+++ b/libraries/classes/Url.php
@@ -270,7 +270,6 @@ class Url
'hostname',
'dbname',
'tablename',
- 'checkprivsdb',
];
$paramsToEncrypt = [];
foreach ($params as $paramKey => $paramValue) {
diff --git a/libraries/routes.php b/libraries/routes.php
index 205450ede1..508c8deb63 100644
--- a/libraries/routes.php
+++ b/libraries/routes.php
@@ -71,6 +71,7 @@ return static function (RouteCollector $routes): void {
$routes->addRoute(['GET', 'POST'], '', Database\OperationsController::class);
$routes->post('/collation', Database\Operations\CollationController::class);
});
+ $routes->get('/privileges', Database\PrivilegesController::class);
$routes->addRoute(['GET', 'POST'], '/qbe', Database\QueryByExampleController::class);
$routes->addRoute(['GET', 'POST'], '/routines', Database\RoutinesController::class);
$routes->addRoute(['GET', 'POST'], '/search', Database\SearchController::class);
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 699e0c2b7b..fa0687f8ca 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -6706,10 +6706,7 @@
$info
- $params['checkprivsdb']
- $params['checkprivstable']
$params['single_table']
- $params['viewing_mode']
$subObject
diff --git a/templates/database/privileges/index.twig b/templates/database/privileges/index.twig
index 773c361168..9c68d50feb 100644
--- a/templates/database/privileges/index.twig
+++ b/templates/database/privileges/index.twig
@@ -132,7 +132,7 @@
+ }) }}">
{{ get_icon('b_usradd', 'Add user account'|trans) }}
diff --git a/templates/server/databases/index.twig b/templates/server/databases/index.twig
index 63b1acb48b..c876f87825 100644
--- a/templates/server/databases/index.twig
+++ b/templates/server/databases/index.twig
@@ -235,10 +235,7 @@
{{ get_icon('s_rights', 'Check privileges'|trans) }}
diff --git a/templates/server/privileges/add_user_fieldset.twig b/templates/server/privileges/add_user_fieldset.twig
index ecb594e8fa..892eea75ff 100644
--- a/templates/server/privileges/add_user_fieldset.twig
+++ b/templates/server/privileges/add_user_fieldset.twig
@@ -2,10 +2,7 @@
diff --git a/templates/server/privileges/initials_row.twig b/templates/server/privileges/initials_row.twig
index 622310d65b..c546433b0a 100644
--- a/templates/server/privileges/initials_row.twig
+++ b/templates/server/privileges/initials_row.twig
@@ -4,7 +4,7 @@
{% if tmp_initial is not same as(null) %}
{% if initial_was_found %}
- {{ tmp_initial }}
+ {{ tmp_initial }}
{% else %}
@@ -14,7 +14,7 @@
{% endif %}
{% endfor %}
- {% trans 'Show all' %}
+ {% trans 'Show all' %}
diff --git a/templates/server/privileges/subnav.twig b/templates/server/privileges/subnav.twig
index 84c7443625..29f0da1bda 100644
--- a/templates/server/privileges/subnav.twig
+++ b/templates/server/privileges/subnav.twig
@@ -1,7 +1,7 @@
-
-
+
{% trans 'User accounts overview' %}
diff --git a/test/classes/Controllers/Database/PrivilegesControllerTest.php b/test/classes/Controllers/Database/PrivilegesControllerTest.php
index 4a3fb575be..7a4845876c 100644
--- a/test/classes/Controllers/Database/PrivilegesControllerTest.php
+++ b/test/classes/Controllers/Database/PrivilegesControllerTest.php
@@ -5,10 +5,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Database;
use PhpMyAdmin\Controllers\Database\PrivilegesController;
-use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Url;
use function __;
@@ -31,23 +31,34 @@ class PrivilegesControllerTest extends AbstractTestCase
public function testIndex(): void
{
- $GLOBALS['db'] = 'db';
+ $GLOBALS['db'] = 'test_db';
$GLOBALS['server'] = 0;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $this->dummyDbi->addResult(
+ 'SHOW TABLES FROM `test_db`;',
+ [['test_table']],
+ ['Tables_in_test_db']
+ );
+
+ // phpcs:disable Generic.Files.LineLength.TooLong
+ $this->dummyDbi->addResult(
+ 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`, `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`, `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`, `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`, `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment` FROM `information_schema`.`TABLES` t WHERE `TABLE_SCHEMA` IN (\'test_db\') ORDER BY Name ASC LIMIT 250 OFFSET 0',
+ [['def', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '0', '0', '4', '2011-12-13 14:15:16', null, null, 'utf8mb4_general_ci', null, '', '', '0', 'N', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '0', '0', '4', '2011-12-13 14:15:16', null, null, 'utf8mb4_general_ci', null, '', '']],
+ ['TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'TABLE_TYPE', 'ENGINE', 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT', 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION', 'CHECKSUM', 'CREATE_OPTIONS', 'TABLE_COMMENT', 'MAX_INDEX_LENGTH', 'TEMPORARY', 'Db', 'Name', 'TABLE_TYPE', 'Engine', 'Type', 'Version', 'Row_format', 'Rows', 'Avg_row_length', 'Data_length', 'Max_data_length', 'Index_length', 'Data_free', 'Auto_increment', 'Create_time', 'Update_time', 'Check_time', 'Collation', 'Checksum', 'Create_options', 'Comment']
+ );
+ // phpcs:enable
+
$privileges = [];
$serverPrivileges = $this->createMock(Privileges::class);
$serverPrivileges->method('getAllPrivileges')
->willReturn($privileges);
- $actual = (new PrivilegesController(
- ResponseRenderer::getInstance(),
- new Template(),
- $serverPrivileges,
- $GLOBALS['dbi']
- ))(['checkprivsdb' => $GLOBALS['db']]);
+ $response = new ResponseRenderer();
+ (new PrivilegesController($response, new Template(), $serverPrivileges, $GLOBALS['dbi']))();
+ $actual = $response->getHTMLResult();
$this->assertStringContainsString(
Url::getCommon(['db' => $GLOBALS['db']], ''),
@@ -86,9 +97,5 @@ class PrivilegesControllerTest extends AbstractTestCase
_pgettext('Create new user', 'New'),
$actual
);
- $this->assertStringContainsString(
- Url::getCommon(['checkprivsdb' => $GLOBALS['db']]),
- $actual
- );
}
}
diff --git a/test/classes/Controllers/Server/PrivilegesControllerTest.php b/test/classes/Controllers/Server/PrivilegesControllerTest.php
index 2c0a2a5d36..345aa9d24b 100644
--- a/test/classes/Controllers/Server/PrivilegesControllerTest.php
+++ b/test/classes/Controllers/Server/PrivilegesControllerTest.php
@@ -54,8 +54,6 @@ class PrivilegesControllerTest extends AbstractTestCase
);
// phpcs:enable
- $_GET = ['viewing_mode' => 'server'];
-
$response = new ResponseRenderer();
(new PrivilegesController($response, new Template(), new Relation($this->dbi), $this->dbi))();
|