diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 6f69b30c4f..8d05da2fc8 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -729,7 +729,6 @@ class Privileges // global or db-specific $html_output .= $this->getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row); } - $html_output .= '' . "\n"; if ($submit) { $html_output .= '' . "\n"; - - return $html_output; } /** @@ -1097,7 +1060,7 @@ class Privileges */ public function getHtmlForGlobalOrDbSpecificPrivs($db, $table, array $row) { - $privTable_names = [ + $privTableNames = [ 0 => __('Data'), 1 => __('Structure'), 2 => __('Administration'), @@ -1107,49 +1070,43 @@ class Privileges $privTable[1] = $this->getStructurePrivilegeTable($table, $row); $privTable[2] = $this->getAdministrationPrivilegeTable($db); - $html_output = ''; + $grantCount = count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - ( + isset($row['Grant_priv']) ? 1 : 0); + if ($db == '*') { $legend = __('Global privileges'); - $menu_label = __('Global'); + $menuLabel = __('Global'); } elseif ($table == '*') { $legend = __('Database-specific privileges'); - $menu_label = __('Database'); + $menuLabel = __('Database'); } else { $legend = __('Table-specific privileges'); - $menu_label = __('Table'); + $menuLabel = __('Table'); } - $html_output .= '
' - . '' . $legend - . ' ' - . ' ' - . '' - . '

' - . __('Note: MySQL privilege names are expressed in English.') - . '

'; // Output the Global privilege tables with checkboxes - $html_output .= $this->getHtmlForGlobalPrivTableWithCheckboxes( + $globalPrivTable = $this->getHtmlForGlobalPrivTableWithCheckboxes( $privTable, - $privTable_names, + $privTableNames, $row ); - // The "Resource limits" box is not displayed for db-specific privs - if ($db == '*') { - $html_output .= $this->getHtmlForResourceLimits($row); - $html_output .= $this->getHtmlForRequires($row); + $resourceLimits = []; + $requireOptions = []; + if ($db === '*') { + $resourceLimits = $this->getResourceLimits($row); + $requireOptions = $this->getRequireOptions($row); } - // for Safari 2.0.2 - $html_output .= '
'; - return $html_output; + return $this->template->render('server/privileges/global_db_specific_privileges', [ + 'grant_count' => $grantCount, + 'menu_label' => $menuLabel, + 'legend' => $legend, + 'global_priv_table' => $globalPrivTable, + 'is_global' => $db === '*', + 'resource_limits' => $resourceLimits, + 'require_options' => $requireOptions, + ]); } /** diff --git a/templates/server/privileges/global_db_specific_privileges.twig b/templates/server/privileges/global_db_specific_privileges.twig new file mode 100644 index 0000000000..5995a97fca --- /dev/null +++ b/templates/server/privileges/global_db_specific_privileges.twig @@ -0,0 +1,64 @@ + +
+ + {{ legend }} + + + +

+ {% trans 'Note: MySQL privilege names are expressed in English.' %} +

+ + {{ global_priv_table|raw }} + + {% if is_global %} +
+ {% trans 'Resource limits' %} +

+ {% trans 'Note: Setting these options to 0 (zero) removes the limit.' %} +

+ {% for limit in resource_limits %} +
+ + +
+ {% endfor %} +
+ +
+ SSL +
+ {% for option in require_options %} + {% if option.name == 'ssl_cipher' %} +
+ {% endif %} + +
+ {% if option.is_radio %} + + + {% else %} + + + {% endif %} +
+ + {% if option.name == 'ssl_cipher' %} +
+ {% endif %} + {% endfor %} +
+
+ {% endif %} + +
+
diff --git a/templates/server/privileges/require_options.twig b/templates/server/privileges/require_options.twig deleted file mode 100644 index 03da69162f..0000000000 --- a/templates/server/privileges/require_options.twig +++ /dev/null @@ -1,32 +0,0 @@ -
- SSL -
- {% for require_option in require_options %} - {% if require_option['name'] is same as('ssl_cipher') %} -
- {% endif %} -
- {% if require_option['radio'] %} - - - {% else %} - - - {% endif %} -
- {% endfor %} -
{# END specified_div #} -
{# END require_ssl_div #} -
diff --git a/templates/server/privileges/resource_limits.twig b/templates/server/privileges/resource_limits.twig deleted file mode 100644 index 2569bd7da8..0000000000 --- a/templates/server/privileges/resource_limits.twig +++ /dev/null @@ -1,21 +0,0 @@ -
- {% trans 'Resource limits' %} -

- - {% trans 'Note: Setting these options to 0 (zero) removes the limit.' %} - -

- {% for limit in limits %} -
- - -
- {% endfor %} -
diff --git a/templates/server/privileges/table_specific_privileges.twig b/templates/server/privileges/table_specific_privileges.twig index a0089899a0..fab75f260f 100644 --- a/templates/server/privileges/table_specific_privileges.twig +++ b/templates/server/privileges/table_specific_privileges.twig @@ -95,7 +95,8 @@
{% for privilege in privileges %}
- + @@ -104,3 +105,4 @@
+
diff --git a/test/classes/Server/PrivilegesTest.php b/test/classes/Server/PrivilegesTest.php index 339995ecde..94d8dc6ad5 100644 --- a/test/classes/Server/PrivilegesTest.php +++ b/test/classes/Server/PrivilegesTest.php @@ -300,138 +300,6 @@ class PrivilegesTest extends TestCase ); } - /** - * Test for getHtmlForRequires - * - * @return void - */ - public function testGetHtmlForRequires() - { - /* Assertion 1 */ - $row = [ - 'ssl_type' => '', - 'ssh_cipher' => '', - ]; - - $html = $this->serverPrivileges->getHtmlForRequires( - $row - ); - // SSL - $this->assertStringContainsString( - 'SSL', - $html - ); - $this->assertStringContainsString( - 'value="NONE" checked="checked"', - $html - ); - $this->assertStringContainsString( - 'value="ANY"', - $html - ); - $this->assertStringContainsString( - 'value="X509"', - $html - ); - $this->assertStringContainsString( - 'value="SPECIFIED"', - $html - ); - - /* Assertion 2 */ - $row = [ - 'ssl_type' => 'ANY', - 'ssh_cipher' => '', - ]; - - $html = $this->serverPrivileges->getHtmlForRequires( - $row - ); - // SSL - $this->assertStringContainsString( - 'SSL', - $html - ); - $this->assertStringContainsString( - 'value="NONE"', - $html - ); - $this->assertStringContainsString( - 'value="ANY" checked="checked"', - $html - ); - $this->assertStringContainsString( - 'value="X509"', - $html - ); - $this->assertStringContainsString( - 'value="SPECIFIED"', - $html - ); - - /* Assertion 3 */ - $row = [ - 'ssl_type' => 'X509', - 'ssh_cipher' => '', - ]; - - $html = $this->serverPrivileges->getHtmlForRequires( - $row - ); - // SSL - $this->assertStringContainsString( - 'SSL', - $html - ); - $this->assertStringContainsString( - 'value="NONE"', - $html - ); - $this->assertStringContainsString( - 'value="ANY"', - $html - ); - $this->assertStringContainsString( - 'value="X509" checked="checked"', - $html - ); - $this->assertStringContainsString( - 'value="SPECIFIED"', - $html - ); - - /* Assertion 4 */ - $row = [ - 'ssl_type' => 'SPECIFIED', - 'ssh_cipher' => '', - ]; - - $html = $this->serverPrivileges->getHtmlForRequires( - $row - ); - // SSL - $this->assertStringContainsString( - 'SSL', - $html - ); - $this->assertStringContainsString( - 'value="NONE"', - $html - ); - $this->assertStringContainsString( - 'value="ANY"', - $html - ); - $this->assertStringContainsString( - 'value="X509"', - $html - ); - $this->assertStringContainsString( - 'value="SPECIFIED" checked="checked"', - $html - ); - } - /** * Test for getHtmlForUserGroupDialog * @@ -547,59 +415,6 @@ class PrivilegesTest extends TestCase ); } - /** - * Test for getHtmlForResourceLimits - * - * @return void - */ - public function testGetHtmlForResourceLimits() - { - $row = [ - 'max_questions' => 'max_questions', - 'max_updates' => 'max_updates', - 'max_connections' => 'max_connections', - 'max_user_connections' => 'max_user_connections', - ]; - - $html = $this->serverPrivileges->getHtmlForResourceLimits($row); - $this->assertStringContainsString( - '' . __('Resource limits') . '', - $html - ); - $this->assertStringContainsString( - __('Note: Setting these options to 0 (zero) removes the limit.'), - $html - ); - $this->assertStringContainsString( - 'MAX QUERIES PER HOUR', - $html - ); - $this->assertStringContainsString( - $row['max_connections'], - $html - ); - $this->assertStringContainsString( - $row['max_updates'], - $html - ); - $this->assertStringContainsString( - $row['max_connections'], - $html - ); - $this->assertStringContainsString( - $row['max_user_connections'], - $html - ); - $this->assertStringContainsString( - __('Limits the number of new connections the user may open per hour.'), - $html - ); - $this->assertStringContainsString( - __('Limits the number of simultaneous connections the user may have.'), - $html - ); - } - /** * Test for getSqlQueryForDisplayPrivTable * @@ -1031,8 +846,11 @@ class PrivilegesTest extends TestCase //validate 3: getHtmlForGlobalOrDbSpecificPrivs $this->assertStringContainsString( - '
', + '
', + $html + ); + $this->assertStringContainsString( + '', $html ); $this->assertStringContainsString( @@ -1094,6 +912,43 @@ class PrivilegesTest extends TestCase __('Note: Setting these options to 0 (zero) removes the limit.'), $html ); + $this->assertStringContainsString( + 'MAX QUERIES PER HOUR', + $html + ); + $this->assertStringContainsString( + 'id="text_max_updates" value="max_updates"', + $html + ); + $this->assertStringContainsString( + __('Limits the number of new connections the user may open per hour.'), + $html + ); + $this->assertStringContainsString( + __('Limits the number of simultaneous connections the user may have.'), + $html + ); + + $this->assertStringContainsString( + 'SSL', + $html + ); + $this->assertStringContainsString( + 'value="NONE"', + $html + ); + $this->assertStringContainsString( + 'value="ANY"', + $html + ); + $this->assertStringContainsString( + 'value="X509"', + $html + ); + $this->assertStringContainsString( + 'value="SPECIFIED"', + $html + ); $GLOBALS['dbi'] = $dbi_old; $this->serverPrivileges->dbi = $dbi_old;