Skip to content

Commit 5d82aab

Browse files
authored
[php/libraries/UserPermissions.class.inc] Fix editing of users when a module is disabled (#7754)
if set one module as "No" in the module_manager, user account module can't edit the user ( 500 error). The query is incorrectly including inactivated modules, which causes an exception when trying to call getLongName() on the module.
1 parent c4b7b6f commit 5d82aab

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

php/libraries/UserPermissions.class.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,13 @@ class UserPermissions
302302
if (!$this->hasPermission('superuser')) {
303303
$query .= "JOIN user_perm_rel up ON (p.permID=up.PermID)
304304
LEFT JOIN permissions_category pc ON (pc.ID=p.categoryID)
305-
LEFT JOIN modules m ON (p.moduleID=m.ID)
306-
WHERE up.userID = :UID
305+
LEFT JOIN modules m ON p.moduleID=m.ID
306+
WHERE up.userID = :UID and m.Active='Y'
307307
ORDER BY p.categoryID, m.Name, p.description";
308308
$results = $DB->pselect($query, ['UID' => $this->userID]);
309309
} else {
310310
$query .= "LEFT JOIN permissions_category pc ON (pc.ID=p.categoryID)
311-
LEFT JOIN modules m ON (p.moduleID=m.ID)";
311+
LEFT JOIN modules m ON p.moduleID=m.ID WHERE m.Active='Y'";
312312
$results = $DB->pselect($query, []);
313313

314314
}

test/unittests/UserTest.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,16 @@ class UserTest extends TestCase
184184

185185
private $_moduleInfo = [
186186
0 => [
187-
'ID' => 2,
188-
'Name' => 'candidate_list'
187+
'ID' => 2,
188+
'Name' => 'candidate_list',
189+
'Active' => 'Y',
189190
],
190191
1 => [
191-
'ID' => 5,
192-
'Name' => 'timepoint_list'
192+
'ID' => 5,
193+
'Name' => 'timepoint_list',
194+
'Active' => 'Y',
193195
],
196+
194197
];
195198

196199
private $_userPermInfo = [0 => ['permID' => 1,
@@ -1127,36 +1130,28 @@ public function testGetPermissionsVerbose()
11271130
$this->assertEquals(
11281131
$this->_user->getPermissionsVerbose(),
11291132
[
1130-
0 => ['permID' => '1',
1131-
'code' => "superuser",
1132-
'description' => "superuser description",
1133-
'type' => "superuser category",
1134-
'action' => null,
1135-
'moduleID' => null,
1136-
'label' => 'superuser description'
1137-
],
1138-
1 => ['permID' => '2',
1133+
0 => ['permID' => '2',
11391134
'code' => "test_permission",
11401135
'description' => "description 1",
11411136
'type' => "category 1",
11421137
'action' => "View",
1143-
'moduleID' => 2,
1138+
'moduleID' => '2',
11441139
'label' => "Access Profile: View description 1"
11451140
],
1146-
2 => ['permID' => '3',
1141+
1 => ['permID' => '3',
11471142
'code' => "test_permission2",
11481143
'description' => "description 2",
11491144
'type' => "category 2",
11501145
'action' => "Edit",
1151-
'moduleID' => 5,
1146+
'moduleID' => '5',
11521147
'label' => "Timepoint List: Edit description 2"
11531148
],
1154-
3 => ['permID' => '4',
1149+
2 => ['permID' => '4',
11551150
'code' => 'test_permission3',
11561151
'description' => 'description 3',
11571152
'type' => null,
11581153
'action' => 'View/Create',
1159-
'moduleID' => 5,
1154+
'moduleID' => '5',
11601155
'label' => 'Timepoint List: View/Create description 3'
11611156
]
11621157
]

0 commit comments

Comments
 (0)