Skip to content

Commit 237f851

Browse files
committed
Merge branch 'develop'
2 parents 56d556c + 0fe13f4 commit 237f851

30 files changed

+9062
-186
lines changed

config/vanilla/bootstrap.before.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ function watchButton($categoryID) {
374374
* @return bool return true if user has a permission
375375
*/
376376
function checkGroupPermission($userID,$groupID, $categoryID = null , $permissionCategoryID = null , $permission = null, $fullMatch = true) {
377-
$groupModel = new GroupModel();
378-
return $groupModel->checkPermission($userID,$groupID, $categoryID,$permissionCategoryID , $permission, $fullMatch);
377+
return GroupModel::checkPermission($userID,$groupID, $categoryID,$permissionCategoryID , $permission, $fullMatch);
379378
}
380379
}
381380

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: 6 additions & 3 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

@@ -193,7 +196,7 @@
193196
$Configuration['Vanilla']['Comment']['MinLength'] = 2;
194197

195198
// File handling.
196-
$Configuration['Garden']['Upload']['MaxFileSize'] = '5M';
199+
$Configuration['Garden']['Upload']['MaxFileSize'] = '50M';
197200
$Configuration['Garden']['Upload']['AllowedFileExtensions'] = [
198201
'txt', 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'tiff', 'ico', 'zip', 'gz', 'tar.gz', 'tgz', 'psd', 'ai', 'pdf', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'log', 'rar', '7z', 'xml', 'json'
199202
];

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);

0 commit comments

Comments
 (0)