Commit 33c2e2b8 authored by Emma's avatar Emma

page for showing active forum bans for each user

parent 10a5a81e
Pipeline #16534785 failed with stage
in 6 minutes and 18 seconds
......@@ -87,3 +87,10 @@ clear_inbox:
path: /clear_inbox.{_format}
methods: [POST]
requirements: { _format: html|json }
user_forum_bans:
controller: App\Controller\UserController::listForumBans
defaults: { page: 1 }
path: /user/{username}/forum_bans/{page}
methods: [GET]
requirements: { username: \w+, page: \d+ }
......@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Form\Model\UserFilterData;
use App\Form\UserFilterType;
use App\Repository\ForumBanRepository;
use Doctrine\ORM\EntityManager;
use App\Entity\User;
use App\Entity\UserBlock;
......@@ -368,4 +369,20 @@ final class UserController extends AbstractController {
'username' => $user->getUsername(),
]);
}
/**
* @IsGranted("ROLE_ADMIN")
*
* @param User $user
* @param ForumBanRepository $repository
* @param int $page
*
* @return Response
*/
public function listForumBans(User $user, ForumBanRepository $repository, int $page) {
return $this->render('user/forum_bans.html.twig', [
'bans' => $repository->findActiveBansByUser($user, $page),
'user' => $user,
]);
}
}
......@@ -4,8 +4,10 @@ namespace App\Repository;
use App\Entity\Forum;
use App\Entity\ForumBan;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Types\Type;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
......@@ -38,7 +40,29 @@ class ForumBanRepository extends ServiceEntityRepository {
->andWhere('m.expiresAt IS NULL OR m.expiresAt >= :now')
->orderBy('m.timestamp', 'DESC')
->setParameter('forum', $forum)
->setParameter('now', new \DateTime(), 'datetimetz');
->setParameter('now', new \DateTime(), Type::DATETIMETZ);
$pager = new Pagerfanta(new DoctrineORMAdapter($qb));
$pager->setMaxPerPage($maxPerPage);
$pager->setCurrentPage($page);
return $pager;
}
public function findActiveBansByUser(User $user, int $page, int $maxPerPage = 25) {
$qb = $this->createQueryBuilder('m')
->leftJoin(ForumBan::class, 'b',
'WITH', 'm.user = b.user AND '.
'm.forum = b.forum AND '.
'm.timestamp < b.timestamp'
)
->where('b.timestamp IS NULL')
->andWhere('m.banned = TRUE')
->andWhere('m.user = :user')
->andWhere('m.expiresAt IS NULL OR m.expiresAt >= :now')
->orderBy('m.timestamp', 'DESC')
->setParameter('user', $user)
->setParameter('now', new \DateTime(), Type::DATETIMETZ);
$pager = new Pagerfanta(new DoctrineORMAdapter($qb));
$pager->setMaxPerPage($maxPerPage);
......
{% extends 'base.html.twig' %}
{% block title 'title.user_forum_bans'|trans({'%user%': user.username}) %}
{% block head %}
{{ parent() }}
{{ include('_includes/meta_pagination.html.twig', {pager: bans}, with_context=false) }}
{% endblock %}
{% block body %}
{% from 'user/_macros.html.twig' import user_link %}
<h1 class="page-heading">
{{ 'title.user_forum_bans'|trans({'%user%': user_link(user, {prefix: true})})|raw }}
</h1>
{% if bans|length > 0 %}
<table class="table">
<thead>
<tr>
<th>{{ 'label.forum'|trans }}</th>
<th>{{ 'label.banned_by'|trans }}</th>
<th>{{ 'label.banned'|trans }}</th>
<th>{{ 'label.expires'|trans }}</th>
<th>{{ 'label.reason'|trans }}</th>
</tr>
</thead>
<tbody>
{% for ban in bans %}
<tr>
<td><a href="{{ path('forum', {forum_name: ban.forum.name}) }}">/f/{{ ban.forum.name }}</a></td>
<td>{{ user_link(ban.bannedBy) }}</td>
<td>
{% with { date: ban.timestamp|localizeddate('long', 'short') } %}
<time datetime="{{ ban.timestamp|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% endwith %}
</td>
<td>
{% if ban.expiryTime %}
{% set date = ban.expiryTime|localizeddate('long', 'short') %}
<time datetime="{{ ban.expiryTime|date('c') }}" class="relative-time" title="{{ date }}">
{{- date -}}
</time>
{% else %}
<small>{{ 'label.never'|trans }}</small>
{% endif %}
</td>
<td>{{ ban.reason }}</td>
<td>
<a href="{{ path('unban_user', {username: ban.user.username}) }}" class="button button--inline">
{{ 'action.unban'|trans }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<div class="alert alert--notice">
<p>{{ 'flash.no_entries_to_display'|trans }}</p>
</div>
{% endif %}
{{ include('_includes/pagination.html.twig', {pager: bans}, with_context=false) }}
{% endblock %}
......@@ -65,6 +65,11 @@
{% endif %}
{% endset %}
{% set toolbox_items = toolbox_items|merge([item]) %}
{% set item %}
<li><a href="{{ path('user_forum_bans', {username: user.username}) }}">{{ 'nav.forum_bans'|trans }}</a></li>
{% endset %}
{% set toolbox_items = toolbox_items|merge([item]) %}
{% endif %}
{% endif %}
......
......@@ -334,6 +334,7 @@ nav:
theme_settings: Theme settings
filter_results: Filter results
users: Users
forum_bans: Forum bans
placeholder:
default: (default)
......@@ -438,6 +439,7 @@ title:
global_moderation_log: Global moderation log
delete_submission: Delete submission
list_of_users: 'List of users, page #%page%'
user_forum_bans: "%user%'s forum bans"
user:
submissions: Submissions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment