mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-08 08:14:25 +02:00
New area "moderation"
- Moved several admin pages to the moderation area - ACL still is checking for administrator credentials
This commit is contained in:
parent
4fb7e9b023
commit
18f54f4425
61 changed files with 1707 additions and 1417 deletions
161
src/Module/Moderation/Users/Active.php
Normal file
161
src/Module/Moderation/Users/Active.php
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Active extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError($this->baseUrl->get(true), 'moderation_users_active');
|
||||
|
||||
$users = $request['user'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_block'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user blocked', '%s users blocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_delete'])) {
|
||||
foreach ($users as $uid) {
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
User::remove($uid);
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect($this->args->getQueryString());
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$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 = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'active', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
|
||||
|
||||
$count = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/active.tpl');
|
||||
return self::getTabsHTML('active') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Active Accounts'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$delete' => $this->t('Delete'),
|
||||
'$block' => $this->t('Block'),
|
||||
'$blocked' => $this->t('User blocked'),
|
||||
'$siteadmin' => $this->t('Site admin'),
|
||||
'$accountexpired' => $this->t('Account expired'),
|
||||
'$h_newuser' => $this->t('Create a new user'),
|
||||
|
||||
'$th_users' => $th_users,
|
||||
'$order_users' => $order,
|
||||
'$order_direction_users' => $order_direction,
|
||||
|
||||
'$confirm_delete_multi' => $this->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
'$confirm_delete' => $this->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users_active'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
160
src/Module/Moderation/Users/Blocked.php
Normal file
160
src/Module/Moderation/Users/Blocked.php
Normal file
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Blocked extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked');
|
||||
|
||||
$users = $request['user'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_unblock'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid, false);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user unblocked', '%s users unblocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_delete'])) {
|
||||
foreach ($users as $uid) {
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
User::remove($uid);
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('moderation/users/blocked');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$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;
|
||||
}
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$valid_orders = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'blocked', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
|
||||
|
||||
$count = $this->database->count('user', ['blocked' => true, 'verified' => true]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/blocked.tpl');
|
||||
return self::getTabsHTML('blocked') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Blocked Users'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$delete' => $this->t('Delete'),
|
||||
'$blocked' => $this->t('User blocked'),
|
||||
'$unblock' => $this->t('Unblock'),
|
||||
'$siteadmin' => $this->t('Site admin'),
|
||||
'$accountexpired' => $this->t('Account expired'),
|
||||
|
||||
'$th_users' => $th_users,
|
||||
'$order_users' => $order,
|
||||
'$order_direction_users' => $order_direction,
|
||||
|
||||
'$confirm_delete_multi' => $this->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
'$confirm_delete' => $this->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users_blocked'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count)
|
||||
]);
|
||||
}
|
||||
}
|
76
src/Module/Moderation/Users/Create.php
Normal file
76
src/Module/Moderation/Users/Create.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Moderation\Users;
|
||||
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Create extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/create', 'admin_users_create');
|
||||
|
||||
$nu_name = $request['new_user_name'] ?? '';
|
||||
$nu_nickname = $request['new_user_nickname'] ?? '';
|
||||
$nu_email = $request['new_user_email'] ?? '';
|
||||
$nu_language = DI::config()->get('system', 'language');
|
||||
|
||||
if ($nu_name !== '' && $nu_email !== '' && $nu_nickname !== '') {
|
||||
try {
|
||||
User::createMinimal($nu_name, $nu_email, $nu_nickname, $nu_language);
|
||||
$this->baseUrl->redirect('admin/users');
|
||||
} catch (\Exception $ex) {
|
||||
$this->systemMessages->addNotice($ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('admin/users/create');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/users/create.tpl');
|
||||
return self::getTabsHTML('all') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Administration'),
|
||||
'$page' => $this->t('New User'),
|
||||
'$submit' => $this->t('Add User'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('admin_users_create'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$newusername' => ['new_user_name', $this->t('Name'), '', $this->t('Name of the new user.')],
|
||||
'$newusernickname' => ['new_user_nickname', $this->t('Nickname'), '', $this->t('Nickname of the new user.')],
|
||||
'$newuseremail' => ['new_user_email', $this->t('Email'), '', $this->t('Email address of the new user.'), '', '', 'email'],
|
||||
]);
|
||||
}
|
||||
}
|
96
src/Module/Moderation/Users/Deleted.php
Normal file
96
src/Module/Moderation/Users/Deleted.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Deleted extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/users/deleted', 'moderation_users_deleted');
|
||||
|
||||
// @TODO: Implement user deletion cancellation
|
||||
|
||||
$this->baseUrl->redirect('moderation/users/deleted');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$valid_orders = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'removed', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$count = $this->database->count('user', ['account_removed' => true]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/deleted.tpl');
|
||||
return self::getTabsHTML('deleted') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Users awaiting permanent deletion'),
|
||||
|
||||
'$th_deleted' => [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Permanent deletion')],
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users_deleted'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
179
src/Module/Moderation/Users/Index.php
Normal file
179
src/Module/Moderation/Users/Index.php
Normal file
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Index extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users');
|
||||
|
||||
$users = $request['user'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_block'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user blocked', '%s users blocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_unblock'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid, false);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user unblocked', '%s users unblocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_delete'])) {
|
||||
foreach ($users as $uid) {
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
User::remove($uid);
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect($this->args->getQueryString());
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$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->get(true), '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;
|
||||
}
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$valid_orders = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
|
||||
|
||||
$count = $this->database->count('user', ["`uid` != ?", 0]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/index.tpl');
|
||||
return self::getTabsHTML('all') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Users'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$h_deleted' => $this->t('User waiting for permanent deletion'),
|
||||
'$delete' => $this->t('Delete'),
|
||||
'$block' => $this->t('Block'),
|
||||
'$blocked' => $this->t('User blocked'),
|
||||
'$unblock' => $this->t('Unblock'),
|
||||
'$siteadmin' => $this->t('Site admin'),
|
||||
'$accountexpired' => $this->t('Account expired'),
|
||||
|
||||
'$h_users' => $this->t('Users'),
|
||||
'$h_newuser' => $this->t('Create a new user'),
|
||||
'$th_deleted' => [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Permanent deletion')],
|
||||
'$th_users' => $th_users,
|
||||
'$order_users' => $order,
|
||||
'$order_direction_users' => $order_direction,
|
||||
|
||||
'$confirm_delete_multi' => $this->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
'$confirm_delete' => $this->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
116
src/Module/Moderation/Users/Pending.php
Normal file
116
src/Module/Moderation/Users/Pending.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\Register;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Pending extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending');
|
||||
|
||||
$pending = $request['pending'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_approve'])) {
|
||||
foreach ($pending as $hash) {
|
||||
User::allow($hash);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user approved', '%s users approved', count($pending)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_deny'])) {
|
||||
foreach ($pending as $hash) {
|
||||
User::deny($hash);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s registration revoked', '%s registrations revoked', count($pending)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('admin/users/pending');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$user = User::getById($uid, ['username', 'blocked']);
|
||||
if (!$user) {
|
||||
$this->systemMessages->addNotice($this->t('User not found'));
|
||||
$this->baseUrl->redirect('admin/users');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'allow':
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending', 't');
|
||||
User::allow(Register::getPendingForUser($uid)['hash'] ?? '');
|
||||
$this->systemMessages->addNotice($this->t('Account approved.'));
|
||||
$this->baseUrl->redirect('admin/users/pending');
|
||||
break;
|
||||
case 'deny':
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending', 't');
|
||||
User::deny(Register::getPendingForUser($uid)['hash'] ?? '');
|
||||
$this->systemMessages->addNotice($this->t('Registration revoked'));
|
||||
$this->baseUrl->redirect('admin/users/pending');
|
||||
break;
|
||||
}
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$pending = Register::getPending($pager->getStart(), $pager->getItemsPerPage());
|
||||
|
||||
$count = Register::getPendingCount();
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/users/pending.tpl');
|
||||
return self::getTabsHTML('pending') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Administration'),
|
||||
'$page' => $this->t('User registrations awaiting review'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$th_pending' => [$this->t('Request date'), $this->t('Name'), $this->t('Email')],
|
||||
'$no_pending' => $this->t('No registrations.'),
|
||||
'$pendingnotetext' => $this->t('Note from the user'),
|
||||
'$approve' => $this->t('Approve'),
|
||||
'$deny' => $this->t('Deny'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('admin_users_pending'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$pending' => $pending,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue