Skip to content

Version 1.4 #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f565ce1
Add endpoints to get user permissions
atelomycterus Mar 17, 2021
c2edfbf
Add endpoints to get user permissions
atelomycterus Mar 17, 2021
c8afa8d
Merge pull request #68 from topcoder-platform/issues-468
jmgasper Mar 17, 2021
76c35a7
Issues-476:Show Copilot/Reviewer roles and hide other challenge roles
atelomycterus Mar 24, 2021
fad4ce9
Issues-395: treaded view is used by default, removed tree view option
atelomycterus Mar 25, 2021
3a8e472
Merge pull request #69 from topcoder-platform/issue-395
jmgasper Mar 25, 2021
ac2acb1
Issues-490: Move reply to comment block
atelomycterus Mar 25, 2021
fd0cffc
Merge pull request #70 from topcoder-platform/issues-490
jmgasper Mar 25, 2021
3c96c92
Issues-476: fixed challenge roles after updating comments
atelomycterus Mar 26, 2021
1811ed9
Merge pull request #71 from topcoder-platform/issues-490
jmgasper Mar 26, 2021
50f9061
Issues-476: Fixed challenge roles for user photo links
atelomycterus Mar 26, 2021
c1d2628
Issues-476: Fixed challenge roles for user photo links
atelomycterus Mar 26, 2021
643ca40
Merge pull request #72 from topcoder-platform/issues-490
jmgasper Mar 26, 2021
e675f37
Issues-490: Add reply link in comment/discission options
atelomycterus Mar 26, 2021
f6ba15f
Issues-490: Render reply link if user has permissison
atelomycterus Mar 26, 2021
70cb0e3
Merge pull request #73 from topcoder-platform/issues-490
jmgasper Mar 27, 2021
a8dbd79
Issues-476: Fixed challenge roles for new comments
atelomycterus Mar 27, 2021
4838416
Merge pull request #74 from topcoder-platform/issues-476-1
jmgasper Mar 27, 2021
5ebf974
Issues-488: Fixed threaded/flat mode
atelomycterus Mar 27, 2021
9238058
Merge pull request #75 from topcoder-platform/issues-488
jmgasper Mar 28, 2021
f3aac21
Issues-498: fixed threaded/flat mode for anonymous
atelomycterus Mar 28, 2021
f98cce3
Issues-488: formating nested comments
atelomycterus Mar 28, 2021
92c8df2
Issues-491: set the scroll animation settings as in quotes plugin
atelomycterus Mar 28, 2021
379dc1f
Merge pull request #76 from topcoder-platform/issues-498
jmgasper Mar 28, 2021
afa0583
Issues-508:Updated Profile Settings link
atelomycterus Mar 29, 2021
dd92114
Merge pull request #77 from topcoder-platform/issues-508
jmgasper Mar 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions DebugPlugin/controllers/api/PermissionApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

use Garden\Web\Exception\ClientException;
use Garden\Schema\Schema;
use Vanilla\Utility\InstanceValidatorSchema;
use Garden\Web\Data;
use Garden\Web\Exception\NotFoundException;
use Garden\Web\Exception\ServerException;
use Vanilla\ApiUtils;

/**
* Permission API Controller for the `/permission` resource.
*/
class PermissionApiController extends AbstractApiController {

/**
* Get default user permissions
* @param $userID
* @return Data
* @throws \Garden\Web\Exception\HttpException
* @throws \Vanilla\Exception\PermissionException
*/
public function index($userID) {
$this->permission('Garden.Settings.Manage');
if (!Gdn::userModel()->getID($userID)) {
throw notFoundException('User');
}
$userPermissions = Gdn::userModel()->getPermissions($userID);
$data = [
'userPermissions' => $userPermissions,
];
return $data;
}

/**
* Get user permissions for a category
* @param $userID
* @param $categoryID
* @return Data
* @throws \Garden\Web\Exception\HttpException
* @throws \Vanilla\Exception\PermissionException
*/
public function get($userID, $categoryID) {
$this->permission('Garden.Settings.Manage');

if (!Gdn::userModel()->getID($userID)) {
throw notFoundException('User');
}

$category = CategoryModel::categories($categoryID);
if (!$category) {
throw notFoundException('Category');
}
$groupID = val('GroupID', $category, null);
$data = [
'GroupID' => $groupID,
'PermsGroupView' => $groupID? GroupModel::getGroupRoleFor($userID, $groupID) : null,
'PermsDiscussionsView' => CategoryModel::checkPermission($category, 'Vanilla.Discussions.View', true, $userID),
'PermsDiscussionsAdd' => CategoryModel::checkPermission($category, 'Vanilla.Discussions.Add', true, $userID),
'PermsDiscussionsEdit' => CategoryModel::checkPermission($category, 'Vanilla.Discussions.Edit', true, $userID),
'PermsCommentsAdd' => CategoryModel::checkPermission($category, 'Vanilla.Comments.Add', true, $userID),
'PermsDiscussionsUploads' => CategoryModel::checkPermission($category, 'Vanilla.Discussions.Uploads', true, $userID),
'PermsCommentsUploads' => CategoryModel::checkPermission($category, 'Vanilla.Comments.Uploads', true, $userID)
];
return $data;
}
}
52 changes: 52 additions & 0 deletions DebugPlugin/openapi/permission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
openapi: 3.0.2
info: Vanilla Permission API
paths:
/permission/{userID}/{categoryID}:
get:
parameters:
- description: UserID to check.
in: path
name: userID
schema:
type: integer
- description: CategoryID to check.
in: path
name: categoryID
schema:
type: integer
responses:
'200':
content:
'application/json':
schema:
items:
$ref: '#/components/schemas/Records'
type: array
description: Success
tags:
- Data
summary: List records.
/permission/{userID}:
get:
parameters:
- description: UserID to check.
in: path
name: userID
schema:
type: integer
responses:
'200':
content:
'application/json':
schema:
items:
$ref: '#/components/schemas/Records'
type: array
description: Success
tags:
- Data
summary: List records.
components:
schemas:
Records:
type: object
144 changes: 101 additions & 43 deletions ReplyTo/class.replyto.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ReplyToPlugin extends Gdn_Plugin {

const QUERY_PARAMETER_VIEW='view';
const VIEW_FLAT = 'flat';
const VIEW_TREE = 'tree';
const VIEW_THREADED = 'threaded';

private $replyToModel;
Expand Down Expand Up @@ -67,12 +66,22 @@ public function postController_render_before($sender) {
$this->prepareController($sender);
}

/**
* Add View Mode before rendering comments
* @param $sender
* @param $args
*/
public function base_beforeCommentsRender_handler($sender, $args) {
$viewMode = self::getViewMode();
$sender->setData('ViewMode', $viewMode);
}

/**
* Render View options for a discussion
* @param $sender
* @param $args
*/
public function base_Replies_handler($sender, $args){
public function base_InlineDiscussionOptionsLeft_handler($sender, $args){
$discussion = $sender->data('Discussion');
if (!$discussion) {
return;
Expand All @@ -83,13 +92,13 @@ public function base_Replies_handler($sender, $args){
}

$discussionUrl = discussionUrl($discussion, '', '/');
$viewMode = getIncomingValue(self::QUERY_PARAMETER_VIEW, self::VIEW_FLAT);
$viewMode = self::getViewMode();

echo '<div class="ReplyViewOptions"><span class="MLabel">View:&nbsp</span>';
echo anchor('Flat', $discussionUrl.'?'.self::QUERY_PARAMETER_VIEW.'='.self::VIEW_FLAT, $viewMode == self::VIEW_FLAT?'Active':'').'&nbsp;&nbsp;|&nbsp;&nbsp;';
echo anchor('Threaded', $discussionUrl.'?'.self::QUERY_PARAMETER_VIEW.'='.self::VIEW_THREADED, $viewMode == self::VIEW_THREADED?'Active':'').'&nbsp;&nbsp;|&nbsp;&nbsp;';
echo anchor('Tree', $discussionUrl.'?'.self::QUERY_PARAMETER_VIEW.'='.self::VIEW_TREE, $viewMode == self::VIEW_TREE?'Active':'');
echo '</div>';
echo '<span class="ReplyViewOptions">';
echo '<span class="MLabel">View:&nbsp</span>';
echo anchor('Threaded', $discussionUrl.'?'.self::QUERY_PARAMETER_VIEW.'='.self::VIEW_THREADED, $viewMode == self::VIEW_THREADED?'ReplyViewOptionLink Active':'ReplyViewOptionLink').'&nbsp;&nbsp;|&nbsp;&nbsp;';
echo anchor('Flat', $discussionUrl.'?'.self::QUERY_PARAMETER_VIEW.'='.self::VIEW_FLAT, $viewMode == self::VIEW_FLAT?'ReplyViewOptionLink Active':'ReplyViewOptionLink');
echo '</span>';
}

/**
Expand All @@ -98,9 +107,9 @@ public function base_Replies_handler($sender, $args){
* @param $sender
*/
public function commentModel_afterConstruct_handler(&$sender) {
self::log('commentModel_afterConstruct_handler', ['path'=> Gdn::request()->pathAndQuery()]);
$viewMode = getIncomingValue(self::QUERY_PARAMETER_VIEW, self::VIEW_FLAT);
if($viewMode == self::VIEW_TREE || $viewMode == self::VIEW_THREADED) {
$viewMode = self::getViewMode();

if($viewMode == self::VIEW_THREADED) {
$sender->orderBy(array('TreeLeft asc', 'DateInserted asc'));
}
}
Expand Down Expand Up @@ -135,13 +144,8 @@ public function commentModel_deleteComment_handler(&$Sender) {
}

public function discussionController_BeforeCalculatingOffsetLimit_handler($sender, $args) {
if (!Gdn::session()->isValid()) {
return;
}
$viewMode = getIncomingValue(self::QUERY_PARAMETER_VIEW);
if(!$viewMode) {
return;
}
$viewMode = self::getViewMode();
// $offsetProvided = $args['OffsetProvided'];
$discussion = $args['Discussion'];
$offset = & $args['Offset'];
$limit = & $args['Limit'];
Expand All @@ -152,7 +156,6 @@ public function discussionController_BeforeCalculatingOffsetLimit_handler($sende
}

if($viewMode === self::VIEW_FLAT) {
$offset = 0;
$enableAutoOffset = false;
} else {
// Show all comment on one offset for Tree/Threaded View
Expand All @@ -176,7 +179,7 @@ public function discussionController_beforeDiscussionRender_handler($sender, $ar
return;
}

$viewMode = getIncomingValue(self::QUERY_PARAMETER_VIEW, self::VIEW_FLAT);
$viewMode = self::getViewMode();
if($viewMode == self::VIEW_FLAT) {
return;
}
Expand All @@ -196,32 +199,30 @@ public function base_commentOptions_handler($sender, $args) {
return;
}
$discussion = $sender->data('Discussion');
$isClosed = ((int)$discussion->Closed) == 1;
if ($isClosed) {
return;
}

//Check permission
if (isset($discussion->PermissionCategoryID)) {
$CategoryID = val('PermissionCategoryID', $discussion);
} else {
$CategoryID = $discussion->CategoryID;
}
$CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion);
$userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close');
$userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add');

// Can the user comment on this category, and is the discussion open for comments?
if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
$canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment);
if (!$canAddComment) {
return;
}
// Can the user comment on this category, and is the discussion open for comments?
// if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
// return;
// }

$options = &$args['CommentOptions'];
$comment = &$args['Comment'];
$comment = $args['Comment'];
$options['ReplyToComment'] = [
'Label' => t('Reply'),
'Url' => '/?ParentCommentID='.$comment->CommentID,
'Class' => 'ReplyComment'
];

$viewMode = getIncomingValue(self::QUERY_PARAMETER_VIEW, self::VIEW_FLAT);
$viewMode = self::getViewMode();
foreach ($options as $key => $value) {
$currentUrl = $options[$key]['Url'];
if (strpos($currentUrl, '?') !== false ) {
Expand All @@ -236,26 +237,70 @@ public function base_commentOptions_handler($sender, $args) {
}
}

/**
* Add 'Reply' option to discussion.
*
* @param Gdn_Controller $sender
* @param array $args
*/
public function base_inlineDiscussionOptions_handler($sender, $args) {
$discussion = $args['Discussion'];
if (!$discussion) {
return;
}

if (!Gdn::session()->UserID) {
return;
}

//Check permission
$CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion);
$userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close');
$userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add');

// See the 'writeCommentForm' method vanilla/applications/vanilla/views/discussion/helper_functions.php
$canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment);
if (!$canAddComment) {
return;
}

// DropdownModule options
$options = & $args['DiscussionOptions'];
$options->addLink('Reply', url("/", true), 'reply', 'ReplyComment');
}

/**
* Insert the indentation classes into the comment.
* All rendering options should be set before displaying comments
* @param $sender
* @param $args
*/
public function base_beforeCommentDisplay_handler($sender, $args) {
ReplyToPlugin::log('base_beforeCommentDisplay_handler', []);

$viewMode = getIncomingValue(self::QUERY_PARAMETER_VIEW, self::VIEW_FLAT);
if($viewMode == self::VIEW_FLAT) {
return;
}
if($sender->deliveryType() != DELIVERY_TYPE_ALL) {
ReplyToPlugin::log('base_beforeCommentDisplay_handler', ['']);
$this->buildCommentReplyToCssClasses($sender);
// Ajax request to post new comments or update comments
if(isset($_SERVER['HTTP_REFERER'])) {
$previous = $_SERVER['HTTP_REFERER'];
$query = parse_url($previous, PHP_URL_QUERY);
parse_str($query, $params);
$viewMode = $params['view'];
if(!$viewMode) {
$viewMode = self::isPagingUrl($previous) ? self::VIEW_FLAT : self::VIEW_THREADED;
}
$sender->setData('ViewMode', $viewMode);
if($viewMode == self::VIEW_THREADED) {
$this->buildCommentReplyToCssClasses($sender);
}
}
} else {
$viewMode = self::getViewMode();
if($viewMode == self::VIEW_THREADED) {
$this->buildCommentReplyToCssClasses($sender);
}
}
$comment = &$args['Comment'];
$cssClass = &$args['CssClass'];
$displayBody = &$args['DisplayBody'];
$displayBody = $viewMode == self::VIEW_FLAT || $viewMode == self::VIEW_THREADED;
// $displayBody = &$args['DisplayBody'];
// $displayBody = $viewMode == self::VIEW_FLAT || $viewMode == self::VIEW_THREADED;
$cssClass .= (!empty($comment->ReplyToClass)? ' ' . $comment->ReplyToClass : '');
}

Expand Down Expand Up @@ -330,6 +375,19 @@ private function buildCommentReplyToCssClasses(&$sender){
}
}

private static function isPagingUrl($url) {
return preg_match('/\/p\d+$/', $url);
}

private static function getViewMode(){
$viewMode = getIncomingValue(self::QUERY_PARAMETER_VIEW);
if(!$viewMode) {
$viewMode = self::isPagingUrl(Gdn::request()->path())? self::VIEW_FLAT: self::VIEW_THREADED;
}

return $viewMode;
}

public static function log($message, $data) {
if (c('Debug')) {
Logger::event(
Expand Down
Loading