diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 378c6e4a89..bdf8125145 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -1373,26 +1373,58 @@ class Privileges */ public function getHtmlForSpecificDbPrivileges(string $db): string { - global $cfg, $pmaThemeImage, $text_dir, $is_createuser; + global $cfg, $pmaThemeImage, $text_dir, $is_createuser, $is_grantuser; $scriptName = Util::getScriptNameForOption( $cfg['DefaultTabDatabase'], 'database' ); - $tableBody = ''; + $privileges = []; if ($this->dbi->isSuperuser()) { - $privileges = $this->getDatabasePrivileges($db); + $databasePrivileges = $this->getDatabasePrivileges($db); $routinePrivileges = $this->getRoutinesPrivileges($db); foreach ($routinePrivileges as $user => $hosts) { foreach ($hosts as $host => $privs) { - $privileges[$user] = $privileges[$user] ?? []; - $privileges[$user][$host] = array_merge($privileges[$user][$host] ?? [], $privs); + $databasePrivileges[$user] = $databasePrivileges[$user] ?? []; + $databasePrivileges[$user][$host] = array_merge( + $databasePrivileges[$user][$host] ?? [], + $privs + ); } } - $tableBody = $this->getHtmlTableBodyForSpecificDbOrTablePrivs($privileges, $db); + foreach ($databasePrivileges as $user => $hosts) { + foreach ($hosts as $host => $specificPrivileges) { + $privileges[$user . '@' . $host] = [ + 'user' => $user, + 'host' => $host, + 'privileges' => [], + ]; + foreach ($specificPrivileges as $specificPrivilege) { + $privilege = [ + 'type' => $specificPrivilege['Type'], + 'database' => $specificPrivilege['Db'], + ]; + if ($specificPrivilege['Type'] === 'r') { + $privilege['routine'] = $specificPrivilege['Routine_name']; + $privilege['has_grant'] = strpos( + $specificPrivilege['Proc_priv'], + 'Grant' + ) !== false; + $privilege['privileges'] = explode(',', $specificPrivilege['Proc_priv']); + } else { + $privilege['has_grant'] = $specificPrivilege['Grant_priv'] === 'Y'; + $privilege['privileges'] = $this->extractPrivInfo( + $specificPrivilege, + true + ); + } + $privileges[$user . '@' . $host]['privileges'][$specificPrivilege['Type']] = $privilege; + } + } + } } $response = Response::getInstance(); @@ -1410,8 +1442,9 @@ class Privileges 'database_url' => $scriptName, 'pma_theme_image' => $pmaThemeImage, 'text_dir' => $text_dir, - 'table_body' => $tableBody, 'is_createuser' => $is_createuser, + 'is_grantuser' => $is_grantuser, + 'privileges' => $privileges, ]); } @@ -1668,211 +1701,6 @@ class Privileges )->getDisplay(); } - /** - * Get HTML snippet for table body of specific database or table privileges - * - * @param array $privMap privilege map - * @param string $db database - * - * @return string - */ - public function getHtmlTableBodyForSpecificDbOrTablePrivs($privMap, $db) - { - $html_output = '
'; - $index_checkbox = 0; - if (empty($privMap)) { - $html_output .= ''
- . htmlspecialchars($current['Db'])
- . '';
- }
- } elseif ($current['Type'] == 't') {
- $html_output .= __('table-specific');
- } elseif ($current['Type'] == 'r') {
- $html_output .= __('routine');
- }
- $html_output .= '';
- $html_output .= htmlspecialchars($current['Routine_name']);
- $html_output .= ' (';
- $html_output .= strtoupper(htmlspecialchars($current['Proc_priv']));
- $html_output .= ')';
- } elseif (isset($current['Table_name'])) {
- $privList = explode(',', $current['Table_priv']);
- $privs = [];
- $grantsArr = $this->getTableGrantsArray();
- foreach ($grantsArr as $grant) {
- $privs[$grant[0]] = 'N';
- foreach ($privList as $priv) {
- if ($grant[0] == $priv) {
- $privs[$grant[0]] = 'Y';
- }
- }
- }
- $html_output .= ''
- . implode(
- ',',
- $this->extractPrivInfo($privs, true, true)
- )
- . '';
- } else {
- $html_output .= ''
- . implode(
- ',',
- $this->extractPrivInfo($current, true, false)
- )
- . '';
- }
- $html_output .= '{{ priv.database }}
+ {% endif %}
+ {% elseif priv.type == 'r' %}
+ {% trans 'routine' %}
+ {% endif %}
+
+ {% if priv.type == 'r' %}
+ {{ priv.routine }}
+ ({{ priv.privileges|join(', ')|upper }})
+ {% else %}
+ {{ priv.privileges|join(', ')|raw }}
+ {% endif %}
+
+