Skip to content

Commit 85c6b85

Browse files
authored
Merge pull request #14 from topcoder-platform/challenge-forum-processor-issues-17
Challenge forum processor issues 17
2 parents 06478b1 + ca9852a commit 85c6b85

File tree

7 files changed

+5278
-2
lines changed

7 files changed

+5278
-2
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ RUN rm -R /vanillapp/plugins/stubcontent
1515
RUN git clone https://github.com/topcoder-platform/forums-plugins.git /tmp/forums-plugins
1616
# Copy all plugins to the Vanilla plugins folder
1717
RUN cp -r /tmp/forums-plugins/. /vanillapp/plugins
18-
# Copy Vanilla boostrap file
19-
COPY ./config/vanilla/. /vanillapp/conf/.
18+
# Copy Vanilla configuration files
19+
COPY ./config/vanilla/. /vanillapp/conf/.
20+
# Copy Topcoder Vanilla files
21+
COPY ./vanilla/. /vanillapp/.

config/vanilla/bootstrap.early.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
saveToConfig('Garden.Email.SupportName', getenv('MAIL_FROM_NAME'), false);
1414
saveToConfig('Garden.Email.SupportAddress', getenv('MAIL_FROM_ADDRESS'), false);
15+
saveToConfig('Garden.Email.UseSmtp', getenv('MAIL_USE_SMTP'), false);
1516
saveToConfig('Garden.Email.SmtpHost', getenv('MAIL_SMTP_HOSTNAME'), false);
1617
saveToConfig('Garden.Email.SmtpUser', getenv('MAIL_SMTP_USERNAME'), false);
1718
saveToConfig('Garden.Email.SmtpPassword', getenv('MAIL_SMTP_PASSWORD'), false);

sample.vanilla.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ MAIL_SMTP_USERNAME=
66
MAIL_SMTP_PASSWORD=
77
MAIL_SMTP_PORT=
88
MAIL_SMTP_SECURITY=
9+
MAIL_USE_SMTP=
910
# TOPCODER PLUGIN
1011
TOPCODER_PLUGIN_BASE_API_URL=
1112
TOPCODER_PLUGIN_MEMBER_API_URI=
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
use Garden\Web\Exception\ClientException;
4+
5+
/**
6+
* Topcoder API Controller for the `/topcoder` resource.
7+
*/
8+
class TopcoderApiController extends AbstractApiController{
9+
10+
/** @var UserMetaModel */
11+
private $userMetaModel;
12+
/** @var UserMetaModel */
13+
private $categoryModel;
14+
/**
15+
* TopcoderApiController constructor.
16+
*
17+
* @param UserMetaModel $userMetaModel
18+
* @param CategoryModel $categoryModel
19+
*/
20+
public function __construct(UserMetaModel $userMetaModel, CategoryModel $categoryModel) {
21+
$this->userMetaModel = $userMetaModel;
22+
$this->categoryModel = $categoryModel;
23+
}
24+
25+
/**
26+
* Lookup a single category by its numeric ID
27+
*
28+
* @param int $id The category ID
29+
* @throws NotFoundException if the category cannot be found.
30+
* @return array
31+
*/
32+
private function category($id) {
33+
$category = CategoryModel::categories($id);
34+
if (empty($category)) {
35+
throw new NotFoundException('Category');
36+
}
37+
return $category;
38+
}
39+
40+
/**
41+
* Add the "watch" status on a category for the user.
42+
*
43+
* @param int $id The target category's ID.
44+
* @param $userId The target user's ID.
45+
* @param array $body
46+
* @return array
47+
* @throws ClientException
48+
* @throws \Garden\Schema\ValidationException
49+
* @throws \Garden\Web\Exception\HttpException
50+
* @throws \Vanilla\Exception\PermissionException
51+
*/
52+
public function put_watch($userId,$id, array $body) {
53+
$this->permission('Garden.SignIn.Allow');
54+
$schema = ['watched:b' => 'The category-watched status for the user.'];
55+
$in = $this->schema($schema, 'in');
56+
$out = $this->schema($schema, 'out');
57+
$body = $in->validate($body);
58+
$newEmailCommentKey = 'Preferences.Email.NewComment.'.$id;
59+
$newEmailDiscussionKey = 'Preferences.Email.NewDiscussion.'.$id;
60+
$newPopupCommentKey = 'Preferences.Popup.NewComment.'.$id;
61+
$newPopupDiscussionKey = 'Preferences.Popup.NewDiscussion.'.$id;
62+
$isDiscussionFollowed = count($this->userMetaModel->getUserMeta($userId,$newEmailDiscussionKey)) > 0;
63+
64+
// Is this a new watch?
65+
if ($body['watched'] && !$isDiscussionFollowed) {
66+
$category = $this->category($id);
67+
$this->permission('Vanilla.Discussions.View', $category['PermissionCategoryID']);
68+
}
69+
// null is used to remove data
70+
$watched = $body['watched'] ? 1 : null;
71+
$this->userMetaModel->setUserMeta($userId, $newEmailCommentKey , $watched);
72+
$this->userMetaModel->setUserMeta($userId, $newEmailDiscussionKey, $watched);
73+
$this->userMetaModel->setUserMeta($userId, $newPopupCommentKey , $watched);
74+
$this->userMetaModel->setUserMeta($userId, $newPopupDiscussionKey , $watched);
75+
76+
$result = $out->validate([
77+
'watched' => count($this->userMetaModel->getUserMeta($userId,$newEmailDiscussionKey)) > 0
78+
]);
79+
return $result;
80+
}
81+
}

0 commit comments

Comments
 (0)