Make snip public index available if not logged in
This commit is contained in:
parent
22c8126cea
commit
5cec259469
@ -43,7 +43,10 @@ security:
|
||||
- { path: ^/logout$, role: ROLE_USER }
|
||||
- { path: ^/admin, role: ROLE_ADMIN }
|
||||
|
||||
- { path: ^/$, role: PUBLIC_ACCESS }
|
||||
- { path: ^/snip/single, role: PUBLIC_ACCESS }
|
||||
- { path: ^/snip/raw, role: PUBLIC_ACCESS }
|
||||
- { path: ^/snip/public$, role: PUBLIC_ACCESS }
|
||||
|
||||
- { path: ^/, role: ROLE_USER }
|
||||
|
||||
|
@ -11,6 +11,10 @@ class HomeController extends AbstractController
|
||||
#[Route('/', name: 'home')]
|
||||
public function home(): Response
|
||||
{
|
||||
if ($this->getUser()) {
|
||||
return $this->redirectToRoute('snip_index');
|
||||
} else {
|
||||
return $this->redirectToRoute('snip_public');
|
||||
}
|
||||
}
|
||||
}
|
@ -45,19 +45,25 @@ class SnipRepository extends ServiceEntityRepository
|
||||
$qb = $this->createQueryBuilder('s');
|
||||
$qb->where('s.createdBy = :user')
|
||||
->setParameter('user', $user)
|
||||
->orderBy('s.createdAt', 'DESC');
|
||||
->orderBy('s.createdAt', 'DESC')
|
||||
;
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findPublic(User $user): array
|
||||
public function findPublic(?User $user): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('s');
|
||||
$qb->where('s.public = :public')
|
||||
->andWhere('s.createdBy != :user')
|
||||
$qb = $this->createQueryBuilder('s')
|
||||
->where('s.public = :public')
|
||||
->setParameter('public', true)
|
||||
->orderBy('s.createdAt', 'DESC')
|
||||
;
|
||||
|
||||
if ($user) {
|
||||
$qb->andWhere('s.createdBy != :user')
|
||||
->setParameter('user', $user)
|
||||
->orderBy('s.createdAt', 'DESC');
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
@ -15,10 +15,10 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ path('snip_new') }}">New snip</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ path('snip_public') }}">Public snips</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<ul class="navbar-nav my-2 my-lg-0">
|
||||
{% if app.environment == 'dev' %}
|
||||
|
@ -3,9 +3,15 @@
|
||||
{% set title %}Snip {{ snip }}{% endset %}
|
||||
|
||||
{% block body %}
|
||||
{% if app.user %}
|
||||
<a href="{{ path('snip_index') }}" class="btn btn-primary">
|
||||
<i class="fa fa-arrow-left"></i> Back
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{{ path('snip_public') }}" class="btn btn-primary">
|
||||
<i class="fa fa-arrow-left"></i> Index
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if is_granted('edit', snip) %}
|
||||
<a class="btn btn-warning" href="{{ path('snip_edit', {snip: snip.id}) }}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Edit
|
||||
|
Loading…
x
Reference in New Issue
Block a user