Skip to content

Commit 309af0b

Browse files
committed
Add checking of ACL when commenting
1 parent 7e6cd23 commit 309af0b

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

src/controllers/Comment/Create.php

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use \BNETDocs\Libraries\Exceptions\UnspecifiedViewException;
1010
use \BNETDocs\Libraries\Logger;
1111
use \BNETDocs\Libraries\Router;
12+
use \BNETDocs\Libraries\User;
1213
use \BNETDocs\Libraries\UserSession;
1314
use \BNETDocs\Models\Comment\Create as CreateModel;
1415
use \BNETDocs\Views\Comment\CreateJSON as CreateJSONView;
@@ -26,6 +27,12 @@ public function run(Router &$router) {
2627
}
2728
$model = new CreateModel();
2829
$model->user_session = UserSession::load($router);
30+
$model->user = (isset($model->user_session) ?
31+
new User($model->user_session->user_id) : null);
32+
33+
$model->acl_allowed = ($model->user &&
34+
$model->user->getOptionsBitmask() & User::OPTION_ACL_COMMENT_CREATE
35+
);
2936

3037
$code = 500;
3138
if (!$model->user_session) {
@@ -57,27 +64,33 @@ protected function createComment(Router &$router, CreateModel &$model) {
5764
$p_type = (isset($query["parent_type"]) ? $query["parent_type"] : null);
5865
$content = (isset($query["content" ]) ? $query["content" ] : null);
5966

60-
if ($p_id !== null) $p_id = (int) $p_id;
61-
if ($p_type !== null) $p_type = (int) $p_type;
62-
63-
switch ($p_type) {
64-
case CommentLib::PARENT_TYPE_DOCUMENT: $origin = "/document/"; break;
65-
case CommentLib::PARENT_TYPE_COMMENT: $origin = "/comment/"; break;
66-
case CommentLib::PARENT_TYPE_NEWS_POST: $origin = "/news/"; break;
67-
case CommentLib::PARENT_TYPE_PACKET: $origin = "/packet/"; break;
68-
case CommentLib::PARENT_TYPE_SERVER: $origin = "/server/"; break;
69-
case CommentLib::PARENT_TYPE_USER: $origin = "/user/"; break;
70-
default: throw new UnexpectedValueException("Parent type: " . $p_type);
71-
}
72-
$origin = Common::relativeUrlToAbsolute($origin . $p_id . "#comments");
73-
$model->origin = $origin;
74-
75-
if (empty($content)) {
67+
if (!$model->acl_allowed) {
7668
$success = false;
7769
} else {
78-
$success = CommentLib::create(
79-
$p_type, $p_id, $model->user_session->user_id, $content
80-
);
70+
71+
if ($p_id !== null) $p_id = (int) $p_id;
72+
if ($p_type !== null) $p_type = (int) $p_type;
73+
74+
switch ($p_type) {
75+
case CommentLib::PARENT_TYPE_DOCUMENT: $origin = "/document/"; break;
76+
case CommentLib::PARENT_TYPE_COMMENT: $origin = "/comment/"; break;
77+
case CommentLib::PARENT_TYPE_NEWS_POST: $origin = "/news/"; break;
78+
case CommentLib::PARENT_TYPE_PACKET: $origin = "/packet/"; break;
79+
case CommentLib::PARENT_TYPE_SERVER: $origin = "/server/"; break;
80+
case CommentLib::PARENT_TYPE_USER: $origin = "/user/"; break;
81+
default: throw new UnexpectedValueException("Parent type: " . $p_type);
82+
}
83+
$origin = Common::relativeUrlToAbsolute($origin . $p_id . "#comments");
84+
$model->origin = $origin;
85+
86+
if (empty($content)) {
87+
$success = false;
88+
} else {
89+
$success = CommentLib::create(
90+
$p_type, $p_id, $model->user_session->user_id, $content
91+
);
92+
}
93+
8194
}
8295

8396
$model->response = [

src/libraries/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function isStaff() {
307307
self::OPTION_ACL_DOCUMENT_CREATE |
308308
self::OPTION_ACL_DOCUMENT_MODIFY |
309309
self::OPTION_ACL_DOCUMENT_DELETE |
310-
self::OPTION_ACL_COMMENT_VIEW |
310+
self::OPTION_ACL_COMMENT_CREATE |
311311
self::OPTION_ACL_COMMENT_MODIFY |
312312
self::OPTION_ACL_COMMENT_DELETE |
313313
self::OPTION_ACL_EVENT_LOG_VIEW |

src/models/Comment/Create.php

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

77
class Create extends Model {
88

9+
public $acl_allowed;
910
public $origin;
1011
public $response;
12+
public $user;
1113
public $user_session;
1214

1315
public function __construct() {
1416
parent::__construct();
17+
$this->acl_allowed = null;
1518
$this->origin = null;
1619
$this->response = null;
20+
$this->user = null;
1721
$this->user_session = null;
1822
}
1923

0 commit comments

Comments
 (0)