Skip to content

Commit

Permalink
[user_accounts] Prevent crash when one user has 0 site/project affili…
Browse files Browse the repository at this point in the history
…ations (aces#8139)

Although this use case should never happen as it is prevented by rules in the edit_user logic, a couple bugs have let it happen in the past and the entire module becomes inaccessible. This makes the module load and displays a message in the user row informing the editor that the user does not currently have any sites and projects.

The only way to test this would be to manually delete all site associations directly in the DB user_psc_rel OR all project associations user_project_rel

Note that the module crashes even if the user not having any sites or projects is not the editor nor the editee... any user can cause this issue.
  • Loading branch information
ridz1208 authored and cmadjar committed Sep 20, 2022
1 parent 80f2d94 commit 50b3d57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 10 additions & 0 deletions modules/user_accounts/jsx/userAccountsIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class UserAccountsIndex extends Component {
.join(', ')}
</td>
);
if (cell.length === 0) {
result = (
<td>This user has no site affiliations</td>
);
}
break;
case 'Project':
// If user has multiple projects, join array of sites into string
Expand All @@ -86,6 +91,11 @@ class UserAccountsIndex extends Component {
).join(', ')}
</td>
);
if (cell.length === 0) {
result = (
<td>This user has no project affiliations</td>
);
}
break;
case 'Username':
url = loris.BaseURL + '/user_accounts/edit_user/' + row.Username;
Expand Down
22 changes: 8 additions & 14 deletions modules/user_accounts/php/useraccountrowprovisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,14 @@ class UserAccountRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisione
*/
public function getInstance($row) : \LORIS\Data\DataInstance
{
$pids = array_map(
function (string $pid) : \ProjectID {
return new \ProjectID($pid);
},
explode(',', $row['projectIds']),
);

$cids = array_map(
function (string $cid) : \CenterID {
return new \CenterID($cid);
},
explode(',', $row['centerIds']),
);

$cids = [];
$pids = [];
if (isset($row['centerIds'])) {
$cids = explode(',', $row['centerIds']);
}
if (isset($row['projectIds'])) {
$pids = explode(',', $row['projectIds']);
}
$row['centerIds'] = $cids;
$row['projectIds'] = $pids;
return new UserAccountRow($row, $cids, $pids);
Expand Down

0 comments on commit 50b3d57

Please # to comment.