Skip to content

Commit 3ec715b

Browse files
committed
Issues-108
1 parent f290b2d commit 3ec715b

File tree

3 files changed

+97
-14
lines changed

3 files changed

+97
-14
lines changed

config/vanilla/bootstrap.before.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,24 @@ function checkGroupPermission($groupID,$permission = null, $fullMatch = true) {
372372
}
373373
}
374374

375-
if(!function_exists('updateTopcoderRolePermissions')) {
375+
if(!function_exists('updateRolePermissions')) {
376376

377-
function updateTopcoderRolePermissions($topcoderRoles) {
377+
/**
378+
* Update role permissions
379+
* @param $roleType
380+
* @param $roles
381+
*/
382+
function updateRolePermissions($roleType, $roles) {
378383
$RoleModel = new RoleModel();
379384
$PermissionModel = new PermissionModel();
380-
// Configure default permission for Topcoder roles
381-
$allRoles = $RoleModel->getByType(RoleModel::TYPE_TOPCODER)->resultArray();
385+
// Configure default permission for roles
386+
$allRoles = $RoleModel->getByType($roleType)->resultArray();
382387
foreach ($allRoles as $role) {
383388
$allPermissions = $PermissionModel->getRolePermissions($role['RoleID']);
384389
foreach ($allPermissions as $permission) {
385390
$roleName = $role['Name'];
386-
if (array_key_exists($roleName, $topcoderRoles)) {
387-
$globalRolePermissions = $topcoderRoles[$roleName];
391+
if (array_key_exists($roleName, $roles)) {
392+
$globalRolePermissions = $roles[$roleName];
388393
foreach ($globalRolePermissions as $key => $value) {
389394
$permission[$key] = $globalRolePermissions[$key];
390395
}
@@ -393,5 +398,4 @@ function updateTopcoderRolePermissions($topcoderRoles) {
393398
}
394399
}
395400
}
396-
397401
}

config/vanilla/bootstrap.late.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
'Groups.EmailInvitations.Add',
2323
'Groups.Group.Archive']);
2424

25-
// TODO: need to be sure that all roles and permissions haven't be changed manually in prod/dev
26-
updateTopcoderRolePermissions(RoleModel::TOPCODER_ROLES);
27-
// updateTopcoderRolePermissions(RoleModel::TOPCODER_PROJECT_ROLES);
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);
2832
}

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

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class RoleModel extends Gdn_Model {
6666
'Groups.Category.Manage' => 1,
6767
'Groups.Group.Delete' => 1,
6868
'Groups.Group.Edit' => 1,
69+
'Groups.Group.Archive' => 1,
6970
'Garden.Uploads.Add' => 1,
7071
'Vanilla.Tagging.Add' => 1,
7172
'Conversations.Moderation.Manage' => 1,
@@ -83,17 +84,82 @@ class RoleModel extends Gdn_Model {
8384
'Vanilla.Comments.Edit' => 1,
8485
'Vanilla.Comments.Delete' => 1,
8586
'Plugins.Attachments.Upload.Allow' => 1,
86-
'Groups.Group.Archive' => 1
87+
];
88+
89+
const GUEST_PERMISSIONS = [
90+
'Garden.Email.View' => 0,
91+
'Garden.Settings.Manage' => 0,
92+
'Garden.Settings.View' => 0,
93+
'Garden.SignIn.Allow' => 0,
94+
'Garden.Users.Add' => 0,
95+
'Garden.Users.Edit' => 0,
96+
'Garden.Users.Delete' => 0,
97+
'Garden.Users.Approve' => 0,
98+
'Garden.Activity.Delete' => 0,
99+
'Garden.Activity.View' => 0,
100+
'Garden.Profiles.View' => 0,
101+
'Garden.Profiles.Edit' => 0,
102+
'Garden.Curation.Manage' => 0,
103+
'Garden.Moderation.Manage' => 0,
104+
'Garden.PersonalInfo.View' => 0,
105+
'Garden.AdvancedNotifications.Allow' => 0,
106+
'Garden.Community.Manage' => 0,
107+
'Garden.Tokens.Add' => 0,
108+
'Groups.Group.Add' => 0,
109+
'Groups.Moderation.Manage' => 0,
110+
'Groups.EmailInvitations.Add' => 0,
111+
'Groups.Category.Manage' => 0,
112+
'Groups.Group.Delete' => 0,
113+
'Groups.Group.Edit' => 0,
114+
'Groups.Group.Archive' => 0,
115+
'Garden.Uploads.Add' => 0,
116+
'Vanilla.Tagging.Add' => 0,
117+
'Conversations.Moderation.Manage' => 0,
118+
'Conversations.Conversations.Add'=> 0,
119+
'Vanilla.Approval.Require' => 1, //
120+
'Vanilla.Comments.Me' => 0,
121+
'Vanilla.Discussions.View' => 0,
122+
'Vanilla.Discussions.Add' => 0,
123+
'Vanilla.Discussions.Edit' => 0,
124+
'Vanilla.Discussions.Announce' => 0,
125+
'Vanilla.Discussions.Sink' => 0,
126+
'Vanilla.Discussions.Close' => 0,
127+
'Vanilla.Discussions.Delete' => 0,
128+
'Vanilla.Comments.Add' => 0,
129+
'Vanilla.Comments.Edit' => 0,
130+
'Vanilla.Comments.Delete' => 0,
131+
'Plugins.Attachments.Upload.Allow' => 0
132+
];
87133

134+
const VANILLA_GUEST_ROLES = [
135+
'Guest' => self::GUEST_PERMISSIONS //The default Vanilla role for Guests
88136
];
137+
89138
const TOPCODER_ROLES = [
90139
'administrator' => self::ALL_VANILLA_PERMISSIONS,
91-
'Connect Manager' => [],
140+
'Connect Manager' => [
141+
'Groups.Category.Manage' => 1,
142+
],
92143
'Connect Account Manager' => [],
93144
'Connect Copilot' => [
94145
'Groups.Category.Manage' => 1,
95146
'Groups.Moderation.Manage' => 1,
96-
'Groups.EmailInvitations.Add' => 1
147+
'Groups.EmailInvitations.Add' => 1,
148+
'Groups.Category.Manage' => 1,
149+
'Groups.Moderation.Manage' => 1,
150+
'Groups.EmailInvitations.Add' => 1,
151+
'Garden.Uploads.Add' => 1,
152+
'Plugins.Attachments.Upload.Allow' => 1,
153+
'Vanilla.Discussions.View' => 1,
154+
'Vanilla.Discussions.Add' => 1,
155+
'Vanilla.Discussions.Edit' => 1,
156+
'Vanilla.Discussions.Announce' => 1,
157+
'Vanilla.Discussions.Sink' => 1,
158+
'Vanilla.Discussions.Close' => 0,
159+
'Vanilla.Discussions.Delete' => 1,
160+
'Vanilla.Comments.Add' => 1,
161+
'Vanilla.Comments.Edit' => 0,
162+
'Vanilla.Comments.Delete' => 1,
97163
],
98164
'Connect Admin' => self::ALL_VANILLA_PERMISSIONS,
99165
'Connect Copilot Manager' => [
@@ -119,7 +185,16 @@ class RoleModel extends Gdn_Model {
119185
'copilot' => [
120186
'Groups.Category.Manage' => 1,
121187
'Groups.Moderation.Manage' => 1,
122-
'Groups.EmailInvitations.Add' => 1
188+
'Groups.EmailInvitations.Add' => 1,
189+
'Garden.Uploads.Add' => 1,
190+
'Plugins.Attachments.Upload.Allow' => 1,
191+
'Vanilla.Discussions.View' => 1,
192+
'Vanilla.Discussions.Add' => 1,
193+
'Vanilla.Discussions.Edit' => 1,
194+
'Vanilla.Discussions.Announce' => 1,
195+
'Vanilla.Discussions.Sink' => 0,
196+
'Vanilla.Discussions.Close' => 1,
197+
'Vanilla.Discussions.Delete' => 1,
123198
],
124199
'customer' => [],
125200
'observer'=> [],

0 commit comments

Comments
 (0)