Skip to content

Commit 9f8004b

Browse files
authored
Merge pull request #187 from topcoder-platform/develop
Prod deploy
2 parents 66450ad + aa26f7b commit 9f8004b

File tree

5 files changed

+126
-158
lines changed

5 files changed

+126
-158
lines changed

config/vanilla/bootstrap.early.php

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,5 @@
11
<?php if (!defined('APPLICATION')) exit();
22

33
if (c('Garden.Installed')) {
4-
$Database = Gdn::database();
5-
$SQL = $Database->sql();
6-
7-
// Cache Settings
8-
saveToConfig('Cache.Enabled', getenv('CACHE_ENABLED'), true);
9-
saveToConfig('Cache.Method', getenv('CACHE_METHOD'), 'dirtycache');
10-
saveToConfig('memcached.Store', getenv('MEMCACHED_SERVER'), 'localhost:11211');
11-
12-
saveToConfig('Garden.Email.SupportName', getenv('MAIL_FROM_NAME') );
13-
saveToConfig('Garden.Email.SupportAddress', getenv('MAIL_FROM_ADDRESS'));
14-
saveToConfig('Garden.Email.UseSmtp', getenv('MAIL_USE_SMTP'));
15-
saveToConfig('Garden.Email.SmtpHost', getenv('MAIL_SMTP_HOSTNAME'));
16-
saveToConfig('Garden.Email.SmtpUser', getenv('MAIL_SMTP_USERNAME'));
17-
saveToConfig('Garden.Email.SmtpPassword', getenv('MAIL_SMTP_PASSWORD'));
18-
saveToConfig('Garden.Email.SmtpPort', getenv('MAIL_SMTP_PORT'));
19-
saveToConfig('Garden.Email.SmtpSecurity', getenv('MAIL_SMTP_SECURITY'));
20-
21-
// Appearance
22-
saveToConfig('Garden.Theme', 'topcoder-theme', false);
23-
saveToConfig('Garden.MobileTheme', 'topcoder-theme', false);
24-
saveToConfig('Feature.NewFlyouts.Enabled', true);
25-
26-
// Feature
27-
saveToConfig('Garden.EditContentTimeout', -1, false);
28-
29-
// Profile settings
30-
saveToConfig('Garden.Profile.EditPhotos', false);
31-
32-
// Add settings for the Topcoder plugin
33-
saveToConfig('Plugins.Topcoder.BaseApiURL', getenv('TOPCODER_PLUGIN_BASE_API_URL'),false);
34-
saveToConfig('Plugins.Topcoder.MemberApiURI', getenv('TOPCODER_PLUGIN_MEMBER_API_URI'),false);
35-
saveToConfig('Plugins.Topcoder.RoleApiURI', getenv('TOPCODER_PLUGIN_ROLE_API_URI'),false);
36-
saveToConfig('Plugins.Topcoder.ResourceRolesApiURI', '/v5/resource-roles', false);
37-
saveToConfig('Plugins.Topcoder.ResourcesApiURI', '/v5/resources', false);
38-
saveToConfig('Plugins.Topcoder.MemberProfileURL', getenv('TOPCODER_PLUGIN_MEMBER_PROFILE_URL'), false); // prod:
39-
saveToConfig('Plugins.Topcoder.UseTopcoderAuthToken', getenv('TOPCODER_PLUGIN_USE_AUTH_TOKEN'), false);
40-
41-
saveToConfig('Plugins.Topcoder.ValidIssuers', str_replace(["[", "]", "\\", "\"", " "], '', getenv('VALID_ISSUERS')));
42-
43-
//Add settings for Topcoder M2M Auth0
44-
saveToConfig('Plugins.Topcoder.M2M.Auth0Audience', getenv('AUTH0_AUDIENCE'));
45-
saveToConfig('Plugins.Topcoder.M2M.Auth0ClientId', getenv('AUTH0_CLIENT_ID'));
46-
saveToConfig('Plugins.Topcoder.M2M.Auth0ClientSecret', getenv('AUTH0_CLIENT_SECRET'));
47-
saveToConfig('Plugins.Topcoder.M2M.Auth0Url', getenv('AUTH0_URL'));
48-
saveToConfig('Plugins.Topcoder.M2M.Auth0ProxyServerUrl', getenv('AUTH0_PROXY_SERVER_URL'));
49-
50-
//Add settings for Topcoder SSO Auth0
51-
saveToConfig('Plugins.Topcoder.SSO.Auth0Domain', getenv('TOPCODER_PLUGIN_SSO_AUTH0DOMAIN'));
52-
saveToConfig('Plugins.Topcoder.SSO.AuthorizationURI', '/v3/authorizations/1');
53-
saveToConfig('Plugins.Topcoder.SSO.CookieName', 'v3jwt',false);
54-
saveToConfig('Plugins.Topcoder.SSO.TopcoderRS256.ID', getenv('TOPCODER_PLUGIN_SSO_TOPCODER_RS256_ID'), false);
55-
saveToConfig('Plugins.Topcoder.SSO.TopcoderHS256.ID', getenv('TOPCODER_PLUGIN_SSO_TOPCODER_HS256_ID'), false);
56-
57-
saveToConfig('Plugins.Topcoder.SSO.TopcoderHS256.Secret', getenv('TOPCODER_HS256_SECRET') );
58-
saveToConfig('Plugins.Topcoder.SSO.TopcoderRS256.UsernameClaim', 'nickname',false);
59-
saveToConfig('Plugins.Topcoder.SSO.TopcoderHS256.UsernameClaim', 'handle',false);
60-
$topcoderSSOAuth0Url = getenv('TOPCODER_PLUGIN_SSO_REFRESHTOKENURL');
61-
saveToConfig('Plugins.Topcoder.SSO.RefreshTokenURL', $topcoderSSOAuth0Url,false);
62-
$signInUrl = getenv('TOPCODER_PLUGIN_SIGNIN_URL');
63-
$signOutUrl = getenv('TOPCODER_PLUGIN_SIGNOUT_URL');
64-
if($signInUrl === false) {
65-
$signInUrl =$topcoderSSOAuth0Url.'?retUrl='.urlencode('https://'.$_SERVER['SERVER_NAME'].'/');
66-
}
67-
if($signOutUrl === false) {
68-
$signOutUrl =$topcoderSSOAuth0Url.'?logout=true&retUrl='.urlencode('https://'.$_SERVER['SERVER_NAME'].'/');
69-
}
70-
saveToConfig('Plugins.Topcoder.AuthenticationProvider.SignInUrl', $signInUrl,false);
71-
saveToConfig('Plugins.Topcoder.AuthenticationProvider.SignOutUrl', $signOutUrl,false);
72-
saveToConfig('Plugins.Topcoder.AuthenticationProvider.RegisterUrl', getenv('TOPCODER_PLUGIN_AUTHENTICATIONPROVIDER_REGISTERURL'),false);
73-
74-
// Filestack
75-
saveToConfig('Plugins.Filestack.ApiKey', getenv('FILESTACK_API_KEY'),false);
76-
77-
// SumoLogic
78-
saveToConfig('Plugins.Sumologic.HttpSourceURL', '',false);
79-
saveToConfig('Plugins.Sumologic.BatchSize', '10',false);
80-
81-
// Add settings for the Editor plugin
82-
if(c('Plugins.editor.ForceWysiwyg') === false) {
83-
saveToConfig('Plugins.editor.ForceWysiwyg', false);
84-
}
85-
86-
// Add settings for the Syntax Prettifier plugin
87-
if(c('Plugins.GooglePrettify.LineNumbers') === false) {
88-
saveToConfig('Plugins.GooglePrettify.LineNumbers', '');
89-
saveToConfig('Plugins.GooglePrettify.NoCssFile', '');
90-
saveToConfig('Plugins.GooglePrettify.UseTabby', '');
91-
saveToConfig('Plugins.GooglePrettify.Language', '');
92-
}
93-
94-
// Add settings for the Recaptcha plugin
95-
if(c('Recaptcha.PrivateKey') === false) {
96-
saveToConfig('Recaptcha.PrivateKey', getenv('RECAPTCHA_PLUGIN_PRIVATE_KEY'), false);
97-
saveToConfig('Recaptcha.PublicKey', getenv('RECAPTCHA_PLUGIN_PUBLIC_KEY'), false);
98-
}
99-
100-
// Fix: Add the 'topcoder' role type in Role Table. It should be removed after upgrading existing DB.
101-
// The Topcoder plugin's setup method will upgrade DB during Vanilla installation
102-
$SQL->query('alter table GDN_Role modify Type enum(\'topcoder\', \'guest\', \'unconfirmed\', \'applicant\', \'member\', \'moderator\', \'administrator\')');
103-
4+
// Only for update in future
1045
}

config/vanilla/config.php

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
$Configuration['Garden']['Installed'] = true;
44

5-
$Configuration['Garden']['SignIn']['Popup'] = false; // Should the sign-in link pop up or go to it's own page
6-
7-
// Conversations
8-
$Configuration['Conversations']['Version'] = '3.0';
9-
$Configuration['Conversations']['Moderation']['Allow'] = true;
10-
11-
// Database
125
$Configuration['Database']['Name'] = getenv('MYSQL_DATABASE');
136
$Configuration['Database']['Host'] = getenv('MYSQL_HOST');
147
$Configuration['Database']['User'] = getenv('MYSQL_ROOT_USER');
158
$Configuration['Database']['Password'] = getenv('MYSQL_ROOT_PASSWORD');
169

10+
// Cache
11+
$Configuration['Cache']['Enabled'] = getenv('CACHE_ENABLED');
12+
$Configuration['Cache']['Method'] = getenv('CACHE_METHOD');
13+
14+
// Conversations
15+
$Configuration['Conversations']['Version'] = '3.0';
16+
$Configuration['Conversations']['Moderation']['Allow'] = true;
17+
1718
// EnabledApplications
1819
$Configuration['EnabledApplications']['Conversations'] = 'conversations';
1920
$Configuration['EnabledApplications']['Vanilla'] = 'vanilla';
@@ -33,35 +34,39 @@
3334
$Configuration['EnabledPlugins']['Groups'] = true;
3435
$Configuration['EnabledPlugins']['Filestack'] = true;
3536
$Configuration['EnabledPlugins']['Sumologic'] = true;
36-
$Configuration['EnabledPlugins']['ReplyTo'] = true; //Uncomment it after upgrading DB
37-
38-
// Debug
39-
$Configuration['Debug'] = FALSE;
40-
$Configuration['Vanilla']['SSO']['Debug'] = TRUE;
41-
42-
// Email contents
43-
$Configuration['Vanilla']['Activity']['ShowDiscussionBody'] = true;
37+
$Configuration['EnabledPlugins']['ReplyTo'] = true;
4438

4539
// Feature
4640
$Configuration['Feature']['NewFlyouts']['Enabled'] = true;
47-
$Configuration['Vanilla']['EnableCategoryFollowing'] = true;
48-
$Configuration['Garden']['EditContentTimeout'] = -1;
4941

5042
// Garden
43+
$Configuration['Garden']['SignIn']['Popup'] = false;
44+
$Configuration['Garden']['EditContentTimeout'] = -1;
5145
$Configuration['Garden']['Title'] = 'Vanilla';
5246
$Configuration['Garden']['Cookie']['Salt'] = 'rLpGSLgZD1AGdJ4n';
5347
$Configuration['Garden']['Cookie']['Domain'] = '';
5448
$Configuration['Garden']['Registration']['ConfirmEmail'] = true;
55-
$Configuration['Garden']['Email']['SupportName'] = 'Vanilla';
49+
$Configuration['Garden']['Email']['SupportName'] = getenv('MAIL_FROM_NAME');
5650
$Configuration['Garden']['Email']['Format'] = 'text';
57-
$Configuration['Garden']['SystemUserID'] = '1';
58-
$Configuration['Garden']['UpdateToken'] = 'c3988cd76f721f1a03d2c347ab6655609a548425';
51+
$Configuration['Garden']['Email']['SupportAddress'] = getenv('MAIL_FROM_ADDRESS');
52+
$Configuration['Garden']['Email']['UseSmtp'] = getenv('MAIL_USE_SMTP');
53+
$Configuration['Garden']['Email']['SmtpHost'] = getenv('MAIL_SMTP_HOSTNAME');
54+
$Configuration['Garden']['Email']['SmtpUser'] = getenv('MAIL_SMTP_USERNAME');
55+
$Configuration['Garden']['Email']['SmtpPassword'] = getenv('MAIL_SMTP_PASSWORD');
56+
$Configuration['Garden']['Email']['SmtpPort'] = getenv('MAIL_SMTP_PORT');
57+
$Configuration['Garden']['Email']['SmtpSecurity'] = getenv('MAIL_SMTP_SECURITY');
58+
$Configuration['Garden']['UpdateToken'] = '105e786dc643fd20143d3c137b593af168560c13';
5959
$Configuration['Garden']['InputFormatter'] = 'Rich';
6060
$Configuration['Garden']['Version'] = 'Undefined';
6161
$Configuration['Garden']['CanProcessImages'] = true;
6262
$Configuration['Garden']['Theme'] = 'topcoder-theme';
6363
$Configuration['Garden']['MobileTheme'] = 'topcoder-theme';
6464
$Configuration['Garden']['Profile']['EditPhotos'] = false;
65+
$Configuration['Garden']['SystemUserID'] = '1';
66+
$Configuration['Garden']['MobileInputFormatter'] = 'Rich';
67+
$Configuration['Garden']['AllowFileUploads'] = true;
68+
$Configuration['Garden']['EditContentTimeout'] = -1;
69+
$Configuration['Garden']['Profile']['EditPhotos'] = false;
6570

6671
// Plugins
6772
$Configuration['Plugins']['editor']['ForceWysiwyg'] = false;
@@ -72,6 +77,43 @@
7277
$Configuration['Plugins']['GettingStarted']['Dashboard'] = '1';
7378
$Configuration['Plugins']['GettingStarted']['Plugins'] = '1';
7479

80+
81+
$Configuration['Plugins']['Topcoder']['BaseApiURL'] = getenv('TOPCODER_PLUGIN_BASE_API_URL');
82+
$Configuration['Plugins']['Topcoder']['MemberApiURI'] = getenv('TOPCODER_PLUGIN_MEMBER_API_URI');
83+
$Configuration['Plugins']['Topcoder']['RoleApiURI'] = getenv('TOPCODER_PLUGIN_ROLE_API_URI');
84+
$Configuration['Plugins']['Topcoder']['ResourceRolesApiURI'] = '/v5/resource-roles';
85+
$Configuration['Plugins']['Topcoder']['ResourcesApiURI'] = '/v5/resources';
86+
$Configuration['Plugins']['Topcoder']['MemberProfileURL'] = getenv('TOPCODER_PLUGIN_MEMBER_PROFILE_URL');
87+
$Configuration['Plugins']['Topcoder']['UseTopcoderAuthToken'] = getenv('TOPCODER_PLUGIN_USE_AUTH_TOKEN');
88+
89+
90+
$Configuration['Plugins']['Topcoder']['ValidIssuers'] = str_replace(["[", "]", "\\", "\"", " "], '', getenv('VALID_ISSUERS'));
91+
$Configuration['Plugins']['Topcoder']['M2M']['Auth0Audience'] = getenv('AUTH0_AUDIENCE');
92+
$Configuration['Plugins']['Topcoder']['M2M']['Auth0ClientId'] = getenv('AUTH0_CLIENT_ID');
93+
$Configuration['Plugins']['Topcoder']['M2M']['Auth0ClientSecret'] = getenv('AUTH0_CLIENT_SECRET');
94+
$Configuration['Plugins']['Topcoder']['M2M']['Auth0Url'] = getenv('AUTH0_URL');
95+
$Configuration['Plugins']['Topcoder']['M2M']['Auth0ProxyServerUrl'] = getenv('AUTH0_PROXY_SERVER_URL');
96+
$Configuration['Plugins']['Topcoder']['SSO']['Auth0Domain'] = getenv('TOPCODER_PLUGIN_SSO_AUTH0DOMAIN');
97+
$Configuration['Plugins']['Topcoder']['SSO']['AuthorizationURI'] = '/v3/authorizations/1';
98+
$Configuration['Plugins']['Topcoder']['SSO']['CookieName'] = 'v3jwt';
99+
$Configuration['Plugins']['Topcoder']['SSO']['TopcoderRS256']['ID'] = getenv('TOPCODER_PLUGIN_SSO_TOPCODER_RS256_ID');
100+
$Configuration['Plugins']['Topcoder']['SSO']['TopcoderHS256']['ID'] = getenv('TOPCODER_PLUGIN_SSO_TOPCODER_HS256_ID');
101+
$Configuration['Plugins']['Topcoder']['SSO']['TopcoderHS256']['Secret'] = getenv('TOPCODER_HS256_SECRET');
102+
$Configuration['Plugins']['Topcoder']['SSO']['TopcoderRS256']['UsernameClaim'] = 'nickname';
103+
$Configuration['Plugins']['Topcoder']['SSO']['TopcoderHS256']['UsernameClaim'] = 'handle';
104+
$Configuration['Plugins']['Topcoder']['SSO']['RefreshTokenURL' ] = getenv('TOPCODER_PLUGIN_SSO_REFRESHTOKENURL');
105+
106+
// Filestack
107+
$Configuration['Plugins']['Filestack']['ApiKey'] = getenv('FILESTACK_API_KEY');
108+
109+
// SumoLogic
110+
$Configuration['Plugins']['Sumologic']['HttpSourceURL'] = '';
111+
$Configuration['Plugins']['Sumologic']['BatchSize'] = 10;
112+
113+
114+
// RichEditor
115+
$Configuration['RichEditor']['Quote']['Enable'] = true;
116+
75117
// Routes
76118
$Configuration['Routes']['YXBwbGUtdG91Y2gtaWNvbi5wbmc='] = array (
77119
0 => 'utility/showtouchicon',
@@ -90,8 +132,18 @@
90132
1 => 'Internal',
91133
);
92134
$Configuration['Routes']['DefaultController'] = 'discussions';
135+
$Configuration['Routes']['XmZpbGVzdGFjaygvLiopPyQ='] = array (
136+
0 => 'vanilla/filestack$1',
137+
1 => 'Internal',
138+
);
93139

94140
// Vanilla
141+
$Configuration['Vanilla']['SSO']['Debug'] = true;
142+
$Configuration['Vanilla']['Activity']['ShowDiscussionBody'] = true;
143+
$Configuration['Vanilla']['EnableCategoryFollowing'] = true;
95144
$Configuration['Vanilla']['Version'] = '3.0';
96145

97-
// Last edited by admin (172.26.0.1) 2020-09-03 13:16:33
146+
// memcached
147+
$Configuration['memcached']['Store'] = getenv('MEMCACHED_SERVER');
148+
149+
// Initial setup config

docker-compose.dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ services:
77
- 3306:3306
88
env_file:
99
- ./mysql.env
10+
security_opt:
11+
- seccomp:unconfined
1012
command: --default-authentication-plugin=mysql_native_password
1113
vanilla-forums:
1214
links:

vanilla/applications/dashboard/models/class.rolemodel.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ class RoleModel extends Gdn_Model {
4545
'Connect Manager' => [],
4646
'Connect Account Manager' => [],
4747
'Connect Copilot' => [
48-
'Name' => ROLE_TOPCODER_CONNECT_COPILOT,
49-
'Type' => ROLE_TYPE_TOPCODER,
50-
'Garden.Uploads.Add' => 1
48+
'Groups.Category.Manage' => 1,
49+
'Groups.Moderation.Manage' => 1,
50+
'Groups.EmailInvitations.Add' => 1
5151
],
5252
'Connect Admin' => [
5353
// all permissions
5454
],
55-
'Connect Copilot Manager' => [],
55+
'Connect Copilot Manager' => [
56+
'Groups.Category.Manage' => 1,
57+
'Groups.Moderation.Manage' => 1,
58+
'Groups.EmailInvitations.Add' => 1
59+
],
5660
'Business Development Representative' => [],
5761
'Presales' => [],
5862
'Account Executive' => [],
@@ -63,11 +67,15 @@ class RoleModel extends Gdn_Model {
6367
];
6468

6569
const TOPCODER_PROJECT_ROLES = [
66-
'manager' => [],
70+
'manager' => [
71+
'Groups.Category.Manage' => 1,
72+
'Groups.Moderation.Manage' => 1,
73+
'Groups.EmailInvitations.Add' => 1
74+
],
6775
'copilot' => [
68-
'Name' => ROLE_TOPCODER_PROJECT_COPILOT,
69-
'Type' => ROLE_TYPE_TOPCODER,
70-
'Garden.Uploads.Add' => 1
76+
'Groups.Category.Manage' => 1,
77+
'Groups.Moderation.Manage' => 1,
78+
'Groups.EmailInvitations.Add' => 1
7179
],
7280
'customer' => [],
7381
'observer'=> [],

vanilla/applications/dashboard/settings/class.hooks.php

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -912,52 +912,57 @@ public function updateModel_afterStructure_handler($sender) {
912912
if (!$hasPermissions) {
913913
PermissionModel::resetAllRoles();
914914

915-
// TODO: refactor it
916-
//create Topocder roles
917-
918915
$RoleModel = new RoleModel();
919916
$PermissionModel = new PermissionModel();
920917
// Configure default permission for Topcoder roles
921918
$allRoles = $RoleModel->getByType(RoleModel::TYPE_TOPCODER)->resultArray();
922-
foreach ($allRoles as $role) {
923-
$allPermissions = $PermissionModel->getRolePermissions($role['RoleID']);
924-
foreach ($allPermissions as $permission) {
925-
$roleName = $role['Name'];
926-
if (array_key_exists($roleName, RoleModel::TOPCODER_ROLES)) {
927-
if ($roleName == RoleModel::ROLE_TOPCODER_CONNECT_ADMIN || $roleName == RoleModel::ROLE_TOPCODER_ADMINISTRATOR) {
928-
foreach ($permission as $key => $value) {
929-
if ($key != 'PermissionID' && $key != 'RoleID' && $key != 'JunctionTable' && $key != 'JunctionColumn'
930-
&& $key !== 'JunctionID') {
931-
$permission[$key] = 1;
932-
}
933-
}
934-
} else {
935-
$globalRolePermissions = RoleModel::TOPCODER_ROLES[$roleName];
936-
foreach ($permission as $key => $value) {
937-
if ($key != 'PermissionID' && $key != 'RoleID' && $key != 'JunctionTable' && $key != 'JunctionColumn'
938-
&& $key !== 'JunctionID') {
939-
$permission[$key] = array_key_exists($key, $globalRolePermissions) ? $globalRolePermissions[$key] : $value;
940-
}
941-
}
919+
$this->updateTopcoderRolePermissions($PermissionModel, $allRoles, RoleModel::TOPCODER_ROLES);
920+
$this->updateTopcoderRolePermissions($PermissionModel, $allRoles, RoleModel::TOPCODER_PROJECT_ROLES);
921+
$this->configureDefaultCategoryPermission($PermissionModel, $allRoles, RoleModel::TOPCODER_ROLES);
922+
923+
}
924+
}
925+
private function configureDefaultCategoryPermission($PermissionModel, $allRoles) {
926+
foreach ($allRoles as $role) {
927+
$allPermissions = $PermissionModel->getRolePermissions($role['RoleID'], '', 'Category', 'PermissionCategoryID', -1);
928+
foreach ($allPermissions as $permission) {
929+
$roleName = $role['Name'];
930+
if ($roleName == RoleModel::ROLE_TOPCODER_CONNECT_ADMIN || $roleName == RoleModel::ROLE_TOPCODER_ADMINISTRATOR) {
931+
foreach ($permission as $key => $value) {
932+
if ($key != 'PermissionID' && $key != 'RoleID' && $key != 'JunctionTable' && $key != 'JunctionColumn'
933+
&& $key !== 'JunctionID') {
934+
$permission[$key] = 1;
942935
}
943936
$PermissionModel->save($permission);
944937
}
945938
}
946939
}
947-
// Configure default category permission for Topcoder roles
948-
foreach ($allRoles as $role) {
949-
$allPermissions = $PermissionModel->getRolePermissions($role['RoleID'], '', 'Category', 'PermissionCategoryID', -1);
950-
foreach ($allPermissions as $permission) {
951-
$roleName = $role['Name'];
940+
}
941+
}
942+
943+
private function updateTopcoderRolePermissions($PermissionModel, $allRoles, $topcoderRoles) {
944+
foreach ($allRoles as $role) {
945+
$allPermissions = $PermissionModel->getRolePermissions($role['RoleID']);
946+
foreach ($allPermissions as $permission) {
947+
$roleName = $role['Name'];
948+
if (array_key_exists($roleName, $topcoderRoles)) {
952949
if ($roleName == RoleModel::ROLE_TOPCODER_CONNECT_ADMIN || $roleName == RoleModel::ROLE_TOPCODER_ADMINISTRATOR) {
953950
foreach ($permission as $key => $value) {
954951
if ($key != 'PermissionID' && $key != 'RoleID' && $key != 'JunctionTable' && $key != 'JunctionColumn'
955952
&& $key !== 'JunctionID') {
956953
$permission[$key] = 1;
957954
}
958-
$PermissionModel->save($permission);
955+
}
956+
} else {
957+
$globalRolePermissions = $topcoderRoles[$roleName];
958+
foreach ($permission as $key => $value) {
959+
if ($key != 'PermissionID' && $key != 'RoleID' && $key != 'JunctionTable' && $key != 'JunctionColumn'
960+
&& $key !== 'JunctionID') {
961+
$permission[$key] = array_key_exists($key, $globalRolePermissions) ? $globalRolePermissions[$key] : $value;
962+
}
959963
}
960964
}
965+
$PermissionModel->save($permission);
961966
}
962967
}
963968
}

0 commit comments

Comments
 (0)