Skip to content

Commit f6ba15f

Browse files
committed
Issues-490: Render reply link if user has permissison
1 parent e675f37 commit f6ba15f

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

ReplyTo/class.replyto.plugin.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,20 @@ public function base_commentOptions_handler($sender, $args) {
192192
return;
193193
}
194194
$discussion = $sender->data('Discussion');
195-
$isClosed = ((int)$discussion->Closed) == 1;
196-
if ($isClosed) {
197-
return;
198-
}
199195

200196
//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');
206200

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) {
209203
return;
210204
}
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+
// }
211209

212210
$options = &$args['CommentOptions'];
213211
$comment = $args['Comment'];
@@ -244,26 +242,21 @@ public function base_inlineDiscussionOptions_handler($sender, $args) {
244242
return;
245243
}
246244

247-
$isClosed = ((int)$discussion->Closed) == 1;
248-
if ($isClosed) {
249-
return;
250-
}
251-
252245
if (!Gdn::session()->UserID) {
253246
return;
254247
}
255248

256249
//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');
262253

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) {
265257
return;
266258
}
259+
267260
// DropdownModule options
268261
$options = & $args['DiscussionOptions'];
269262
$options->addLink('Reply', url("/", true), 'reply', 'ReplyComment');

0 commit comments

Comments
 (0)