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