From c534e85a055d1b1887ecca408f9a107eafe9abec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sun, 8 Sep 2019 20:52:39 -0300 Subject: [PATCH] Extract HTML from display user overview page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Server\Privileges::getHtmlForUserOverview Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Server/Privileges.php | 33 ++++++++++--------- .../server/privileges/user_overview.twig | 29 ++++++++++++++++ 2 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 templates/server/privileges/user_overview.twig diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 360a787fbc..d0a9a4f756 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -3551,10 +3551,7 @@ class Privileges */ public function getHtmlForUserOverview($pmaThemeImage, $text_dir) { - $html_output = '

' . "\n" - . Util::getIcon('b_usrlist') - . __('User accounts overview') . "\n" - . '

' . "\n"; + global $is_createuser; $password_column = 'Password'; $server_type = Util::getServerType(); @@ -3589,6 +3586,7 @@ class Privileges DatabaseInterface::QUERY_STORE ); + $errorMessages = ''; if (! $res) { // the query failed! This may have two reasons: // - the user does not have enough privileges @@ -3605,8 +3603,8 @@ class Privileges ); if (! $res) { - $html_output .= $this->getHtmlForViewUsersError(); - $html_output .= $this->getAddUserHtmlFieldset(); + $errorMessages .= $this->getHtmlForViewUsersError(); + $errorMessages .= $this->getAddUserHtmlFieldset(); } else { // This message is hardcoded because I will replace it by // a automatic repair feature soon. @@ -3615,7 +3613,7 @@ class Privileges . 'Please run the mysql_upgrade command' . ' that should be included in your MySQL server distribution' . ' to solve this problem!'; - $html_output .= Message::rawError($raw)->getDisplay(); + $errorMessages .= Message::rawError($raw)->getDisplay(); } $this->dbi->freeResult($res); } else { @@ -3626,7 +3624,7 @@ class Privileges foreach ($db_rights as $right) { foreach ($right as $account) { if (empty($account['User']) && $account['Host'] == 'localhost') { - $html_output .= Message::notice( + $emptyUserNotice = Message::notice( __( 'A user account allowing any user from localhost to ' . 'connect is present. This will prevent other users ' @@ -3645,7 +3643,7 @@ class Privileges * Also not necessary if there is less than 20 privileges */ if ($this->dbi->numRows($res_all) > 20) { - $html_output .= $this->getHtmlForInitials($array_initials); + $initials = $this->getHtmlForInitials($array_initials); } /** @@ -3656,15 +3654,13 @@ class Privileges || isset($_GET['showall']) || $this->dbi->numRows($res) < 50 ) { - $html_output .= $this->getUsersOverview( + $usersOverview = $this->getUsersOverview( $res, $db_rights, $pmaThemeImage, $text_dir ); - } else { - $html_output .= $this->getAddUserHtmlFieldset(); - } // end if (display overview) + } $response = Response::getInstance(); if (! $response->isAjax() @@ -3706,11 +3702,18 @@ class Privileges Message::NOTICE ); } - $html_output .= $flushnote->getDisplay(); + $flushNotice = $flushnote->getDisplay(); } } - return $html_output; + return $this->template->render('server/privileges/user_overview', [ + 'error_messages' => $errorMessages, + 'empty_user_notice' => $emptyUserNotice ?? '', + 'initials' => $initials ?? '', + 'users_overview' => $usersOverview ?? '', + 'is_createuser' => $is_createuser, + 'flush_notice' => $flushNotice ?? '', + ]); } /** diff --git a/templates/server/privileges/user_overview.twig b/templates/server/privileges/user_overview.twig new file mode 100644 index 0000000000..10c91f4e85 --- /dev/null +++ b/templates/server/privileges/user_overview.twig @@ -0,0 +1,29 @@ +
+

+ {{ get_icon('b_usrlist') }} + {% trans 'User accounts overview' %} +

+
+ +{{ error_messages|raw }} + +{{ empty_user_notice|raw }} + +{{ initials|raw }} + +{% if users_overview is not empty %} + {{ users_overview|raw }} +{% elseif is_createuser %} +
+
+
+ {% trans %}New{% context %}Create new user{% endtrans %} + + {{ get_icon('b_usradd', 'Add user account'|trans) }} + +
+
+
+{% endif %} + +{{ flush_notice|raw }}