Skip to content

Commit 1ad9819

Browse files
committed
Merge branch 'develop' of github.com:topcoder-platform/forums into develop
2 parents f93cee8 + d2b2a41 commit 1ad9819

26 files changed

+6412
-114
lines changed

config/vanilla/bootstrap.late.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,16 @@
5555
$CategoryModel->recalculateTree();
5656
unset($CategoryModel);
5757
}
58+
59+
60+
// Define some permissions for the Vanilla categories.
61+
// FIX: https://github.com/topcoder-platform/forums/issues/373
62+
$PermissionModel->define(
63+
[
64+
'Vanilla.Discussions.Uploads' => 0,
65+
'Vanilla.Comments.Uploads' => 0],
66+
'tinyint',
67+
'Category',
68+
'PermissionCategoryID'
69+
);
5870
}

config/vanilla/config.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
0 => 'staticcontent/container',
135135
1 => 'Internal',
136136
);
137-
$Configuration['Routes']['DefaultController'] = 'discussions';
137+
$Configuration['Routes']['DefaultController'] = 'categories';
138138
$Configuration['Routes']['XmZpbGVzdGFjaygvLiopPyQ='] = array (
139139
0 => 'vanilla/filestack$1',
140140
1 => 'Internal',
@@ -144,7 +144,10 @@
144144
$Configuration['Vanilla']['SSO']['Debug'] = true;
145145
$Configuration['Vanilla']['Activity']['ShowDiscussionBody'] = true;
146146
$Configuration['Vanilla']['Activity']['ShowCommentBody'] = true;
147-
$Configuration['Vanilla']['EnableCategoryFollowing'] = true;
147+
// Show 'My Discussions' in the left nav
148+
$Configuration['Vanilla']['Discussions']['ShowMineTab'] = false;
149+
// Allow users to follow categories. Users will be able to see a feed of discussions of only their followed categories.
150+
$Configuration['Vanilla']['EnableCategoryFollowing'] = false;
148151
$Configuration['Vanilla']['Version'] = '3.0';
149152

150153

vanilla/applications/dashboard/controllers/api/MediaApiController.php

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,6 @@ public function patch_attachment(int $id, array $body): array {
364364
* @return array
365365
*/
366366
public function post(array $body) {
367-
if(!Gdn::session()->checkPermission('Garden.Uploads.Add')) {
368-
throw new ClientException('You don\'t have permission to upload files', 403);
369-
}
370-
371-
//$this->permission('Garden.Uploads.Add');
372-
373367
$allowedExtensions = $this->config->get('Garden.Upload.AllowedFileExtensions', []);
374368
$uploadSchema = new UploadedFileSchema([
375369
UploadedFileSchema::OPTION_ALLOWED_EXTENSIONS => $allowedExtensions,
@@ -380,10 +374,69 @@ public function post(array $body) {
380374

381375
$in = $this->schema([
382376
'file' => $uploadSchema,
377+
'categoryID:i?' => "CategoryID",
378+
'discussionID:i?' => "DiscussionID",
379+
'commentID:i?' => "CommentID",
380+
'actionType:s?' => "ActionType"
383381
], 'in')->setDescription('Add a media item.');
384-
$out = $this->schema($this->fullSchema(), 'out');
385-
386382
$body = $in->validate($body);
383+
$categoryID = $body['categoryID'];
384+
$discussionID = $body['discussionID'];
385+
$commentID = $body['commentID'];
386+
$actionType = $body['actionType'];
387+
388+
if(!$categoryID && !$discussionID && !Gdn::session()->checkPermission('Garden.Uploads.Add')) {
389+
throw new ClientException("You don't have permission to upload files", 403);
390+
}
391+
392+
if(!Gdn::session()->checkPermission('Garden.Uploads.Add')) {
393+
switch ($actionType) {
394+
case 'NewDiscussion':
395+
if(!$categoryID) {
396+
throw new ClientException("You don't have permission to upload files", 403);
397+
}
398+
$permissionCategory = CategoryModel::permissionCategory($categoryID);
399+
$discussionsUploads = CategoryModel::checkPermission($permissionCategory, 'Vanilla.Discussions.Uploads');
400+
if(!$discussionsUploads) {
401+
throw new ClientException("You don't have permission to upload files", 403);
402+
}
403+
break;
404+
case 'EditDiscussion':
405+
$discussionModel = new DiscussionModel();
406+
$discussion = $discussionModel->getID($discussionID);
407+
if (!$discussion) {
408+
throw new NotFoundException('Discussion');
409+
}
410+
$categoryID = val('CategoryID', $discussion, false);
411+
$permissionCategory = CategoryModel::permissionCategory($categoryID);
412+
$discussionsUploads = CategoryModel::checkPermission($permissionCategory, 'Vanilla.Discussions.Uploads');
413+
if(!$discussionsUploads) {
414+
throw new ClientException("You don't have permission to upload files", 403);
415+
}
416+
break;
417+
case 'NewComment':
418+
case 'EditComment':
419+
$discussionModel = new DiscussionModel();
420+
$discussion = $discussionModel->getID($discussionID);
421+
if (!$discussion) {
422+
throw new NotFoundException('Discussion');
423+
}
424+
425+
$categoryID = val('CategoryID', $discussion, false);
426+
$permissionCategory = CategoryModel::permissionCategory($categoryID);
427+
$commentsUploads = CategoryModel::checkPermission($permissionCategory, 'Vanilla.Comments.Uploads');
428+
// No permissions
429+
if(!$commentsUploads) {
430+
throw new ClientException("You don't have permission to upload files", 403);
431+
}
432+
break;
433+
default:
434+
throw new ClientException("You don't have permission to upload files", 403);
435+
}
436+
437+
}
438+
439+
$out = $this->schema($this->fullSchema(), 'out');
387440

388441
$imageExtensions = array_keys(ImageResizer::getExtType());
389442
/** @var UploadedFile $file */

vanilla/applications/dashboard/controllers/class.searchcontroller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function initialize() {
5858
$this->addCssFile('style.css');
5959
$this->addCssFile('vanillicon.css', 'static');
6060
$this->addModule('GuestModule');
61-
$this->addModule('NewDiscussionModule');
61+
//$this->addModule('NewDiscussionModule');
6262
$this->addModule('DiscussionFilterModule');
63-
$this->addModule('CategoriesModule');
63+
//$this->addModule('CategoriesModule');
6464
$this->addModule('BookmarkedModule');
6565
parent::initialize();
6666
$this->setData('Breadcrumbs', [['Name' => t('Search'), 'Url' => '/search']]);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Guest module.
4+
*
5+
* @copyright 2009-2019 Vanilla Forums Inc.
6+
* @license GPL-2.0-only
7+
* @package Dashboard
8+
* @since 2.0
9+
*/
10+
11+
/**
12+
* Renders the "You should register or sign in" panel box.
13+
*/
14+
class GuestModule extends Gdn_Module {
15+
16+
/** @var string */
17+
public $MessageCode = 'GuestModule.Message';
18+
19+
/** @var string */
20+
public $MessageDefault = "Looks like you are new or aren't currently signed in.";
21+
22+
/**
23+
*
24+
*
25+
* @param string $sender
26+
* @param bool $applicationFolder
27+
*/
28+
public function __construct($sender = '', $applicationFolder = false) {
29+
if (!$applicationFolder) {
30+
$applicationFolder = 'Dashboard';
31+
}
32+
parent::__construct($sender, $applicationFolder);
33+
34+
$this->Visible = c('Garden.Modules.ShowGuestModule');
35+
}
36+
37+
/**
38+
*
39+
*
40+
* @return string
41+
*/
42+
public function assetTarget() {
43+
return 'Panel';
44+
}
45+
46+
/**
47+
* Render.
48+
*
49+
* @return string
50+
*/
51+
public function toString() {
52+
if (!Gdn::session()->isValid()) {
53+
return parent::toString();
54+
}
55+
56+
return '';
57+
}
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php if (!defined('APPLICATION')) exit(); ?>
2+
<div class="Box GuestBox">
3+
<h4><?php echo t('Welcome to Topcoder!'); ?></h4>
4+
5+
<p><?php echo t($this->MessageCode, $this->MessageDefault); ?></p>
6+
7+
<p><?php $this->fireEvent('BeforeSignInButton'); ?></p>
8+
9+
<?php
10+
$signInUrl = signInUrl($this->_Sender->SelfUrl);
11+
12+
if ($signInUrl) {
13+
echo '<div class="P">';
14+
15+
echo anchor(t('Login'), signInUrl($this->_Sender->SelfUrl), 'Button Primary SignIn BigButton'.(signInPopup() ? ' SignInPopup' : ''), ['rel' => 'nofollow']);
16+
// $Url = registerUrl($this->_Sender->SelfUrl);
17+
// if (!empty($Url)) {
18+
// echo ' '.anchor(t('Register', t('Apply for Membership', 'Register')), $Url, 'Button ApplyButton', ['rel' => 'nofollow']);
19+
// }
20+
21+
echo '</div>';
22+
}
23+
?>
24+
<?php $this->fireEvent('AfterSignInButton'); ?>
25+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php if (!defined('APPLICATION')) exit(); ?>
2+
<h1 class="H HomepageTitle">Search</h1>
3+
<div class="SearchForm">
4+
<?php
5+
$Form = $this->Form;
6+
echo $Form->open(['action' => url('/search'), 'method' => 'get']),
7+
'<div class="SiteSearch InputAndButton">',
8+
$Form->textBox('Search', ['aria-label' => t('Enter your search term.'), 'title' => t('Enter your search term.') ]),
9+
$Form->button('Search', ['aria-label' => t('Search'), 'Name' => '']),
10+
'</div>',
11+
$Form->errors(),
12+
$Form->close();
13+
?>
14+
</div>
15+
<?php
16+
$ViewLocation = $this->fetchViewLocation('results');
17+
include($ViewLocation);

vanilla/applications/vanilla/controllers/class.categoriescontroller.php

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ class CategoriesController extends VanillaController {
2929
public $Category;
3030

3131
/** @var bool Value indicating if the category-following filter should be displayed when rendering a view */
32-
public $enableFollowingFilter = true;//false;
32+
public $enableFollowingFilter = false;
3333

3434
const SORT_LAST_POST = 'new';
3535
const SORT_OLDEST_POST = 'old';
3636

37+
const ROOT_CATEGORY = ['Name' => 'Roundtables', 'Url'=>'/'];
3738
/**
3839
* @var \Closure $categoriesCompatibilityCallback A backwards-compatible callback to get `$this->data('Categories')`.
3940
*/
@@ -264,15 +265,23 @@ private function getOptions($category) {
264265
public function index($categoryIdentifier = '', $page = '0') {
265266
// Figure out which category layout to choose (Defined on "Homepage" settings page).
266267
$layout = c('Vanilla.Categories.Layout');
267-
$followed = Gdn::request()->get('followed', null);
268-
$saveFollowing = $followed !== null && Gdn::request()->get('save') && Gdn::session()->validateTransientKey(Gdn::request()->get('TransientKey', ''));
269-
if($saveFollowing) {
270-
$followed = Gdn::request()->get('followed');
271-
Gdn::session()->setPreference('FollowedCategories', $followed);
268+
269+
if ($this->CategoryModel->followingEnabled()) {
270+
$followed = Gdn::request()->get('followed', null);
271+
$saveFollowing = $followed !== null && Gdn::request()->get('save') && Gdn::session()->validateTransientKey(Gdn::request()->get('TransientKey', ''));
272+
if ($saveFollowing) {
273+
$followed = Gdn::request()->get('followed');
274+
Gdn::session()->setPreference('FollowedCategories', $followed);
275+
}
276+
277+
$followed = Gdn::session()->getPreference('FollowedCategories', false);
278+
$this->enableFollowingFilter = true;
279+
} else {
280+
$this->enableFollowingFilter = $followed = false;
272281
}
273282

274-
$followed = Gdn::session()->getPreference('FollowedCategories', false);
275283
$this->setData('Followed', $followed);
284+
$this->setData('EnableFollowingFilter', $this->enableFollowingFilter);
276285

277286
$sort = Gdn::request()->get('sort', null);
278287
$saveSorting = $sort !== null && Gdn::request()->get('save') && Gdn::session()->validateTransientKey(Gdn::request()->get('TransientKey', ''));
@@ -283,13 +292,11 @@ public function index($categoryIdentifier = '', $page = '0') {
283292
$this->setData('CategorySort', $sort);
284293

285294
if ($categoryIdentifier == '') {
286-
$this->enableFollowingFilter = true;
287295
$this->fireEvent('EnableFollowingFilter', [
288296
'CategoryIdentifier' => $categoryIdentifier,
289297
'EnableFollowingFilter' => &$this->enableFollowingFilter
290298
]);
291-
$this->setData('EnableFollowingFilter', $this->enableFollowingFilter);
292-
switch ($layout) {
299+
switch ($layout) {
293300
case 'mixed':
294301
$this->View = 'discussions';
295302
$this->discussions();
@@ -316,17 +323,26 @@ public function index($categoryIdentifier = '', $page = '0') {
316323

317324
Gdn_Theme::section($category->CssClass);
318325

319-
// The view filter is shown always if category type != 'discussions'
320-
$this->enableFollowingFilter = strtolower( val('DisplayAs', $category, '')) != 'discussions';
321-
$this->fireEvent('EnableFollowingFilter', [
322-
'CategoryIdentifier' => $categoryIdentifier,
323-
'EnableFollowingFilter' => &$this->enableFollowingFilter
324-
]);
326+
if($this->CategoryModel->followingEnabled()) {
327+
// The view filter is shown always if category type != 'discussions'
328+
$this->enableFollowingFilter = strtolower(val('DisplayAs', $category, '')) != 'discussions';
329+
$this->fireEvent('EnableFollowingFilter', [
330+
'CategoryIdentifier' => $categoryIdentifier,
331+
'EnableFollowingFilter' => &$this->enableFollowingFilter
332+
]);
333+
}
325334

326335
// Load the breadcrumbs.
327-
$this->setData('Breadcrumbs', CategoryModel::getAncestors(val('CategoryID', $category)));
336+
337+
$ancestors = CategoryModel::getAncestors(val('CategoryID', $category));
338+
array_unshift ( $ancestors , self::ROOT_CATEGORY);
339+
$this->setData('Breadcrumbs', $ancestors);
340+
328341

329342
$this->setData('Category', $category, true);
343+
// Set CategoryID
344+
$categoryID = val('CategoryID', $category);
345+
$this->setData('CategoryID', $categoryID, true);
330346
$this->setData('EnableFollowingFilter', $this->enableFollowingFilter);
331347

332348
$this->title(htmlspecialchars(val('Name', $category, '')));
@@ -392,14 +408,10 @@ public function index($categoryIdentifier = '', $page = '0') {
392408
$this->Head->addRss(categoryUrl($category) . '/feed.rss', $this->Head->title());
393409
}
394410

395-
// Set CategoryID
396-
$categoryID = val('CategoryID', $category);
397-
$this->setData('CategoryID', $categoryID, true);
398-
399411
// Add modules
400412
$this->addModule('NewDiscussionModule');
401413
$this->addModule('DiscussionFilterModule');
402-
$this->addModule('CategoriesModule');
414+
// $this->addModule('CategoriesModule');
403415
$this->addModule('BookmarkedModule');
404416
$this->addModule('TagModule');
405417

@@ -528,7 +540,7 @@ public function all($Category = '', $displayAs = '') {
528540
if ($Title) {
529541
$this->title($Title, '');
530542
} else {
531-
$this->title(t('All Categories'));
543+
$this->title(t('Roundtables'));
532544
}
533545
}
534546
Gdn_Theme::section('CategoryList');
@@ -537,7 +549,10 @@ public function all($Category = '', $displayAs = '') {
537549
$this->description(c('Garden.Description', null));
538550
}
539551

540-
$this->setData('Breadcrumbs', CategoryModel::getAncestors(val('CategoryID', $this->data('Category'))));
552+
$ancestors = CategoryModel::getAncestors(val('CategoryID', $this->data('Category')));
553+
array_unshift ( $ancestors , self::ROOT_CATEGORY);
554+
$this->setData('Breadcrumbs', $ancestors);
555+
541556

542557
// Set the category follow toggle before we load category data so that it affects the category query appropriately.
543558
$CategoryFollowToggleModule = new CategoryFollowToggleModule($this);
@@ -623,9 +638,12 @@ public function all($Category = '', $displayAs = '') {
623638
$this->setData('CategoryTree', $categoryTree);
624639

625640
// Add modules
626-
$this->addModule('NewDiscussionModule');
641+
if($Category) {
642+
$this->addModule('NewDiscussionModule');
643+
}
627644
$this->addModule('DiscussionFilterModule');
628645
$this->addModule('BookmarkedModule');
646+
// $this->addModule('CategoriesModule');
629647
$this->addModule($CategoryFollowToggleModule);
630648
$this->addModule('TagModule');
631649

@@ -661,7 +679,7 @@ public function discussions($Category = '') {
661679
if ($Title) {
662680
$this->title($Title, '');
663681
} else {
664-
$this->title(t('All Categories'));
682+
$this->title(t('Roundtables'));
665683
}
666684
}
667685

@@ -717,7 +735,7 @@ public function discussions($Category = '') {
717735
// Add modules
718736
$this->addModule('NewDiscussionModule');
719737
$this->addModule('DiscussionFilterModule');
720-
$this->addModule('CategoriesModule');
738+
// $this->addModule('CategoriesModule');
721739
$this->addModule('BookmarkedModule');
722740
$this->addModule($CategoryFollowToggleModule);
723741

0 commit comments

Comments
 (0)