Skip to content

Commit 6691b47

Browse files
author
Fleetbase Security
committed
fix: restore User::activate() in activate() endpoint to update both user and companyUser status
Activation must update both users.status and company_users.status because a newly created user starts with a global status of 'inactive'. Only updating the CompanyUser record would leave users.status as 'inactive', blocking the user from accessing any organisation. Deactivation remains scoped to the CompanyUser record only (previous commit) so that deactivating a user in one organisation does not lock them out of other organisations they belong to. Refs: GHSA-3wj9-hh56-7fw7
1 parent 3c2d87d commit 6691b47

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

‎src/Http/Controllers/Internal/v1/UserController.php‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,20 +481,17 @@ public function activate($id)
481481
return response()->error('No user found', 404);
482482
}
483483

484-
// Only activate the CompanyUser record for the current organisation,
485-
// mirroring the scoped deactivate behaviour above.
486-
$companyUser = $user->companyUsers()->where('company_uuid', session('company'))->first();
487-
488-
if (!$companyUser) {
489-
return response()->error('User is not a member of this organisation.', 404);
490-
}
491-
492-
$companyUser->status = 'active';
493-
$companyUser->save();
484+
// Activate both the User record and the CompanyUser record.
485+
// Unlike deactivation (which is scoped to the current organisation only),
486+
// activation must also update users.status because a newly created user
487+
// starts with a global status of 'inactive' and needs to be unblocked
488+
// at the user level before they can access any organisation.
489+
$user->activate();
490+
$user = $user->refresh();
494491

495492
return response()->json([
496493
'message' => 'User activated',
497-
'status' => $companyUser->status,
494+
'status' => $user->session_status,
498495
]);
499496
}
500497

0 commit comments

Comments
 (0)