diff --git a/src/Module/Moderation/Users/Active.php b/src/Module/Moderation/Users/Active.php index f25bb40ed2..1b11685f64 100644 --- a/src/Module/Moderation/Users/Active.php +++ b/src/Module/Moderation/Users/Active.php @@ -48,38 +48,8 @@ class Active extends BaseUsers { parent::content(); - $action = (string) $this->parameters['action'] ?? ''; - $uid = (int) $this->parameters['uid'] ?? 0; + $this->processGetActions(); - 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->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'); + } + } } diff --git a/src/Module/Moderation/Users/Blocked.php b/src/Module/Moderation/Users/Blocked.php index 6d4d1cce16..fbdbc8d8c7 100644 --- a/src/Module/Moderation/Users/Blocked.php +++ b/src/Module/Moderation/Users/Blocked.php @@ -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'); + } + } } diff --git a/src/Module/Moderation/Users/Index.php b/src/Module/Moderation/Users/Index.php index 61208d3403..7d195c1096 100644 --- a/src/Module/Moderation/Users/Index.php +++ b/src/Module/Moderation/Users/Index.php @@ -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'); + } + } }