Skip to content

Commit d579b49

Browse files
committed
feature #428 Simplify the post list (admin) displaying your posts only (yceruto)
This PR was merged into the master branch. Discussion ---------- Simplify the post list (admin) displaying your posts only We are currently unable to show a post if the logged user is not the author (i.e. in backend). | Before | After | | ---- | ---- | | ![posts-list-before](https://cloud.githubusercontent.com/assets/2028198/21901130/843901d4-d8c4-11e6-84e5-ecdae35854f1.png) | ![posts-list-after](https://cloud.githubusercontent.com/assets/2028198/21901731/e20e3b1a-d8c6-11e6-94e5-dff0f22d6b86.png) | Commits ------- 1ff045f Show post list (admin) from logged user only
2 parents 63681da + 1ff045f commit d579b49

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

app/Resources/views/admin/blog/index.html.twig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
<thead>
1010
<tr>
1111
<th scope="col">{{ 'label.title'|trans }}</th>
12-
<th scope="col"><i class="fa fa-user" aria-hidden="true"></i> {{ 'label.author'|trans }}</th>
1312
<th scope="col"><i class="fa fa-calendar" aria-hidden="true"></i> {{ 'label.published_at'|trans }}</th>
14-
<th scope="col"><i class="fa fa-cogs" aria-hidden="true"></i> {{ 'label.actions'|trans }}</th>
13+
<th scope="col" class="col-xs-1"><i class="fa fa-cogs" aria-hidden="true"></i> {{ 'label.actions'|trans }}</th>
1514
</tr>
1615
</thead>
1716
<tbody>
1817
{% for post in posts %}
1918
<tr>
2019
<td>{{ post.title }}</td>
21-
<td>{{ post.authorEmail }}</td>
2220
{# it's not mandatory to set the timezone in localizeddate(). This is done to
2321
avoid errors when the 'intl' PHP extension is not available and the application
2422
is forced to use the limited "intl polyfill", which only supports UTC and GMT #}
@@ -29,11 +27,9 @@
2927
{{ 'action.show'|trans }}
3028
</a>
3129

32-
{% if post.isAuthor(app.user) %}
33-
<a href="{{ path('admin_post_edit', { id: post.id }) }}" class="btn btn-sm btn-primary">
34-
<i class="fa fa-edit" aria-hidden="true"></i> {{ 'action.edit'|trans }}
35-
</a>
36-
{% endif %}
30+
<a href="{{ path('admin_post_edit', { id: post.id }) }}" class="btn btn-sm btn-primary">
31+
<i class="fa fa-edit" aria-hidden="true"></i> {{ 'action.edit'|trans }}
32+
</a>
3733
</div>
3834
</td>
3935
</tr>

src/AppBundle/Controller/Admin/BlogController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class BlogController extends Controller
5555
public function indexAction()
5656
{
5757
$entityManager = $this->getDoctrine()->getManager();
58-
$posts = $entityManager->getRepository(Post::class)->findBy([], ['publishedAt' => 'DESC']);
58+
$posts = $entityManager->getRepository(Post::class)->findBy(['authorEmail' => $this->getUser()->getEmail()], ['publishedAt' => 'DESC']);
5959

6060
return $this->render('admin/blog/index.html.twig', ['posts' => $posts]);
6161
}

0 commit comments

Comments
 (0)