99use \BNETDocs \Libraries \Exceptions \UnspecifiedViewException ;
1010use \BNETDocs \Libraries \Logger ;
1111use \BNETDocs \Libraries \Router ;
12+ use \BNETDocs \Libraries \User ;
1213use \BNETDocs \Libraries \UserSession ;
1314use \BNETDocs \Models \Comment \Create as CreateModel ;
1415use \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 = [
0 commit comments