Merge pull request #14719 from MrPetovan/bug/14717-revert-moderation

Partially revert "Improve search for user in Modration module"
This commit is contained in:
Tobias Diekershoff 2025-01-23 07:38:48 +01:00 committed by GitHub
commit 4917380716
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 139 additions and 109 deletions

View file

@ -48,41 +48,8 @@ class Active extends BaseUsers
{
parent::content();
$action = (string) $this->parameters['action'] ?? '';
$uid = (int) $this->parameters['uid'] ?? 0;
$this->processGetActions();
if ($uid === 0) {
$this->systemMessages->addNotice($this->t('User not found'));
$this->baseUrl->redirect('moderation/users');
}
$user = User::getById($uid, ['username', 'blocked']);
if (!is_array($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 = [
@ -146,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');
}
}
}

View file

@ -48,40 +48,7 @@ class Blocked extends BaseUsers
{
parent::content();
$action = (string) $this->parameters['action'] ?? '';
$uid = (int) $this->parameters['uid'] ?? 0;
if ($uid === 0) {
$this->systemMessages->addNotice($this->t('User not found'));
$this->baseUrl->redirect('moderation/users');
}
$user = User::getById($uid, ['username', 'blocked']);
if (!is_array($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);
@ -145,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');
}
}
}

View file

@ -55,47 +55,7 @@ class Index extends BaseUsers
{
parent::content();
$action = (string) $this->parameters['action'] ?? '';
$uid = (int) $this->parameters['uid'] ?? 0;
if ($uid === 0) {
$this->systemMessages->addNotice($this->t('User not found'));
$this->baseUrl->redirect('moderation/users');
}
$user = User::getById($uid, ['username', 'blocked']);
if (!is_array($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);
@ -164,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');
}
}
}