Skip to content

Commit b4d610b

Browse files
author
James Cori
committed
Merge branch 'develop'
2 parents c2fe7ca + 79a04dc commit b4d610b

25 files changed

+13401
-72
lines changed

config/vanilla/bootstrap.before.php

Lines changed: 454 additions & 1 deletion
Large diffs are not rendered by default.

config/vanilla/bootstrap.early.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,63 @@
11
<?php if (!defined('APPLICATION')) exit();
22

33
if (c('Garden.Installed')) {
4-
// Only for update in future
4+
5+
// Update Vanilla Role Names
6+
Gdn::sql()->update('Role')->set('Name', 'Vanilla Member')->where('RoleID', 8)->put();
7+
Gdn::sql()->update('Role')->set('Name', 'Vanilla Admin')->where('RoleID', 16)->put();
8+
Gdn::sql()->update('Role')->set('Name', 'Vanilla Moderator')->where('RoleID', 32)->put();
9+
10+
11+
//
12+
// Update Vanilla tables and data
13+
//
14+
15+
//Add extra columns in Category : https://github.com/topcoder-platform/forums/issues/178
16+
if(!Gdn::structure()->table('Category')->columnExists('GroupID')) {
17+
Gdn::structure()->table('Category')
18+
->column('GroupID', 'int', true, 'key')
19+
->set(false, false);
20+
21+
// Update data after adding GroupID column: https://github.com/topcoder-platform/forums/issues/178
22+
Gdn::sql()->query("UPDATE GDN_Category c
23+
INNER JOIN (SELECT c.CategoryID, g.GroupID FROM GDN_Category c , GDN_Group g WHERE c.UrlCode LIKE concat(g.ChallengeID,'%')) AS src
24+
ON src.CategoryID = c.CategoryID
25+
SET c.GroupID = src.GroupID
26+
WHERE c.GroupID IS NULL");
27+
}
28+
29+
30+
31+
// Add the column Type in Group : https://github.com/topcoder-platform/forums/issues/133
32+
if(! Gdn::structure()->table('Group')->columnExists('Privacy')) {
33+
if(Gdn::structure()->table('Group')->renameColumn('Type', 'Privacy')) {
34+
35+
// Reset the internal state of this object so that it can be reused.
36+
Gdn::structure()->reset();
37+
38+
Gdn::structure()->table('Group')
39+
->column('Type', ['challenge', 'regular'], true)
40+
->set(false, false);
41+
42+
// Update existing data, all groups with ChallengeID will have the type 'challenge'
43+
Gdn::sql()->query("UPDATE GDN_Group g
44+
SET g.Type = CASE WHEN g.ChallengeID IS NOT NULL THEN 'challenge'
45+
ELSE 'regular' END");
46+
47+
Gdn::structure()->table('Group')
48+
->column('Type', ['challenge', 'regular'], false)
49+
->set(false, false);
50+
}
51+
}
52+
53+
// Add the column Archived in Group : https://github.com/topcoder-platform/forums/issues/136
54+
if(!Gdn::structure()->table('Group')->columnExists('Archived')) {
55+
Gdn::structure()->table('Group')
56+
->column('Archived', 'tinyint(1)', '0')
57+
->set(false, false);
58+
}
59+
60+
// Delete the records with UserID=0 (Guests) from UserRole table
61+
// FIX: https://github.com/topcoder-platform/forums/issues/108
62+
Gdn::sql()->delete('UserRole',['UserID' => 0]);
563
}

config/vanilla/bootstrap.late.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php if (!defined('APPLICATION')) exit();
2+
/**
3+
* Bootstrap Late
4+
*
5+
* All configurations are loaded, as well as the Application, Plugin and Theme
6+
* managers.
7+
*/
8+
9+
if (c('Garden.Installed')) {
10+
$Database = Gdn::database();
11+
$SQL = $Database->sql();
12+
$PermissionModel = Gdn::permissionModel();
13+
$PermissionModel->Database = Gdn::database();
14+
$PermissionModel->SQL = $SQL;
15+
16+
// Define some global vanilla permissions
17+
$PermissionModel->define(['Groups.Group.Add',
18+
'Groups.Group.Delete',
19+
'Groups.Group.Edit',
20+
'Groups.Category.Manage',
21+
'Groups.Moderation.Manage',
22+
'Groups.EmailInvitations.Add',
23+
'Groups.Group.Archive']);
24+
25+
updateRolePermissions(RoleModel::TYPE_GUEST, RoleModel::VANILLA_GUEST_ROLES);
26+
27+
// TODO: Role permission might be configured manually in the env
28+
// Before uncommenting the next lines:
29+
// Check all roles in the env and update all role permissions in RoleModel
30+
// updateRolePermissions(RoleModel::TYPE_TOPCODER, RoleModel::TOPCODER_ROLES);
31+
// updateTopcoderRolePermissions(RoleModel::TYPE_TOPCODER,RoleModel::TOPCODER_PROJECT_ROLES);
32+
}

config/vanilla/config.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
$Configuration['EnabledPlugins']['GettingStarted'] = 'GettingStarted';
2525
$Configuration['EnabledPlugins']['stubcontent'] = false;
2626
$Configuration['EnabledPlugins']['Topcoder'] = true;
27-
$Configuration['EnabledPlugins']['rich-editor'] = true;
27+
$Configuration['EnabledPlugins']['rich-editor'] = false;
2828
$Configuration['EnabledPlugins']['editor'] = true;
2929
$Configuration['EnabledPlugins']['emojiextender'] = true;
3030
$Configuration['EnabledPlugins']['GooglePrettify'] = true;
@@ -140,10 +140,31 @@
140140
// Vanilla
141141
$Configuration['Vanilla']['SSO']['Debug'] = true;
142142
$Configuration['Vanilla']['Activity']['ShowDiscussionBody'] = true;
143+
$Configuration['Vanilla']['Activity']['ShowCommentBody'] = true;
143144
$Configuration['Vanilla']['EnableCategoryFollowing'] = true;
144145
$Configuration['Vanilla']['Version'] = '3.0';
145146

146147
// memcached
147148
$Configuration['memcached']['Store'] = getenv('MEMCACHED_SERVER');
148149

149-
// Initial setup config
150+
// Initial setup config
151+
152+
// Email Template settings
153+
$Configuration['Garden']['Email']['Format']='html';
154+
$Configuration['Garden']['EmailTemplate']['BackgroundColor']='#ffffff';
155+
$Configuration['Garden']['EmailTemplate']['ButtonBackgroundColor']='transparent';
156+
$Configuration['Garden']['EmailTemplate']['ButtonTextColor']='#865827';
157+
$Configuration['Garden']['EmailTemplate']['Image']='https://www.dropbox.com/s/zddbsvh6f4h308o/e09141aacc790f0f31b80cc0bfd81cb9.png?dl=1';
158+
// Email Logo size
159+
$Configuration['Garden']['EmailTemplate']['ImageMaxWidth']='400';
160+
$Configuration['Garden']['EmailTemplate']['ImageMaxHeight']='300';
161+
162+
// Profile Configuration
163+
// Hide/Show the options in User Notification Preferences:
164+
// 'Email.WallComment' = 'Notify me when people write on my wall.'
165+
// 'Email.ActivityComment' = 'Notify me when people reply to my wall comments.'
166+
// 'Popup.WallComment' = 'Notify me when people write on my wall.'
167+
// 'Popup.ActivityComment' = 'Notify me when people reply to my wall comments.'
168+
// 'Email.ConversationMessage' = 'Notify me of private messages.'
169+
// 'Popup.ConversationMessage' = 'Notify me of private messages.'
170+
$Configuration['Garden']['Profile']['ShowActivities']=false;
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<?php
2+
/**
3+
* Hooks for Conversations.
4+
*
5+
* @copyright 2009-2019 Vanilla Forums Inc.
6+
* @license GPL-2.0-only
7+
* @package Conversations
8+
* @since 2.0
9+
*/
10+
11+
use Garden\Container\Container;
12+
use Garden\Container\Reference;
13+
14+
/**
15+
* Handles hooks into Dashboard and Vanilla.
16+
*/
17+
class ConversationsHooks implements Gdn_IPlugin {
18+
/**
19+
* Handle the container init event to register things with the container.
20+
*
21+
* @param Container $dic
22+
*/
23+
public function container_init(Container $dic) {
24+
$dic->rule(\Vanilla\Menu\CounterModel::class)
25+
->addCall('addProvider', [new Reference(ConversationCounterProvider::class)])
26+
;
27+
}
28+
29+
/**
30+
*
31+
*
32+
* @param DbaController $sender
33+
*/
34+
public function dbaController_countJobs_handler($sender) {
35+
$counts = [
36+
'Conversation' => ['CountMessages', 'CountParticipants', 'FirstMessageID', 'LastMessageID', 'DateUpdated', 'UpdateUserID']
37+
];
38+
39+
foreach ($counts as $table => $columns) {
40+
foreach ($columns as $column) {
41+
$name = "Recalculate $table.$column";
42+
$url = "/dba/counts.json?".http_build_query(['table' => $table, 'column' => $column]);
43+
44+
$sender->Data['Jobs'][$name] = $url;
45+
}
46+
}
47+
}
48+
49+
/**
50+
* Remove data when deleting a user.
51+
*
52+
* @since 2.0.0
53+
* @access public
54+
*/
55+
public function userModel_beforeDeleteUser_handler($sender) {
56+
$userID = val('UserID', $sender->EventArguments);
57+
$options = val('Options', $sender->EventArguments, []);
58+
$options = is_array($options) ? $options : [];
59+
60+
$deleteMethod = val('DeleteMethod', $options, 'delete');
61+
if ($deleteMethod == 'delete') {
62+
/** @var Gdn_SQLDriver $sql */
63+
$sql = $sender->SQL;
64+
$sql
65+
->from('UserConversation as uc')
66+
->join('Conversation as c', 'c.ConversationID = uc.ConversationID')
67+
->where(['c.InsertUserID' => $userID])
68+
->orWhere(['c.UpdateUserID' => $userID])
69+
->delete();
70+
$sql
71+
->from('ConversationMessage as cm')
72+
->join('Conversation as c', 'c.ConversationID = cm.ConversationID')
73+
->where(['c.InsertUserID' => $userID])
74+
->orWhere(['c.UpdateUserID' => $userID])
75+
->delete();
76+
77+
$sender->SQL->delete('Conversation', ['InsertUserID' => $userID]);
78+
$sender->SQL->delete('Conversation', ['UpdateUserID' => $userID]);
79+
} elseif ($deleteMethod == 'wipe') {
80+
$sender->SQL->update('ConversationMessage')
81+
->set('Body', t('The user and all related content has been deleted.'))
82+
->set('Format', 'Deleted')
83+
->where('InsertUserID', $userID)
84+
->put();
85+
}
86+
// Remove the user's profile information related to this application
87+
$sender->SQL->update('User')
88+
->set('CountUnreadConversations', 0)
89+
->where('UserID', $userID)
90+
->put();
91+
}
92+
93+
/**
94+
* Add 'Inbox' to profile menu.
95+
*
96+
* @since 2.0.0
97+
* @access public
98+
*/
99+
public function profileController_addProfileTabs_handler($sender) {
100+
if (Gdn::session()->isValid()) {
101+
$inbox = t('Inbox');
102+
$inboxHtml = sprite('SpInbox').' '.$inbox;
103+
$inboxLink = '/messages/all';
104+
105+
if (Gdn::session()->UserID != $sender->User->UserID) {
106+
// Accomodate admin access
107+
if (c('Conversations.Moderation.Allow', false) && Gdn::session()->checkPermission('Conversations.Moderation.Manage')) {
108+
$countUnread = $sender->User->CountUnreadConversations;
109+
$inboxLink .= "?userid={$sender->User->UserID}";
110+
} else {
111+
return;
112+
}
113+
} else {
114+
// Current user
115+
$countUnread = Gdn::session()->User->CountUnreadConversations;
116+
}
117+
118+
if (is_numeric($countUnread) && $countUnread > 0) {
119+
$inboxHtml .= ' <span class="Aside"><span class="Count">'.$countUnread.'</span></span>';
120+
}
121+
$sender->addProfileTab($inbox, $inboxLink, 'Inbox', $inboxHtml);
122+
}
123+
}
124+
125+
/**
126+
* Add "Message" option to profile options.
127+
*/
128+
public function profileController_beforeProfileOptions_handler($sender, $args) {
129+
if (!$sender->EditMode &&
130+
Gdn::session()->UserID != $sender->User->UserID &&
131+
Gdn::session()->checkPermission('Conversations.Conversations.Add')
132+
) {
133+
$sender->EventArguments['MemberOptions'][] = [
134+
'Text' => sprite('SpMessage').' '.t('Message'),
135+
'Url' => '/messages/add/'.rawurlencode($sender->User->Name),
136+
'CssClass' => 'MessageUser'
137+
];
138+
}
139+
}
140+
141+
142+
/**
143+
* Additional options for the Preferences screen.
144+
*
145+
* @since 2.0.0
146+
* @access public
147+
*/
148+
public function profileController_afterPreferencesDefined_handler($sender) {
149+
if (c('Garden.Profile.ShowActivities', true)) {
150+
$sender->Preferences['Notifications']['Email.ConversationMessage'] = t('Notify me of private messages.');
151+
$sender->Preferences['Notifications']['Popup.ConversationMessage'] = t('Notify me of private messages.');
152+
}
153+
}
154+
155+
/**
156+
* Add 'Inbox' to global menu.
157+
*
158+
* @since 2.0.0
159+
* @access public
160+
*/
161+
public function base_render_before($sender) {
162+
// Add the menu options for conversations
163+
if ($sender->Menu && Gdn::session()->isValid()) {
164+
$inbox = t('Inbox');
165+
$countUnreadConversations = val('CountUnreadConversations', Gdn::session()->User);
166+
if (is_numeric($countUnreadConversations) && $countUnreadConversations > 0) {
167+
$inbox .= ' <span class="Alert">'.$countUnreadConversations.'</span>';
168+
}
169+
170+
$sender->Menu->addLink('Conversations', $inbox, '/messages/all', false, ['Standard' => true]);
171+
}
172+
}
173+
174+
/**
175+
* Let us add Messages to the Inbox page.
176+
*/
177+
public function base_afterGetLocationData_handler($sender, $args) {
178+
$args['ControllerData']['Conversations/messages/inbox'] = t('Inbox Page');
179+
}
180+
181+
/**
182+
* Provide default permissions for roles, based on the value in their Type column.
183+
*
184+
* @param PermissionModel $sender Instance of permission model that fired the event
185+
*/
186+
public function permissionModel_defaultPermissions_handler($sender) {
187+
$sender->addDefault(
188+
RoleModel::TYPE_MEMBER,
189+
['Conversations.Conversations.Add' => 1]
190+
);
191+
$sender->addDefault(
192+
RoleModel::TYPE_MODERATOR,
193+
['Conversations.Conversations.Add' => 1]
194+
);
195+
$sender->addDefault(
196+
RoleModel::TYPE_ADMINISTRATOR,
197+
['Conversations.Conversations.Add' => 1]
198+
);
199+
}
200+
201+
/**
202+
* Database & config changes to be done upon enable.
203+
*
204+
* @since 2.0.0
205+
* @access public
206+
*/
207+
public function setup() {
208+
$Database = Gdn::database();
209+
$Config = Gdn::factory(Gdn::AliasConfig);
210+
$Drop = false;
211+
$Validation = new Gdn_Validation(); // This is going to be needed by structure.php to validate permission names
212+
include(PATH_APPLICATIONS.DS.'conversations'.DS.'settings'.DS.'structure.php');
213+
include(PATH_APPLICATIONS.DS.'conversations'.DS.'settings'.DS.'stub.php');
214+
}
215+
}

0 commit comments

Comments
 (0)