@@ -192,22 +192,20 @@ public function base_commentOptions_handler($sender, $args) {
192
192
return ;
193
193
}
194
194
$ discussion = $ sender ->data ('Discussion ' );
195
- $ isClosed = ((int )$ discussion ->Closed ) == 1 ;
196
- if ($ isClosed ) {
197
- return ;
198
- }
199
195
200
196
//Check permission
201
- if (isset ($ discussion ->PermissionCategoryID )) {
202
- $ CategoryID = val ('PermissionCategoryID ' , $ discussion );
203
- } else {
204
- $ CategoryID = $ discussion ->CategoryID ;
205
- }
197
+ $ CategoryID = val ('PermissionCategoryID ' , $ discussion )? val ('PermissionCategoryID ' , $ discussion ):val ('CategoryID ' , $ discussion );
198
+ $ userCanClose = CategoryModel::checkPermission ($ CategoryID , 'Vanilla.Discussions.Close ' );
199
+ $ userCanComment = CategoryModel::checkPermission ($ CategoryID , 'Vanilla.Comments.Add ' );
206
200
207
- // Can the user comment on this category, and is the discussion open for comments?
208
- if (!Gdn:: Session ()-> CheckPermission ( ' Vanilla.Comments.Add ' , TRUE , ' Category ' , $ CategoryID ) ) {
201
+ $ canAddComment = ( $ discussion -> Closed == ' 1 ' && $ userCanClose ) || ( $ discussion-> Closed == ' 0 ' && $ userCanComment );
202
+ if (!$ canAddComment ) {
209
203
return ;
210
204
}
205
+ // Can the user comment on this category, and is the discussion open for comments?
206
+ // if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
207
+ // return;
208
+ // }
211
209
212
210
$ options = &$ args ['CommentOptions ' ];
213
211
$ comment = $ args ['Comment ' ];
@@ -244,26 +242,21 @@ public function base_inlineDiscussionOptions_handler($sender, $args) {
244
242
return ;
245
243
}
246
244
247
- $ isClosed = ((int )$ discussion ->Closed ) == 1 ;
248
- if ($ isClosed ) {
249
- return ;
250
- }
251
-
252
245
if (!Gdn::session ()->UserID ) {
253
246
return ;
254
247
}
255
248
256
249
//Check permission
257
- if (isset ($ discussion ->PermissionCategoryID )) {
258
- $ CategoryID = val ('PermissionCategoryID ' , $ discussion );
259
- } else {
260
- $ CategoryID = $ discussion ->CategoryID ;
261
- }
250
+ $ CategoryID = val ('PermissionCategoryID ' , $ discussion )? val ('PermissionCategoryID ' , $ discussion ):val ('CategoryID ' , $ discussion );
251
+ $ userCanClose = CategoryModel::checkPermission ($ CategoryID , 'Vanilla.Discussions.Close ' );
252
+ $ userCanComment = CategoryModel::checkPermission ($ CategoryID , 'Vanilla.Comments.Add ' );
262
253
263
- // Can the user comment on this category, and is the discussion open for comments?
264
- if (!Gdn::Session ()->CheckPermission ('Vanilla.Comments.Add ' , TRUE , 'Category ' , $ CategoryID )) {
254
+ // See the 'writeCommentForm' method vanilla/applications/vanilla/views/discussion/helper_functions.php
255
+ $ canAddComment = ($ discussion ->Closed == '1 ' && $ userCanClose ) || ($ discussion ->Closed == '0 ' && $ userCanComment );
256
+ if (!$ canAddComment ) {
265
257
return ;
266
258
}
259
+
267
260
// DropdownModule options
268
261
$ options = & $ args ['DiscussionOptions ' ];
269
262
$ options ->addLink ('Reply ' , url ("/ " , true ), 'reply ' , 'ReplyComment ' );
0 commit comments