9
9
use \BNETDocs \Libraries \Exceptions \UnspecifiedViewException ;
10
10
use \BNETDocs \Libraries \Logger ;
11
11
use \BNETDocs \Libraries \Router ;
12
+ use \BNETDocs \Libraries \User ;
12
13
use \BNETDocs \Libraries \UserSession ;
13
14
use \BNETDocs \Models \Comment \Create as CreateModel ;
14
15
use \BNETDocs \Views \Comment \CreateJSON as CreateJSONView ;
@@ -26,6 +27,12 @@ public function run(Router &$router) {
26
27
}
27
28
$ model = new CreateModel ();
28
29
$ 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
+ );
29
36
30
37
$ code = 500 ;
31
38
if (!$ model ->user_session ) {
@@ -57,27 +64,33 @@ protected function createComment(Router &$router, CreateModel &$model) {
57
64
$ p_type = (isset ($ query ["parent_type " ]) ? $ query ["parent_type " ] : null );
58
65
$ content = (isset ($ query ["content " ]) ? $ query ["content " ] : null );
59
66
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 ) {
76
68
$ success = false ;
77
69
} 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
+
81
94
}
82
95
83
96
$ model ->response = [
0 commit comments