aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers/userController.php
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2019-12-03 22:32:17 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2019-12-03 22:32:17 +0100
commit0de7e84380dff5222e6728aacbbb42abaac51dd9 (patch)
tree07eba3a6070f11fd966c9f257aa652b6f6242eed /app/Controllers/userController.php
parent68c006b7ad61d0730a3aa8f75c6232c00d0f14e1 (diff)
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
Diffstat (limited to 'app/Controllers/userController.php')
-rw-r--r--app/Controllers/userController.php66
1 files changed, 56 insertions, 10 deletions
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php
index 39b4769fd..05e7475e7 100644
--- a/app/Controllers/userController.php
+++ b/app/Controllers/userController.php
@@ -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(),
+ );
+ }
}