Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Make posts visible to admins with status message
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 authored and greg0ire committed Jun 24, 2018
1 parent 7334550 commit aa99819
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Action/ViewPostAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
namespace Sonata\NewsBundle\Action;

use Sonata\NewsBundle\Model\BlogInterface;
use Sonata\NewsBundle\Model\PostInterface;
use Sonata\NewsBundle\Model\PostManagerInterface;
use Sonata\SeoBundle\Seo\SeoPageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

final class ViewPostAction extends Controller
{
Expand All @@ -31,15 +33,24 @@ final class ViewPostAction extends Controller
*/
private $postManager;

/**
* @var AuthorizationCheckerInterface
*/
private $authChecker;

/**
* @var SeoPageInterface|null
*/
private $seoPage;

public function __construct(BlogInterface $blog, PostManagerInterface $postManager)
{
public function __construct(
BlogInterface $blog,
PostManagerInterface $postManager,
AuthorizationCheckerInterface $authChecker
) {
$this->blog = $blog;
$this->postManager = $postManager;
$this->authChecker = $authChecker;
}

/**
Expand Down Expand Up @@ -84,4 +95,14 @@ public function setSeoPage(SeoPageInterface $seoPage = null)
{
$this->seoPage = $seoPage;
}

/**
* @return bool
*/
protected function isVisible(PostInterface $post)
{
return $post->isPublic() ||
$this->authChecker->isGranted('ROLE_SUPER_ADMIN') ||
$this->authChecker->isGranted('ROLE_SONATA_NEWS_ADMIN_POST_EDIT');
}
}
1 change: 1 addition & 0 deletions src/Resources/config/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<service id="Sonata\NewsBundle\Action\ViewPostAction" class="Sonata\NewsBundle\Action\ViewPostAction" public="true">
<argument type="service" id="sonata.news.blog"/>
<argument type="service" id="sonata.news.manager.post"/>
<argument type="service" id="security.authorization_checker"/>
<call method="setSeoPage">
<argument type="service" id="sonata.seo.page" on-invalid="null"/>
</call>
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/translations/SonataNewsBundle.de.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@
<source>form.label_class</source>
<target>CSS Klasse</target>
</trans-unit>
<trans-unit id="message_close">
<source>message_close</source>
<target>Schließen</target>
</trans-unit>
<trans-unit id="post_is_disabled">
<source>post_is_disabled</source>
<target>News ist noch nicht freigeschaltet.</target>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 8 additions & 0 deletions src/Resources/translations/SonataNewsBundle.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ Quick moderation links :
<source>form.label_class</source>
<target>CSS Class</target>
</trans-unit>
<trans-unit id="message_close">
<source>message_close</source>
<target>Close</target>
</trans-unit>
<trans-unit id="post_is_disabled">
<source>post_is_disabled</source>
<target>Post is not public.</target>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Resources/views/Post/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
</div>
{% endblock %}


{% if not post.isPublic %}
<div class="alert alert-danger alert-fixed">
<button type="button" class="close" data-dismiss="alert"
aria-label="{{ 'message_close'|trans({}, 'SonataNewsBundle') }}"
>&times;</button>
<i class="fa fa-eye-slash" aria-hidden="true"></i> {{ 'post_is_disabled'|trans({}, 'SonataNewsBundle') }}
</div>
{% endif %}

<article class="sonata-blog-post-container">
<header>
<div class="sonata-blog-post-date-container">
Expand Down

0 comments on commit aa99819

Please sign in to comment.