]> git.mxchange.org Git - friendica.git/commitdiff
Extract GET action processing in Moderation modules
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 23 Jan 2025 02:51:03 +0000 (21:51 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 23 Jan 2025 02:51:03 +0000 (21:51 -0500)
src/Module/Moderation/Users/Active.php
src/Module/Moderation/Users/Blocked.php
src/Module/Moderation/Users/Index.php

index f25bb40ed2779917708e4dcfbd685a92263ecafd..1b11685f6410933b0b28a273cedcdf9233422933 100644 (file)
@@ -48,38 +48,8 @@ class Active extends BaseUsers
        {
                parent::content();
 
-               $action = (string) $this->parameters['action'] ?? '';
-               $uid    = (int) $this->parameters['uid'] ?? 0;
-
-               if ($uid !== 0) {
-                       $user = User::getById($uid, ['username', 'blocked']);
-                       if (!$user) {
-                               $this->systemMessages->addNotice($this->t('User not found'));
-                               $this->baseUrl->redirect('moderation/users');
-                       }
-               }
-
-               switch ($action) {
-                       case 'delete':
-                               if ($this->session->getLocalUserId() != $uid) {
-                                       self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
-                                       // delete user
-                                       User::remove($uid);
-
-                                       $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
-                               } else {
-                                       $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
-                               }
+               $this->processGetActions();
 
-                               $this->baseUrl->redirect('moderation/users/active');
-                               break;
-                       case 'block':
-                               self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
-                               User::block($uid);
-                               $this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
-                               $this->baseUrl->redirect('moderation/users/active');
-                               break;
-               }
                $pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
 
                $valid_orders = [
@@ -143,4 +113,48 @@ class Active extends BaseUsers
                        '$pager' => $pager->renderFull($count),
                ]);
        }
+
+       /**
+        * @return void
+        * @throws \Friendica\Network\HTTPException\FoundException
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \Friendica\Network\HTTPException\MovedPermanentlyException
+        * @throws \Friendica\Network\HTTPException\NotFoundException
+        * @throws \Friendica\Network\HTTPException\TemporaryRedirectException
+        */
+       private function processGetActions(): void
+       {
+               $action = (string)$this->parameters['action'] ?? '';
+               $uid = (int)$this->parameters['uid'] ?? 0;
+
+               if ($uid === 0) {
+                       return;
+               }
+
+               $user = User::getById($uid, ['username']);
+               if (!$user) {
+                       $this->systemMessages->addNotice($this->t('User not found'));
+                       $this->baseUrl->redirect('moderation/users');
+               }
+
+               switch ($action) {
+                       case 'delete':
+                               if ($this->session->getLocalUserId() != $uid) {
+                                       self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
+                                       // delete user
+                                       User::remove($uid);
+
+                                       $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
+                               } else {
+                                       $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
+                               }
+
+                               $this->baseUrl->redirect('moderation/users/active');
+                       case 'block':
+                               self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
+                               User::block($uid);
+                               $this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
+                               $this->baseUrl->redirect('moderation/users/active');
+               }
+       }
 }
index 6d4d1cce163a99ed80a47d808ef38165d01816b7..fbdbc8d8c7e338cb3f35d1b0458f79330a7854d7 100644 (file)
@@ -48,37 +48,7 @@ class Blocked extends BaseUsers
        {
                parent::content();
 
-               $action = (string) $this->parameters['action'] ?? '';
-               $uid    = (int) $this->parameters['uid'] ?? 0;
-
-               if ($uid !== 0) {
-                       $user = User::getById($uid, ['username', 'blocked']);
-                       if (!$user) {
-                               $this->systemMessages->addNotice($this->t('User not found'));
-                               $this->baseUrl->redirect('moderation/users');
-                       }
-               }
-
-               switch ($action) {
-                       case 'delete':
-                               if ($this->session->getLocalUserId() != $uid) {
-                                       self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked', 't');
-                                       // delete user
-                                       User::remove($uid);
-
-                                       $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
-                               } else {
-                                       $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
-                               }
-                               $this->baseUrl->redirect('moderation/users/blocked');
-                               break;
-                       case 'unblock':
-                               self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked', 't');
-                               User::block($uid, false);
-                               $this->systemMessages->addNotice($this->t('User "%s" unblocked', $user['username']));
-                               $this->baseUrl->redirect('moderation/users/blocked');
-                               break;
-               }
+               $this->processGetActions();
 
                $pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
 
@@ -142,4 +112,47 @@ class Blocked extends BaseUsers
                        '$pager' => $pager->renderFull($count)
                ]);
        }
+
+       /**
+        * @return void
+        * @throws \Friendica\Network\HTTPException\FoundException
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \Friendica\Network\HTTPException\MovedPermanentlyException
+        * @throws \Friendica\Network\HTTPException\NotFoundException
+        * @throws \Friendica\Network\HTTPException\TemporaryRedirectException
+        */
+       private function processGetActions(): void
+       {
+               $action = (string)$this->parameters['action'] ?? '';
+               $uid = (int)$this->parameters['uid'] ?? 0;
+
+               if ($uid === 0) {
+                       return;
+               }
+
+               $user = User::getById($uid, ['username']);
+               if (!$user) {
+                       $this->systemMessages->addNotice($this->t('User not found'));
+                       $this->baseUrl->redirect('moderation/users');
+               }
+
+               switch ($action) {
+                       case 'delete':
+                               if ($this->session->getLocalUserId() != $uid) {
+                                       self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked', 't');
+                                       // delete user
+                                       User::remove($uid);
+
+                                       $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
+                               } else {
+                                       $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
+                               }
+                               $this->baseUrl->redirect('moderation/users/blocked');
+                       case 'unblock':
+                               self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked', 't');
+                               User::block($uid, false);
+                               $this->systemMessages->addNotice($this->t('User "%s" unblocked', $user['username']));
+                               $this->baseUrl->redirect('moderation/users/blocked');
+               }
+       }
 }
index 61208d3403fae23f9ea39b50c6ce961d8a10fb05..7d195c109622b599151b4adf9e661cfffe17492b 100644 (file)
@@ -55,44 +55,7 @@ class Index extends BaseUsers
        {
                parent::content();
 
-               $action = (string) $this->parameters['action'] ?? '';
-               $uid    = (int) $this->parameters['uid'] ?? 0;
-
-               if ($uid !== 0) {
-                       $user = User::getById($uid, ['username', 'blocked']);
-                       if (!$user) {
-                               $this->systemMessages->addNotice($this->t('User not found'));
-                               $this->baseUrl->redirect('moderation/users');
-                       }
-               }
-
-               switch ($action) {
-                       case 'delete':
-                               if ($this->session->getLocalUserId() != $uid) {
-                                       self::checkFormSecurityTokenRedirectOnError($this->baseUrl, 'moderation_users', 't');
-                                       // delete user
-                                       User::remove($uid);
-
-                                       $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
-                               } else {
-                                       $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
-                               }
-
-                               $this->baseUrl->redirect('moderation/users');
-                               break;
-                       case 'block':
-                               self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
-                               User::block($uid);
-                               $this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
-                               $this->baseUrl->redirect('moderation/users');
-                               break;
-                       case 'unblock':
-                               self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
-                               User::block($uid, false);
-                               $this->systemMessages->addNotice($this->t('User "%s" unblocked', $user['username']));
-                               $this->baseUrl->redirect('moderation/users');
-                               break;
-               }
+               $this->processGetActions();
 
                $pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
 
@@ -161,4 +124,53 @@ class Index extends BaseUsers
                        '$pager' => $pager->renderFull($count),
                ]);
        }
+
+       /**
+        * @return void
+        * @throws \Friendica\Network\HTTPException\FoundException
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \Friendica\Network\HTTPException\MovedPermanentlyException
+        * @throws \Friendica\Network\HTTPException\NotFoundException
+        * @throws \Friendica\Network\HTTPException\TemporaryRedirectException
+        */
+       private function processGetActions(): void
+       {
+               $action = (string) $this->parameters['action'] ?? '';
+               $uid = (int) $this->parameters['uid'] ?? 0;
+
+               if ($uid === 0) {
+                       return;
+               }
+
+               $user = User::getById($uid, ['username']);
+               if (!$user) {
+                       $this->systemMessages->addNotice($this->t('User not found'));
+                       $this->baseUrl->redirect('moderation/users');
+               }
+
+               switch ($action) {
+                       case 'delete':
+                               if ($this->session->getLocalUserId() != $uid) {
+                                       self::checkFormSecurityTokenRedirectOnError($this->baseUrl, 'moderation_users', 't');
+                                       // delete user
+                                       User::remove($uid);
+
+                                       $this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
+                               } else {
+                                       $this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
+                               }
+
+                               $this->baseUrl->redirect('moderation/users');
+                       case 'block':
+                               self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
+                               User::block($uid);
+                               $this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
+                               $this->baseUrl->redirect('moderation/users');
+                       case 'unblock':
+                               self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
+                               User::block($uid, false);
+                               $this->systemMessages->addNotice($this->t('User "%s" unblocked', $user['username']));
+                               $this->baseUrl->redirect('moderation/users');
+               }
+       }
 }