Skip to content

Commit 6bd2971

Browse files
committed
Show unpublished on main news when user has privs
1 parent 9ab5c8a commit 6bd2971

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

controllers/News.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use \BNETDocs\Libraries\Exceptions\UnspecifiedViewException;
88
use \BNETDocs\Libraries\NewsPost;
99
use \BNETDocs\Libraries\Router;
10+
use \BNETDocs\Libraries\User;
1011
use \BNETDocs\Libraries\UserSession;
1112
use \BNETDocs\Models\News as NewsModel;
1213
use \BNETDocs\Views\NewsHtml as NewsHtmlView;
@@ -29,6 +30,16 @@ public function run(Router &$router) {
2930
}
3031
$model = new NewsModel();
3132
$model->user_session = UserSession::load($router);
33+
$model->user = (isset($model->user_session) ?
34+
new User($model->user_session->user_id) :
35+
null);
36+
$model->acl_allowed = ($model->user &&
37+
$model->user->getOptionsBitmask() & (
38+
User::OPTION_ACL_NEWS_CREATE |
39+
User::OPTION_ACL_NEWS_MODIFY |
40+
User::OPTION_ACL_NEWS_DELETE
41+
)
42+
);
3243
$this->getNews($model);
3344
ob_start();
3445
$view->render($model);
@@ -43,7 +54,7 @@ protected function getNews(NewsModel &$model) {
4354
$model->news_posts = NewsPost::getAllNews(true);
4455

4556
// Remove news posts that are not published
46-
if ($model->news_posts) {
57+
if (!$model->acl_allowed && $model->news_posts) {
4758
$i = count($model->news_posts) - 1;
4859
while ($i >= 0) {
4960
if (!($model->news_posts[$i]->getOptionsBitmask()

models/News.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
class News extends Model {
88

9+
public $acl_allowed;
910
public $news_posts;
11+
public $user;
1012
public $user_session;
1113

1214
public function __construct() {
1315
parent::__construct();
16+
$this->acl_allowed = null;
1417
$this->news_posts = [];
18+
$this->user = null;
1519
$this->user_session = null;
1620
}
1721

templates/News.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace BNETDocs\Templates;
33

44
use \BNETDocs\Libraries\Common;
55
use \BNETDocs\Libraries\Gravatar;
6+
use \BNETDocs\Libraries\NewsPost;
67
use \BNETDocs\Libraries\Pair;
78
use \BNETDocs\Libraries\User;
89

@@ -35,6 +36,9 @@ foreach ($this->context->news_posts as $news_post) {
3536
<a href="https://twitter.com/share?text=<?php echo urlencode($news_post->getTitle()); ?>&amp;url=<?php echo urlencode($url); ?>" rel="external" data-popup="1"><img class="social-btn float-right" src="<?php echo Common::relativeUrlToAbsolute("/a/social-twitter-24px.png"); ?>"/></a>
3637
<a href="https://facebook.com/sharer/sharer.php?u=<?php echo urlencode($url); ?>" rel="external" data-popup="1"><img class="social-btn float-right" src="<?php echo Common::relativeUrlToAbsolute("/a/social-facebook-24px.png"); ?>"/></a>
3738
<header><a href="<?php echo $url; ?>"><?php echo $news_post->getTitle(); ?></a></header>
39+
<?php if (!($news_post->getOptionsBitmask() & NewsPost::OPTION_PUBLISHED)) { ?>
40+
<section class="red"><p><strong>Warning:</strong> This news post is not yet published. You can view this because you are allowed to create, modify, or delete news posts.</p></section>
41+
<?php } ?>
3842
<section class="news"><img class="category" alt="<?php echo $news_post->getCategory()->getLabel(); ?>" title="<?php echo $news_post->getCategory()->getLabel(); ?>" src="<?php echo Common::relativeUrlToAbsolute("/a/news_categories/" . $news_post->getCategory()->getFilename()); ?>"/><?php echo $news_post->getContent(true); ?></section>
3943
<footer>
4044
<span class="float-left"><a href="<?php echo Common::relativeUrlToAbsolute("/user/" . urlencode($user_id) . "/" . Common::sanitizeForUrl($users[$user_id]->getName(), true)); ?>"><img class="avatar" src="<?php echo $avatar; ?>"/> <?php echo htmlspecialchars($users[$user_id]->getName(), ENT_HTML5, "UTF-8"); ?></a></span>

0 commit comments

Comments
 (0)