Upgrade user management page (#2417)

Before, the use of the user management page was a little bit tedious
when there was many users. One must select a user to view some
metrics, to update it, or to delete it.
Now, the view is clearer because it shows all users at once with
their metrics. I introduced a detail page that repeats the metrics
but also allow to purge the user's feeds, to update or delete the
user.

This is the first step to make that page more useful and user-friendly.
I have in mind to add a pager for when there is a lot of users, a metric
to know when was the last time the user was using the application, and
a flag to know if the user has admin rights.

See #2096 and #2504 for ideas and inspiration
This commit is contained in:
Alexis Degrugillier
2019-12-03 22:32:17 +01:00
committed by Alexandre Alapetite
parent 68c006b7ad
commit 0de7e84380
35 changed files with 253 additions and 73 deletions

View File

@@ -118,7 +118,6 @@ class FreshRSS_user_Controller extends Minz_ActionController {
Minz_Request::bad(_t('feedback.user.updated.error', $username),
array('c' => 'user', 'a' => 'manage'));
}
}
}
@@ -194,6 +193,23 @@ class FreshRSS_user_Controller extends Minz_ActionController {
}
}
public function purgeAction() {
if (!FreshRSS_Auth::hasAccess('admin')) {
Minz_Error::error(403);
}
if (Minz_Request::isPost()) {
$username = Minz_Request::param('username');
if (!FreshRSS_UserDAO::exists($username)) {
Minz_Error::error(404);
}
$feedDAO = FreshRSS_Factory::createFeedDao($username);
$feedDAO->purge();
}
}
/**
* This action displays the user management page.
*/
@@ -204,18 +220,22 @@ class FreshRSS_user_Controller extends Minz_ActionController {
Minz_View::prependTitle(_t('admin.user.title') . ' · ');
if (Minz_Request::isPost()) {
$action = Minz_Request::param('action');
if ('delete' === $action) {
$this->deleteAction();
} elseif ('update' === $action) {
$this->updateAction();
} elseif ('purge' === $action) {
$this->purgeAction();
}
}
$this->view->show_email_field = FreshRSS_Context::$system_conf->force_email_validation;
$this->view->current_user = Minz_Request::param('u');
$this->view->nb_articles = 0;
$this->view->size_user = 0;
if ($this->view->current_user) {
// Get information about the current user.
$entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user);
$this->view->nb_articles = $entryDAO->count();
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($this->view->current_user);
$this->view->size_user = $databaseDAO->size();
foreach (listUsers() as $user) {
$this->view->users[$user] = $this->retrieveUserDetails($user);
}
}
@@ -542,4 +562,30 @@ class FreshRSS_user_Controller extends Minz_ActionController {
Minz_Request::forward($redirect_url, true);
}
public function detailsAction() {
if (!FreshRSS_Auth::hasAccess('admin')) {
Minz_Error::error(403);
}
$username = Minz_Request::param('username');
if (!FreshRSS_UserDAO::exists($username)) {
Minz_Error::error(404);
}
$this->view->username = $username;
$this->view->details = $this->retrieveUserDetails($username);
}
private function retrieveUserDetails($username) {
$feedDAO = FreshRSS_Factory::createFeedDao($username);
$entryDAO = FreshRSS_Factory::createEntryDao($username);
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
return array(
'feed_count' => $feedDAO->count(),
'article_count' => $entryDAO->count(),
'database_size' => $databaseDAO->size(),
);
}
}